Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-actor/Conflict tests and BTC pull replication conflict resolution #7286

Open
wants to merge 17 commits into
base: release/anemone
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions db/hybrid_logical_vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (hlv *HybridLogicalVector) InvalidateMV() {
if source == hlv.SourceID {
continue
}
hlv.setPreviousVersion(source, value)
hlv.SetPreviousVersion(source, value)
}
hlv.MergeVersions = nil
}
Expand Down Expand Up @@ -346,13 +346,13 @@ func (hlv *HybridLogicalVector) AddNewerVersions(otherVector *HybridLogicalVecto
// for source if the local version for that source is lower
for i, v := range otherVector.PreviousVersions {
if hlv.PreviousVersions[i] == 0 {
hlv.setPreviousVersion(i, v)
hlv.SetPreviousVersion(i, v)
} else {
// if we get here then there is entry for this source in PV so we must check if its newer or not
otherHLVPVValue := v
localHLVPVValue := hlv.PreviousVersions[i]
if localHLVPVValue < otherHLVPVValue {
hlv.setPreviousVersion(i, v)
hlv.SetPreviousVersion(i, v)
}
}
}
Expand Down Expand Up @@ -384,8 +384,8 @@ func (hlv *HybridLogicalVector) computeMacroExpansions() []sgbucket.MacroExpansi
return outputSpec
}

// setPreviousVersion will take a source/version pair and add it to the HLV previous versions map
func (hlv *HybridLogicalVector) setPreviousVersion(source string, version uint64) {
// SetPreviousVersion will take a source/version pair and sets the value for the given source in the previous versions map
func (hlv *HybridLogicalVector) SetPreviousVersion(source string, version uint64) {
if hlv.PreviousVersions == nil {
hlv.PreviousVersions = make(HLVVersions)
}
Expand Down Expand Up @@ -443,6 +443,41 @@ func (hlv *HybridLogicalVector) ToHistoryForHLV() string {
return s.String()
}

func FromHistoryForHLV(history string) (*HybridLogicalVector, error) {
hlv := NewHybridLogicalVector()
// split the history string into PV and MV
versionSets := strings.Split(history, ";")
switch len(versionSets) {
case 0:
// no versions present
return hlv, nil
case 2:
// MV
mvs := strings.Split(versionSets[1], ",")
for _, mv := range mvs {
v, err := ParseVersion(mv)
if err != nil {
return nil, err
}
hlv.MergeVersions[v.SourceID] = v.Value
}
fallthrough
Comment on lines +446 to +464
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was for pre-beta implementation and needs removing/changing

case 1:
// PV
pvs := strings.Split(versionSets[0], ",")
for _, pv := range pvs {
v, err := ParseVersion(pv)
if err != nil {
return nil, err
}
hlv.PreviousVersions[v.SourceID] = v.Value
}
default:
return nil, fmt.Errorf("Invalid history string format")
}
return hlv, nil
}

// appendRevocationMacroExpansions adds macro expansions for the channel map. Not strictly an HLV operation
// but putting the function here as it's required when the HLV's current version is being macro expanded
func appendRevocationMacroExpansions(currentSpec []sgbucket.MacroExpansionSpec, channelNames []string) (updatedSpec []sgbucket.MacroExpansionSpec) {
Expand All @@ -456,9 +491,9 @@ func appendRevocationMacroExpansions(currentSpec []sgbucket.MacroExpansionSpec,

// ExtractHLVFromBlipMessage extracts the full HLV a string in the format seen over Blip
// blip string may be the following formats
// 1. cv only: cv
// 2. cv and pv: cv;pv
// 3. cv, pv, and mv: cv;mv;pv
// 1. cv only: cv
// 2. cv and pv: cv;pv1,pv2
// 3. cv+mv and pv: cv,mv1,mv2;pv1,pv2
//
// Function will return list of revIDs if legacy rev ID was found in the HLV history section (PV)
// TODO: CBG-3662 - Optimise once we've settled on and tested the format with CBL
Expand Down
10 changes: 7 additions & 3 deletions rest/blip_api_delta_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -960,18 +960,22 @@ func TestBlipNonDeltaSyncPush(t *testing.T) {
defer client.Close()

client.ClientDeltas = false
btcRunner.StartPull(client.id)
btcRunner.StartPush(client.id)

// create doc1 rev 1-0335a345b6ffed05707ccc4cbc1b67f4
version := rt.PutDocDirectly(docID, JsonToMap(t, `{"greetings": [{"hello": "world!"}, {"hi": "alice"}]}`))

btcRunner.StartOneshotPull(client.id)
data := btcRunner.WaitForVersion(client.id, docID, version)
assert.Equal(t, `{"greetings":[{"hello":"world!"},{"hi":"alice"}]}`, string(data))

// create doc1 rev 2-abcxyz on client
newRev := btcRunner.AddRev(client.id, docID, &version, []byte(`{"greetings":[{"hello":"world!"},{"hi":"alice"},{"howdy":"bob"}]}`))
// Check EE is delta, and CE is full-body replication

btcRunner.StartPushWithOpts(client.id, BlipTesterPushOptions{Continuous: false, Since: "0"})

msg := client.waitForReplicationMessage(collection, 2)
// ensure message is type rev
require.Equal(t, db.MessageRev, msg.Profile())

// Check the request was NOT sent with a deltaSrc property
assert.Equal(t, "", msg.Properties[db.RevMessageDeltaSrc])
Expand Down
Loading
Loading