Skip to content

Commit 8d831ac

Browse files
authored
Write dummy system xattr on resurrection (#7292)
1 parent 8540300 commit 8d831ac

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

topologytest/couchbase_server_peer_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,17 @@ func (p *CouchbaseServerPeer) WriteDocument(dsName sgbucket.DataStoreName, docID
129129
var lastXattrs map[string][]byte
130130
// write the document LWW, ignoring any in progress writes
131131
callback := func(existingBody []byte, xattrs map[string][]byte, _ uint64) (sgbucket.UpdatedDoc, error) {
132+
doc := sgbucket.UpdatedDoc{Doc: body}
132133
// only set lastXattrs if existing document is not a tombstone, they will not be preserved if this is a resurrection
133134
if len(existingBody) > 0 {
134135
lastXattrs = xattrs
136+
} else {
137+
// create resurrection document with xattrs to prevent XDCR from doing a round trip replication when one peer has a _vv xattr and the other does not.
138+
doc.Xattrs = map[string][]byte{
139+
dummySystemXattr: []byte(`{"dummy": "xattr"}`),
140+
}
135141
}
136-
return sgbucket.UpdatedDoc{Doc: body}, nil
142+
return doc, nil
137143
}
138144
cas, err := p.getCollection(dsName).WriteUpdateWithXattrs(p.Context(), docID, metadataXattrNames, 0, nil, nil, callback)
139145
require.NoError(p.tb, err)

topologytest/peer_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,18 @@ func TestPeerImplementation(t *testing.T) {
449449
}
450450
peer.WaitForDocVersion(collectionName, docID, resurrectionVersion.docMeta)
451451

452+
ctx := peer.Context()
453+
if peer.Type() != PeerTypeCouchbaseLite {
454+
collection, err := peer.GetBackingBucket().NamedDataStore(collectionName)
455+
require.NoError(t, err)
456+
xattrs, _, err := collection.GetXattrs(ctx, docID, metadataXattrNames)
457+
require.NoError(t, err)
458+
require.NotEmpty(t, xattrs)
459+
if tc.peerOption.Type == PeerTypeCouchbaseServer {
460+
require.Contains(t, xattrs, dummySystemXattr)
461+
}
462+
}
463+
452464
})
453465
}
454466

0 commit comments

Comments
 (0)