Skip to content

Commit b8d105b

Browse files
torcolvingregns1
andauthored
[4.0.0 backport] CBG-4908: fix for panic in CheckProposedVersion for legacy revision case (#7803)
Co-authored-by: Gregory Newman-Smith <[email protected]>
1 parent 4006fa4 commit b8d105b

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

db/crud.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3688,6 +3688,9 @@ func (db *DatabaseCollectionWithUser) CheckProposedVersion(ctx context.Context,
36883688
} else if previousRevFormat == "revTreeID" && syncData.GetRevTreeID() == previousRev {
36893689
// Non-conflicting update, client's previous legacy revTreeID is server's currentRev
36903690
return ProposedRev_OK, ""
3691+
} else if hlv == nil {
3692+
// no HLV on this doc in SGW so if previousRev didn't match current rev then it is a conflict
3693+
return ProposedRev_Conflict, syncData.GetRevTreeID()
36913694
} else if previousRevFormat == "version" && localDocCV == previousVersion {
36923695
// Non-conflicting update, client's previous version is server's CV
36933696
return ProposedRev_OK, ""

rest/blip_api_crud_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3568,6 +3568,52 @@ func TestBlipPullConflict(t *testing.T) {
35683568
})
35693569
}
35703570

3571+
func TestPushHLVOntoLegacyRev(t *testing.T) {
3572+
t.Skip("CBG-4909 skipping due to conflict resolution not yet implemented for CBL rev tree")
3573+
3574+
btcRunner := NewBlipTesterClientRunner(t)
3575+
btcRunner.SkipSubtest[RevtreeSubtestName] = true // revtree subtest not relevant to this test
3576+
btcRunner.Run(func(t *testing.T) {
3577+
// Steps:
3578+
// 1. Rev 1-abc is created on SGW
3579+
// 2. Client pulls this revision (one shot)
3580+
// 3. Doc is mutated on SGW to get 2-abc (legacy rev only)
3581+
// 4. Doc is updated on CBL to get 100@CBL1 (HLV)
3582+
// 5. Client attempts to push this doc update
3583+
rt := NewRestTester(t,
3584+
&RestTesterConfig{
3585+
SyncFn: channels.DocChannelsSyncFunction,
3586+
})
3587+
defer rt.Close()
3588+
3589+
docID := SafeDocumentName(t, t.Name())
3590+
3591+
const alice = "alice"
3592+
rt.CreateUser(alice, []string{"ABC"})
3593+
3594+
opts := &BlipTesterClientOpts{Username: alice}
3595+
client := btcRunner.NewBlipTesterClientOptsWithRT(rt, opts)
3596+
3597+
// create legacy doc on rt and have CBL pull it
3598+
doc := rt.CreateDocNoHLV(docID, db.Body{"channels": []string{"ABC"}})
3599+
btcRunner.StartOneshotPull(client.id)
3600+
3601+
docInitVersion := doc.ExtractDocVersion()
3602+
btcRunner.WaitForVersion(client.id, docID, docInitVersion)
3603+
3604+
// update doc again in legacy mode on rt
3605+
_ = rt.CreateDocNoHLV(docID, db.Body{"channels": []string{"ABC"}, "_rev": docInitVersion.RevTreeID})
3606+
3607+
// update doc on client to have vv given to it and attempt to push it
3608+
newVersion := btcRunner.AddRev(client.id, docID, &docInitVersion, []byte(`{"channels": ["ABC"]}`))
3609+
3610+
btcRunner.StartPush(client.id)
3611+
btcRunner.StartPull(client.id)
3612+
3613+
rt.WaitForVersion(docID, newVersion)
3614+
})
3615+
}
3616+
35713617
func TestTombstoneCount(t *testing.T) {
35723618
base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll)
35733619
rtConfig := RestTesterConfig{

0 commit comments

Comments
 (0)