Skip to content

Commit 959c4b8

Browse files
committed
fixes
- update CBG ticket names - remove all changes in rest package, create DocMetadata in topology test to include extended version information - created log key VV for testing
1 parent 1b69cbc commit 959c4b8

13 files changed

+120
-127
lines changed

base/log_keys.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const (
5353
KeyReplicate
5454
KeySync
5555
KeySyncMsg
56+
KeyVV
5657
KeyWebSocket
5758
KeyWebSocketFrame
5859
KeySGTest
@@ -87,6 +88,7 @@ var (
8788
KeyReplicate: "Replicate",
8889
KeySync: "Sync",
8990
KeySyncMsg: "SyncMsg",
91+
KeyVV: "VV",
9092
KeyWebSocket: "WS",
9193
KeyWebSocketFrame: "WSFrame",
9294
KeySGTest: "TEST",

db/crud.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -901,9 +901,9 @@ func (db *DatabaseCollectionWithUser) updateHLV(ctx context.Context, d *Document
901901
hasHLV := d.HLV != nil
902902
if d.HLV == nil {
903903
d.HLV = &HybridLogicalVector{}
904-
base.DebugfCtx(ctx, base.KeySGTest, "No existing HLV for doc %s", base.UD(d.ID))
904+
base.DebugfCtx(ctx, base.KeyVV, "No existing HLV for doc %s", base.UD(d.ID))
905905
} else {
906-
base.DebugfCtx(ctx, base.KeySGTest, "Existing HLV for doc %s before modification %+v", base.UD(d.ID), d.HLV)
906+
base.DebugfCtx(ctx, base.KeyVV, "Existing HLV for doc %s before modification %+v", base.UD(d.ID), d.HLV)
907907
}
908908
switch docUpdateEvent {
909909
case ExistingVersion:
@@ -925,9 +925,9 @@ func (db *DatabaseCollectionWithUser) updateHLV(ctx context.Context, d *Document
925925
return nil, err
926926
}
927927
d.HLV.CurrentVersionCAS = d.Cas
928-
base.DebugfCtx(ctx, base.KeySGTest, "Adding new version to HLV due to import for doc %s, updated HLV %+v", base.UD(d.ID), d.HLV)
928+
base.DebugfCtx(ctx, base.KeyVV, "Adding new version to HLV due to import for doc %s, updated HLV %+v", base.UD(d.ID), d.HLV)
929929
} else {
930-
base.DebugfCtx(ctx, base.KeySGTest, "Not updating HLV to _mou.cas == doc.cas for doc %s, extant HLV %+v", base.UD(d.ID), d.HLV)
930+
base.DebugfCtx(ctx, base.KeyVV, "Not updating HLV to _mou.cas == doc.cas for doc %s, extant HLV %+v", base.UD(d.ID), d.HLV)
931931
}
932932
case NewVersion, ExistingVersionWithUpdateToHLV:
933933
// add a new entry to the version vector
@@ -2098,9 +2098,9 @@ func (col *DatabaseCollectionWithUser) documentUpdateFunc(
20982098
mouMatch := false
20992099
if doc.MetadataOnlyUpdate != nil && base.HexCasToUint64(doc.MetadataOnlyUpdate.CAS) == doc.Cas {
21002100
mouMatch = base.HexCasToUint64(doc.MetadataOnlyUpdate.CAS) == doc.Cas
2101-
base.DebugfCtx(ctx, base.KeySGTest, "updateDoc(%q): _mou:%+v Metadata-only update match:%t", base.UD(doc.ID), doc.MetadataOnlyUpdate, mouMatch)
2101+
base.DebugfCtx(ctx, base.KeyVV, "updateDoc(%q): _mou:%+v Metadata-only update match:%t", base.UD(doc.ID), doc.MetadataOnlyUpdate, mouMatch)
21022102
} else {
2103-
base.DebugfCtx(ctx, base.KeySGTest, "updateDoc(%q): has no _mou", base.UD(doc.ID))
2103+
base.DebugfCtx(ctx, base.KeyVV, "updateDoc(%q): has no _mou", base.UD(doc.ID))
21042104
}
21052105
// Invoke the callback to update the document and with a new revision body to be used by the Sync Function:
21062106
newDoc, newAttachments, createNewRevIDSkipped, updatedExpiry, err := callback(doc)

rest/api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2834,7 +2834,7 @@ func TestPvDeltaReadAndWrite(t *testing.T) {
28342834

28352835
// assert that we have a prev CV drop to pv and a new CV pair, assert pv values are as expected after delta conversions
28362836
assert.Equal(t, testSource, newDoc.HLV.SourceID)
2837-
assert.Equal(t, version2.HLV.Version, newDoc.HLV.Version)
2837+
assert.Equal(t, version2.CV.Value, newDoc.HLV.Version)
28382838
assert.Len(t, newDoc.HLV.PreviousVersions, 1)
28392839
assert.Equal(t, casV1, newDoc.HLV.PreviousVersions[encodedSourceV1])
28402840

rest/blip_api_crud_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,15 +2173,21 @@ func TestPullReplicationUpdateOnOtherHLVAwarePeer(t *testing.T) {
21732173
otherSource := "otherSource"
21742174
hlvHelper := db.NewHLVAgent(t, rt.GetSingleDataStore(), otherSource, "_vv")
21752175
existingHLVKey := "doc1"
2176-
_ = hlvHelper.InsertWithHLV(ctx, existingHLVKey)
2176+
cas := hlvHelper.InsertWithHLV(ctx, existingHLVKey)
21772177

21782178
// force import of this write
21792179
_, _ = rt.GetDoc(docID)
21802180
bucketDoc, _, err := collection.GetDocWithXattrs(ctx, docID, db.DocUnmarshalAll)
21812181
require.NoError(t, err)
21822182

21832183
// create doc version of the above doc write
2184-
version1 := DocVersionFromDocument(bucketDoc)
2184+
version1 := DocVersion{
2185+
RevTreeID: bucketDoc.CurrentRev,
2186+
CV: db.Version{
2187+
SourceID: hlvHelper.Source,
2188+
Value: cas,
2189+
},
2190+
}
21852191

21862192
_ = btcRunner.WaitForVersion(client.id, docID, version1)
21872193

rest/utilities_testing.go

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ func createBlipTesterWithSpec(tb testing.TB, spec BlipTesterSpec, rt *RestTester
14851485
if err != nil {
14861486
return nil, err
14871487
}
1488-
log.Printf("db:%s Creating user: %v", bt.restTester.GetDatabase().Name, userDocBody)
1488+
log.Printf("Creating user: %v", userDocBody)
14891489

14901490
// Create a user. NOTE: this must come *after* the bt.rt.TestPublicHandler() call, otherwise it will end up getting ignored
14911491
_ = bt.restTester.SendAdminRequest(
@@ -2448,15 +2448,12 @@ func WaitAndAssertBackgroundManagerExpiredHeartbeat(t testing.TB, bm *db.Backgro
24482448

24492449
// DocVersion represents a specific version of a document in an revID/HLV agnostic manner.
24502450
type DocVersion struct {
2451-
RevTreeID string // RevTreeID is the rev treee ID of a document, may be empty not present
2452-
HLV *db.HybridLogicalVector // HLV is the hybrid logical vector of the document, may not be present
2453-
Mou *db.MetadataOnlyUpdate // Mou is the metadata only update of the document, may not be present
2454-
Cas uint64 // Cas is the cas value of the document
2455-
HasImplicitCV bool // If true, the HLV was constructed from cas@sourceID instead of from _vv, used for documents written to Couchbase Server without Sync Gateway
2451+
RevTreeID string
2452+
CV db.Version
24562453
}
24572454

2458-
func (v DocVersion) String() string {
2459-
return fmt.Sprintf("Cas:%d RevTreeID:%s HLV:%+v Mou:%+v HasImplicitCV:%t", v.Cas, v.RevTreeID, v.HLV, v.Mou, v.HasImplicitCV)
2455+
func (v *DocVersion) String() string {
2456+
return fmt.Sprintf("RevTreeID: %s", v.RevTreeID)
24602457
}
24612458

24622459
func (v DocVersion) Equal(o DocVersion) bool {
@@ -2468,19 +2465,15 @@ func (v DocVersion) Equal(o DocVersion) bool {
24682465

24692466
func (v DocVersion) GetRev(useHLV bool) string {
24702467
if useHLV {
2471-
if v.HLV == nil {
2468+
if v.CV.SourceID == "" {
24722469
return ""
24732470
}
2474-
return v.HLV.GetCurrentVersionString()
2471+
return v.CV.String()
24752472
} else {
24762473
return v.RevTreeID
24772474
}
24782475
}
24792476

2480-
func (v DocVersion) CV() string {
2481-
return v.GetRev(true)
2482-
}
2483-
24842477
// Digest returns the digest for the current version
24852478
func (v DocVersion) Digest() string {
24862479
return strings.Split(v.RevTreeID, "-")[1]
@@ -2511,16 +2504,6 @@ func NewDocVersionFromFakeRev(fakeRev string) DocVersion {
25112504
return DocVersion{RevTreeID: fakeRev}
25122505
}
25132506

2514-
// DocVersionFromDocument returns a DocVersion from the given document.
2515-
func DocVersionFromDocument(doc *db.Document) DocVersion {
2516-
return DocVersion{
2517-
RevTreeID: doc.CurrentRev,
2518-
Mou: doc.MetadataOnlyUpdate,
2519-
Cas: doc.Cas,
2520-
HLV: doc.HLV,
2521-
}
2522-
}
2523-
25242507
// DocVersionFromPutResponse returns a DocRevisionID from the given response to PUT /{, or fails the given test if a rev ID was not found.
25252508
func DocVersionFromPutResponse(t testing.TB, response *TestResponse) DocVersion {
25262509
var r struct {

rest/utilities_testing_blip_client.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ func (btc *BlipTesterCollectionClient) PushRev(docID string, parentVersion DocVe
924924

925925
func (btc *BlipTesterCollectionClient) requireRevID(expected DocVersion, revID string) {
926926
if btc.UseHLV() {
927-
require.Equal(btc.parent.rt.TB(), expected.CV(), revID)
927+
require.Equal(btc.parent.rt.TB(), expected.CV.String(), revID)
928928
} else {
929929
require.Equal(btc.parent.rt.TB(), expected.RevTreeID, revID)
930930
}
@@ -948,7 +948,7 @@ func (btc *BlipTesterClient) GetDocVersion(docID string) DocVersion {
948948
if !btc.UseHLV() || doc.HLV == nil {
949949
return DocVersion{RevTreeID: doc.CurrentRev}
950950
}
951-
return DocVersion{RevTreeID: doc.CurrentRev, HLV: doc.HLV}
951+
return DocVersion{RevTreeID: doc.CurrentRev, CV: db.Version{SourceID: doc.HLV.SourceID, Value: doc.HLV.Version}}
952952
}
953953

954954
// PushRevWithHistory creates a revision on the client with history, and immediately sends a changes request for it.
@@ -1193,7 +1193,7 @@ func (btc *BlipTesterClient) AssertOnBlipHistory(t *testing.T, msg *blip.Message
11931193
require.NoError(t, err)
11941194
if subProtocol >= db.CBMobileReplicationV4 { // history could be empty a lot of the time in HLV messages as updates from the same source won't populate previous versions
11951195
if msg.Properties[db.RevMessageHistory] != "" {
1196-
assert.Equal(t, docVersion.CV(), msg.Properties[db.RevMessageHistory])
1196+
assert.Equal(t, docVersion.CV.String(), msg.Properties[db.RevMessageHistory])
11971197
}
11981198
} else {
11991199
assert.Equal(t, docVersion.RevTreeID, msg.Properties[db.RevMessageHistory])
@@ -1207,7 +1207,7 @@ func (btc *BlipTesterCollectionClient) GetVersion(docID string, docVersion DocVe
12071207

12081208
if doc, ok := btc.docs[docID]; ok {
12091209
if doc.revMode == revModeHLV {
1210-
if doc.getCurrentRevID() == docVersion.CV() {
1210+
if doc.getCurrentRevID() == docVersion.CV.String() {
12111211
return doc.body, true
12121212
}
12131213
} else {
@@ -1306,7 +1306,7 @@ func (btr *BlipTesterReplicator) storeMessage(msg *blip.Message) {
13061306
func (btc *BlipTesterCollectionClient) WaitForBlipRevMessage(docID string, version DocVersion) (msg *blip.Message) {
13071307
var revID string
13081308
if btc.UseHLV() {
1309-
revID = version.CV()
1309+
revID = version.CV.String()
13101310
} else {
13111311
revID = version.RevTreeID
13121312
}
@@ -1455,9 +1455,16 @@ func (btc *BlipTesterCollectionClient) sendPushMsg(msg *blip.Message) error {
14551455
// PutDoc will upsert the document with a given contents.
14561456
func (btc *BlipTesterClient) PutDoc(docID string, body string) DocVersion {
14571457
rt := btc.rt
1458-
var unmarshalledBody db.Body
1459-
require.NoError(rt.TB(), base.JSONUnmarshal([]byte(body), &unmarshalledBody))
1460-
return rt.PutDocDirectly(docID, unmarshalledBody)
1458+
version := rt.PutDoc(docID, body)
1459+
if btc.UseHLV() {
1460+
collection, _ := rt.GetSingleTestDatabaseCollection()
1461+
source, value := collection.GetDocumentCurrentVersion(rt.TB(), docID)
1462+
version.CV = db.Version{
1463+
SourceID: source,
1464+
Value: value,
1465+
}
1466+
}
1467+
return version
14611468
}
14621469

14631470
// RequireRev checks the current rev for the specified docID on the backend the BTC is replicating

rest/utilities_testing_resttester.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,35 +419,35 @@ func (rt *RestTester) RequireDbOnline() {
419419
// TEMPORARY HELPER METHODS FOR BLIP TEST CLIENT RUNNER
420420
func (rt *RestTester) PutDocDirectly(docID string, body db.Body) DocVersion {
421421
collection, ctx := rt.GetSingleTestDatabaseCollectionWithUser()
422-
_, doc, err := collection.Put(ctx, docID, body)
422+
rev, doc, err := collection.Put(ctx, docID, body)
423423
require.NoError(rt.TB(), err)
424-
return DocVersionFromDocument(doc)
424+
return DocVersion{RevTreeID: rev, CV: db.Version{SourceID: doc.HLV.SourceID, Value: doc.HLV.Version}}
425425
}
426426

427427
func (rt *RestTester) UpdateDocDirectly(docID string, version DocVersion, body db.Body) DocVersion {
428428
collection, ctx := rt.GetSingleTestDatabaseCollectionWithUser()
429429
body[db.BodyId] = docID
430430
body[db.BodyRev] = version.RevTreeID
431-
_, doc, err := collection.Put(ctx, docID, body)
431+
rev, doc, err := collection.Put(ctx, docID, body)
432432
require.NoError(rt.TB(), err)
433-
return DocVersionFromDocument(doc)
433+
return DocVersion{RevTreeID: rev, CV: db.Version{SourceID: doc.HLV.SourceID, Value: doc.HLV.Version}}
434434
}
435435

436436
func (rt *RestTester) DeleteDocDirectly(docID string, version DocVersion) DocVersion {
437437
collection, ctx := rt.GetSingleTestDatabaseCollectionWithUser()
438-
_, doc, err := collection.DeleteDoc(ctx, docID, version.RevTreeID)
438+
rev, doc, err := collection.DeleteDoc(ctx, docID, version.RevTreeID)
439439
require.NoError(rt.TB(), err)
440-
return DocVersionFromDocument(doc)
440+
return DocVersion{RevTreeID: rev, CV: db.Version{SourceID: doc.HLV.SourceID, Value: doc.HLV.Version}}
441441
}
442442

443443
func (rt *RestTester) PutDocDirectlyInCollection(collection *db.DatabaseCollection, docID string, body db.Body) DocVersion {
444444
dbUser := &db.DatabaseCollectionWithUser{
445445
DatabaseCollection: collection,
446446
}
447447
ctx := base.UserLogCtx(collection.AddCollectionContext(rt.Context()), "gotest", base.UserDomainBuiltin, nil)
448-
_, doc, err := dbUser.Put(ctx, docID, body)
448+
rev, doc, err := dbUser.Put(ctx, docID, body)
449449
require.NoError(rt.TB(), err)
450-
return DocVersionFromDocument(doc)
450+
return DocVersion{RevTreeID: rev, CV: db.Version{SourceID: doc.HLV.SourceID, Value: doc.HLV.Version}}
451451
}
452452

453453
// PutDocWithAttachment will upsert the document with a given contents and attachments.

topologytest/couchbase_lite_mock_peer_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ func (p *CouchbaseLiteMockPeer) String() string {
4343
}
4444

4545
// GetDocument returns the latest version of a document. The test will fail the document does not exist.
46-
func (p *CouchbaseLiteMockPeer) GetDocument(_ sgbucket.DataStoreName, _ string) (rest.DocVersion, db.Body) {
46+
func (p *CouchbaseLiteMockPeer) GetDocument(_ sgbucket.DataStoreName, _ string) (DocMetadata, db.Body) {
4747
// this isn't yet collection aware, using single default collection
48-
return rest.EmptyDocVersion(), nil
48+
return DocMetadata{}, nil
4949
}
5050

5151
// getSingleBlipClient returns the single blip client for the peer. If there are multiple clients, or not clients it will fail the test. This is temporary to stub support for multiple Sync Gateway peers.
@@ -62,28 +62,28 @@ func (p *CouchbaseLiteMockPeer) getSingleBlipClient() *PeerBlipTesterClient {
6262
}
6363

6464
// CreateDocument creates a document on the peer. The test will fail if the document already exists.
65-
func (p *CouchbaseLiteMockPeer) CreateDocument(dsName sgbucket.DataStoreName, docID string, body []byte) rest.DocVersion {
65+
func (p *CouchbaseLiteMockPeer) CreateDocument(dsName sgbucket.DataStoreName, docID string, body []byte) DocMetadata {
6666
p.t.Logf("%s: Creating document %s", p, docID)
6767
return p.WriteDocument(dsName, docID, body)
6868
}
6969

7070
// WriteDocument writes a document to the peer. The test will fail if the write does not succeed.
71-
func (p *CouchbaseLiteMockPeer) WriteDocument(_ sgbucket.DataStoreName, docID string, body []byte) rest.DocVersion {
71+
func (p *CouchbaseLiteMockPeer) WriteDocument(_ sgbucket.DataStoreName, docID string, body []byte) DocMetadata {
7272
// this isn't yet collection aware, using single default collection
7373
client := p.getSingleBlipClient()
7474
// set an HLV here.
7575
docVersion, err := client.btcRunner.PushRev(client.ID(), docID, rest.EmptyDocVersion(), body)
7676
require.NoError(client.btcRunner.TB(), err)
77-
return docVersion
77+
return DocMetadataFromDocVersion(docID, docVersion)
7878
}
7979

8080
// DeleteDocument deletes a document on the peer. The test will fail if the document does not exist.
81-
func (p *CouchbaseLiteMockPeer) DeleteDocument(sgbucket.DataStoreName, string) rest.DocVersion {
82-
return rest.EmptyDocVersion()
81+
func (p *CouchbaseLiteMockPeer) DeleteDocument(sgbucket.DataStoreName, string) DocMetadata {
82+
return DocMetadata{}
8383
}
8484

8585
// WaitForDocVersion waits for a document to reach a specific version. The test will fail if the document does not reach the expected version in 20s.
86-
func (p *CouchbaseLiteMockPeer) WaitForDocVersion(_ sgbucket.DataStoreName, docID string, _ rest.DocVersion) db.Body {
86+
func (p *CouchbaseLiteMockPeer) WaitForDocVersion(_ sgbucket.DataStoreName, docID string, _ DocMetadata) db.Body {
8787
// this isn't yet collection aware, using single default collection
8888
client := p.getSingleBlipClient()
8989
// FIXME: waiting for a specific version isn't working yet.
@@ -99,7 +99,7 @@ func (p *CouchbaseLiteMockPeer) WaitForDeletion(_ sgbucket.DataStoreName, _ stri
9999
}
100100

101101
// WaitForTombstoneVersion waits for a document to reach a specific version, this must be a tombstone. The test will fail if the document does not reach the expected version in 20s.
102-
func (p *CouchbaseLiteMockPeer) WaitForTombstoneVersion(_ sgbucket.DataStoreName, _ string, _ rest.DocVersion) {
102+
func (p *CouchbaseLiteMockPeer) WaitForTombstoneVersion(_ sgbucket.DataStoreName, _ string, _ DocMetadata) {
103103
require.Fail(p.TB(), "WaitForTombstoneVersion not yet implemented CBG-4257")
104104
}
105105

0 commit comments

Comments
 (0)