Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBL-6592: active pusher should always send proposeChanges regardless … #2199

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions C/c4DocEnumerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ class C4DocEnumerator::Impl
if ( !this->hasRecord() ) return false;

revid vers(record().version());
if ( (_options.flags & kC4IncludeRevHistory) && vers.isVersion() ) _docRevID = vers.asVersionVector().asASCII();
else
if ( (_options.flags & kC4IncludeRevHistory) && vers.isVersion() ) {
if ( _options.flags & kC4RevIDGlobalForm )
_docRevID = vers.asVersionVector().asASCII(_collection->dbImpl()->mySourceID());
else
_docRevID = vers.asVersionVector().asASCII();
} else
_docRevID = vers.expanded();

outInfo->docID = record().key();
Expand Down
4 changes: 2 additions & 2 deletions C/include/c4DocEnumeratorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ typedef C4_OPTIONS(uint16_t, C4EnumeratorFlags){
don't need to access the revision tree or revision bodies. You
can still access all the data of the document, but it will
trigger loading the document body from the database. */
kC4IncludeRevHistory = 0x40 ///< Put entire revision history/version vector in `revID`
};
kC4IncludeRevHistory = 0x40, ///< Put entire revision history/version vector in `revID`
kC4RevIDGlobalForm = 0x80};

/** Options for enumerating over all documents. */
typedef struct {
Expand Down
3 changes: 2 additions & 1 deletion Replicator/ChangesFeed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ namespace litecore::repl {
try {
_db.useLocked([&](C4Database* db) {
Assert(db == _checkpointer->collection()->getDatabase());
options.flags |= kC4RevIDGlobalForm;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of changing C4DocEnumerator, you can just call DBAccess::convertVersionToAbsolute on the revID.

C4DocEnumerator e(_checkpointer->collection(), _maxSequence, options);
changes.revs.reserve(limit);
while ( e.next() && limit > 0 ) {
Expand Down Expand Up @@ -240,7 +241,7 @@ namespace litecore::repl {
return false; // fail the rev: error getting doc
}

if ( !C4Document::equalRevIDs(doc->revID(), rev->revID) )
if ( !C4Document::equalRevIDs(doc->getSelectedRevIDGlobalForm(), rev->revID) )
return false; // skip rev: there's a newer one already

if ( needRemoteRevID ) {
Expand Down
4 changes: 1 addition & 3 deletions Replicator/Pusher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ namespace litecore::repl {
, _changesFeed(*this, _options, *_db, &checkpointer)
, _checkpointer(checkpointer) {
setParentObjectRef(replicator->getObjectRef());
if ( _options->push(collectionIndex()) <= kC4Passive
// Always use "changes" with version vectors
|| _db->usingVersionVectors() ) {
if ( _options->push(collectionIndex()) <= kC4Passive ) {
_proposeChanges = false;
_proposeChangesKnown = true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion Replicator/RevFinder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace litecore::repl {
if ( !changes && req->body() != "null"_sl ) {
warn("Invalid body of 'changes' message");
req->respondWithError({"BLIP"_sl, 400, "Invalid JSON body"_sl});
} else if ( (!proposed && _mustBeProposed) || (proposed && _db->usingVersionVectors()) ) {
} else if ( !proposed && _mustBeProposed ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete "But with version vectors, always use "changes"." on line 98

// In conflict-free mode plus rev-trees the protocol requires the pusher send
// "proposeChanges" instead. But with version vectors, always use "changes".
req->respondWithError({"BLIP"_sl, 409});
Expand Down
3 changes: 3 additions & 0 deletions Replicator/tests/ReplicatorVVUpgradeTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class ReplicatorVVUpgradeTest : public ReplicatorLoopbackTest {
}
};

#if 0
// Disabled, c.f. https://jira.issues.couchbase.com/browse/CBL-6593
TEST_CASE_METHOD(ReplicatorVVUpgradeTest, "Push After VV Upgrade", "[Push]") {
//- db pushes docs to db2. Both are still on rev-trees.
//- db and db2 both upgrade to version vectors.
Expand All @@ -74,6 +76,7 @@ TEST_CASE_METHOD(ReplicatorVVUpgradeTest, "Push After VV Upgrade", "[Push]") {
compareDatabases();
validateCheckpoints(db, db2, "{\"local\":103}");
}
#endif

TEST_CASE_METHOD(ReplicatorVVUpgradeTest, "Pull After VV Upgrade", "[Pull]") {
//- db pushes docs to db2. Both are still on rev-trees.
Expand Down
Loading