Skip to content

Commit

Permalink
Enable version vector
Browse files Browse the repository at this point in the history
* Updated LiteCore to 7c777bf4df301746433445d785fc2de78b97af15.
* Enabled version vector.
* Updated default conflict resolution logic to use timestamp instead of generation. This would make the default logic to be last write wins instead of most frequent update wins.
* Disabled tests that uses the previous default conflict resolution logic.
* Fixed XCode 15 build issues
  • Loading branch information
pasin committed Oct 4, 2023
1 parent d6d2541 commit 8431424
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/CBLDatabase_Internal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private:
}
C4DatabaseConfig2 c4Config = {};
c4Config.parentDirectory = effectiveDir(config->directory);
c4Config.flags = kC4DB_Create;
c4Config.flags = kC4DB_Create | kC4DB_VersionVectors;
#ifdef COUCHBASE_ENTERPRISE
c4Config.encryptionKey = asC4Key(&config->encryptionKey);
#endif
Expand Down
1 change: 1 addition & 0 deletions src/CBLDocument_Internal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public:
slice docID() const {return _docID;}
slice revisionID() const {return _revID;}
unsigned generation() const {return C4Document::getRevIDGeneration(_revID);}
uint64_t timestamp() const {return C4Document::getRevIDTimestamp(_revID);}

uint64_t sequence() const {
auto c4doc = _c4doc.useLocked();
Expand Down
4 changes: 2 additions & 2 deletions src/ConflictResolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ static const CBLDocument* defaultConflictResolver(void *context,
const CBLDocument* resolved;
if (remoteDoc == nullptr || localDoc == nullptr)
resolved = nullptr;
else if (remoteDoc->generation() > localDoc->generation())
else if (remoteDoc->timestamp() > localDoc->timestamp())
resolved = remoteDoc;
else if (localDoc->generation() > remoteDoc->generation())
else if (localDoc->timestamp() > remoteDoc->timestamp())
resolved = localDoc;
else if (FLSlice_Compare(localDoc->revisionID(), remoteDoc->revisionID()) > 0)
resolved = localDoc;
Expand Down
4 changes: 3 additions & 1 deletion test/DocumentTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ TEST_CASE_METHOD(DocumentTest, "Save Empty Document", "[Document]") {

doc = CBLCollection_GetMutableDocument(col, "foo"_sl, &error);
CHECK(CBLDocument_ID(doc) == "foo"_sl);
CHECK(CBLDocument_RevisionID(doc) == "1-581ad726ee407c8376fc94aad966051d013893c4"_sl);

auto str = slice(CBLDocument_RevisionID(doc)).asString();
CHECK(CBLDocument_RevisionID(doc).buf);
CHECK(CBLDocument_Sequence(doc) == 1);
CHECK(alloc_slice(CBLDocument_CreateJSON(doc)) == "{}"_sl);
CBLDocument_Release(doc);
Expand Down
2 changes: 1 addition & 1 deletion test/LogTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ TEST_CASE_METHOD(LogTest, "File Logging : Set Log Level", "[Log][FileLog]") {
}

// Verify:
int lineCount = 1; // Header:
int lineCount = 2; // Header (2 lines):
for (CBLLogLevel level : kLogLevels) {
if (level == kCBLLogNone)
continue;
Expand Down
8 changes: 0 additions & 8 deletions test/QueryTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ TEST_CASE_METHOD(QueryTest, "Query Listener", "[Query][LiveQuery]") {
// Remove listener token and sleep to ensure async cleanup in LiteCore's LiveQuerier's _stop()
// functions is done before checking instance leaking in CBLTest's destructor:
CBLListener_Remove(listenerToken);
listenerToken = nullptr;
cerr << "Sleeping to ensure async cleanup ..." << endl;
this_thread::sleep_for(500ms);
}
Expand Down Expand Up @@ -566,7 +565,6 @@ TEST_CASE_METHOD(QueryTest, "Remove Query Listener", "[Query][LiveQuery]") {
CHECK(state.resultCount() == 3);

// Cleanup:
listenerToken = nullptr;
cerr << "Sleeping to ensure async cleanup ..." << endl;
this_thread::sleep_for(500ms);
}
Expand Down Expand Up @@ -604,7 +602,6 @@ TEST_CASE_METHOD(QueryTest, "Query Listener and Changing parameters", "[Query][L
CHECK(state.resultCount() == 2);

CBLListener_Remove(listenerToken);
listenerToken = nullptr;
cerr << "Sleeping to ensure async cleanup ..." << endl;
this_thread::sleep_for(500ms);
}
Expand Down Expand Up @@ -666,10 +663,6 @@ TEST_CASE_METHOD(QueryTest, "Multiple Query Listeners", "[Query][LiveQuery]") {
CBLListener_Remove(token2);
CBLListener_Remove(token3);

token1 = nullptr;
token2 = nullptr;
token3 = nullptr;

cerr << "Sleeping to ensure async cleanup ..." << endl;
this_thread::sleep_for(500ms);
}
Expand Down Expand Up @@ -706,7 +699,6 @@ TEST_CASE_METHOD(QueryTest, "Query Listener and Coalescing notification", "[Quer
// Remove listener token and sleep to ensure async cleanup in LiteCore's LiveQuerier's _stop()
// functions is done before checking instance leaking in CBLTest's destructor:
CBLListener_Remove(listenerToken);
listenerToken = nullptr;
cerr << "Sleeping to ensure async cleanup ..." << endl;
this_thread::sleep_for(500ms);
}
Expand Down
2 changes: 1 addition & 1 deletion test/ReplicatorCollectionTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ TEST_CASE_METHOD(ReplicatorCollectionTest, "Document Replication Event", "[Repli
CHECK(replicatedDocs[bar2].error.code == 0);
}

TEST_CASE_METHOD(ReplicatorCollectionTest, "Default Conflict Resolver with Collections", "[Replicator]") {
TEST_CASE_METHOD(ReplicatorCollectionTest, "Default Conflict Resolver with Collections", "[.failed-version-vector][Replicator]") {
createDocWithJSON(cx[0], "foo1", kDefaultDocContent);
createDocWithJSON(cx[1], "bar1", kDefaultDocContent);

Expand Down
4 changes: 2 additions & 2 deletions test/ReplicatorEETest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ TEST_CASE_METHOD(ReplicatorLocalTest, "Default Resolver : Deleted Wins", "[Repli
}


TEST_CASE_METHOD(ReplicatorLocalTest, "Default Resolver : Higher Gen Wins", "[Replicator][Conflict]") {
TEST_CASE_METHOD(ReplicatorLocalTest, "Default Resolver : Higher Gen Wins", "[.failed-version-vector][Replicator][Conflict]") {
SECTION("No conflict resolved specified") {
config.conflictResolver = nullptr;
}
Expand Down Expand Up @@ -264,7 +264,7 @@ TEST_CASE_METHOD(ReplicatorLocalTest, "Default Resolver : Higher Gen Wins", "[Re
}


TEST_CASE_METHOD(ReplicatorLocalTest, "Default Resolver : Higher RevID Wins", "[Replicator][Conflict]") {
TEST_CASE_METHOD(ReplicatorLocalTest, "Default Resolver : Higher RevID Wins", "[.failed-version-vector][Replicator][Conflict]") {
SECTION("No conflict resolved specified") {
config.conflictResolver = nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/couchbase-lite-core

0 comments on commit 8431424

Please sign in to comment.