Skip to content

Commit 4a79b35

Browse files
authored
Revert "CBG-4905: update defualt resolver for blip tester" (#7928)
1 parent 58e10a4 commit 4a79b35

File tree

3 files changed

+9
-59
lines changed

3 files changed

+9
-59
lines changed

rest/utilities_testing_blip_client.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -344,37 +344,25 @@ func (cd *clientDoc) _hasConflict(t testing.TB, incomingHLV *db.HybridLogicalVec
344344
return false
345345
}
346346

347-
func (btcc *BlipTesterCollectionClient) _resolveConflict(incomingHLV *db.HybridLogicalVector, incomingBody []byte, incomingIsDelete bool, localDoc *clientDocRev) (body []byte, hlv db.HybridLogicalVector, isTombstone bool) {
347+
func (btcc *BlipTesterCollectionClient) _resolveConflict(incomingHLV *db.HybridLogicalVector, incomingBody []byte, localDoc *clientDocRev) (body []byte, hlv db.HybridLogicalVector) {
348348
switch btcc.parent.ConflictResolver {
349349
case ConflictResolverLastWriteWins:
350350
return btcc._resolveConflictLWW(incomingHLV, incomingBody, localDoc)
351351
}
352352
btcc.TB().Fatalf("Unknown conflict resolver %q - cannot resolve detected conflict", btcc.parent.ConflictResolver)
353-
return nil, db.HybridLogicalVector{}, isTombstone
353+
return nil, db.HybridLogicalVector{}
354354
}
355355

356-
func (btcc *BlipTesterCollectionClient) _resolveConflictLWW(incomingHLV *db.HybridLogicalVector, incomingBody []byte, latestLocalRev *clientDocRev) (body []byte, hlv db.HybridLogicalVector, isTombstone bool) {
356+
func (btcc *BlipTesterCollectionClient) _resolveConflictLWW(incomingHLV *db.HybridLogicalVector, incomingBody []byte, latestLocalRev *clientDocRev) (body []byte, hlv db.HybridLogicalVector) {
357357
latestLocalHLV := latestLocalRev.HLV
358358
updatedHLV := latestLocalRev.HLV.Copy()
359-
localDeleted := latestLocalRev.isDelete
360-
incomingIsDelete := incomingBody == nil || bytes.Equal(incomingBody, []byte(`{}`))
361-
if localDeleted && !incomingIsDelete {
362-
// resolve in favour of local document
363-
incomingHLV.UpdateWithIncomingHLV(updatedHLV)
364-
return latestLocalRev.body, *updatedHLV, true
365-
}
366-
if incomingIsDelete && !localDeleted {
367-
// resolve in favour of remote document
368-
updatedHLV.UpdateWithIncomingHLV(incomingHLV)
369-
return incomingBody, *updatedHLV, true
370-
}
371359
// resolve conflict in favor of remote document
372360
if incomingHLV.Version > latestLocalHLV.Version {
373361
updatedHLV.UpdateWithIncomingHLV(incomingHLV)
374-
return incomingBody, *updatedHLV, incomingIsDelete
362+
return incomingBody, *updatedHLV
375363
}
376364
incomingHLV.UpdateWithIncomingHLV(updatedHLV)
377-
return latestLocalRev.body, *updatedHLV, latestLocalRev.isDelete
365+
return latestLocalRev.body, *updatedHLV
378366
}
379367

380368
type BlipTesterCollectionClient struct {
@@ -2199,15 +2187,14 @@ func (btcc *BlipTesterCollectionClient) addRev(ctx context.Context, docID string
21992187
btcc.seqLock.Lock()
22002188
defer btcc.seqLock.Unlock()
22012189
newClientSeq := btcc._nextSequence()
2202-
isDelete := opts.isDelete
22032190

22042191
newBody := opts.body
22052192
newVersion := opts.incomingVersion
22062193
doc, hasLocalDoc := btcc._getClientDoc(docID)
22072194
updatedHLV := doc._getLatestHLVCopy(btcc.TB())
22082195
require.NotNil(btcc.TB(), updatedHLV, "updatedHLV should not be nil for docID %q", docID)
22092196
if doc._hasConflict(btcc.TB(), opts.incomingHLV) {
2210-
newBody, updatedHLV, isDelete = btcc._resolveConflict(opts.incomingHLV, opts.body, opts.isDelete, doc._latestRev(btcc.TB()))
2197+
newBody, updatedHLV = btcc._resolveConflict(opts.incomingHLV, opts.body, doc._latestRev(btcc.TB()))
22112198
base.DebugfCtx(ctx, base.KeySGTest, "Resolved conflict for docID %q, incomingHLV:%#v, existingHLV:%#v, updatedHLV:%#v", docID, opts.incomingHLV, doc._latestRev(btcc.TB()).HLV, updatedHLV)
22122199
} else {
22132200
base.DebugfCtx(ctx, base.KeySGTest, "No conflict")
@@ -2220,7 +2207,7 @@ func (btcc *BlipTesterCollectionClient) addRev(ctx context.Context, docID string
22202207
// ConflictResolver is currently on BlipTesterClient, but might be per replication in the future.
22212208
docRev := clientDocRev{
22222209
clientSeq: newClientSeq,
2223-
isDelete: isDelete,
2210+
isDelete: opts.isDelete,
22242211
pullMessage: opts.msg,
22252212
body: newBody,
22262213
HLV: updatedHLV,

topologytest/multi_actor_no_conflict_test.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ package topologytest
1010

1111
import (
1212
"fmt"
13-
"strings"
1413
"testing"
1514

1615
"github.com/couchbase/sync_gateway/base"
@@ -107,21 +106,9 @@ func TestMultiActorResurrect(t *testing.T) {
107106

108107
resBody := fmt.Appendf(nil, `{"activePeer": "%s", "createPeer": "%s", "deletePeer": "%s", "resurrectPeer": "%s", "topology": "%s", "action": "resurrect"}`, resurrectPeerName, createPeerName, deletePeer, resurrectPeer, topology.specDescription)
109108
resurrectVersion := resurrectPeer.WriteDocument(collectionName, docID, resBody)
110-
// in the case of a Couchbase Server resurrection, the hlv is lost since all system xattrs are
111-
// lost on a resurrection so the resurrecting version may conflict with a version on cbl
112-
// peer then cbl will resolve in favor if its own tombstone.
109+
// in the case of a Couchbase Server resurrection, the hlv is lost since all system xattrs are lost on a resurrection
113110
if resurrectPeer.Type() == PeerTypeCouchbaseServer {
114-
if strings.Contains(topologySpec.description, "CBL") {
115-
if conflictNotExpectedOnCBL(deletePeer, resurrectPeer) {
116-
// if no cbl conflict is expected we can wait on CV and body
117-
waitForCVAndBody(t, collectionName, docID, resurrectVersion, topology)
118-
} else {
119-
// if cbl conflict is expected we need to wait for tombstone convergence
120-
waitForConvergingTombstones(t, collectionName, docID, topology)
121-
}
122-
} else {
123-
waitForCVAndBody(t, collectionName, docID, resurrectVersion, topology)
124-
}
111+
waitForCVAndBody(t, collectionName, docID, resurrectVersion, topology)
125112
} else {
126113
waitForVersionAndBody(t, collectionName, docID, resurrectVersion, topology)
127114
}

topologytest/peer_test.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -127,30 +127,6 @@ func (p Peers) SortedPeers() iter.Seq2[string, Peer] {
127127
}
128128
}
129129

130-
// peerIsServerSide returns true if the peer is a Couchbase Server or Sync Gateway peer.
131-
func peerIsServerSide(p Peer) bool {
132-
return p.Type() == PeerTypeCouchbaseServer || p.Type() == PeerTypeSyncGateway
133-
}
134-
135-
// conflictNotExpectedOnCBL will return true if no conflict is expected for delete and resurrect operations for
136-
// topologies with cbl peer in them and false for expected conflict
137-
func conflictNotExpectedOnCBL(deletePeer Peer, resurrectPeer Peer) bool {
138-
if deletePeer.Type() == PeerTypeCouchbaseLite {
139-
// cbl delete will mean cbs resurrect has a conflict
140-
return false
141-
}
142-
if peerIsServerSide(deletePeer) && peerIsServerSide(resurrectPeer) {
143-
if deletePeer.SourceID() != resurrectPeer.SourceID() {
144-
// conflict expected due to different backing bucket (sourceID)
145-
return false
146-
}
147-
// if both actors are server side and same backing bucket, no conflict expected
148-
return true
149-
}
150-
// conflict expected
151-
return false
152-
}
153-
154130
// NonImportSortedPeers returns a sorted iterator peers that will not cause import operations. For example:
155131
// - cbs1 <-> sg1 <-> cbl1 would return sg1 and cbl1, but not cbs1
156132
// - cbs1 <-> cbs2 would return cbs1 and cbs2

0 commit comments

Comments
 (0)