Skip to content

Commit e07fa42

Browse files
CBL-2676: Puller needs to consider the kSynced flag (#1309) (#1350)
CBL-2676: Puller needs to consider the kSynced flag The kSynced flag is a shortcut flag on a document that indicates that the latest revision has been pushed to the remote, but that this information has not yet been recorded into the body of the document (i.e. the document has not been saved since). The pusher uses a method which consolidates this information when deciding which revision to send as the ancestor in a proposeChanges message. The puller also needs to consolidate this information when deciding whether or not a change is properly set as the remote ancestor when a changes message comes from the other side because otherwise it will sometimes falsely believe it already has things correctly set by scanning the document body, but not considering the kSynced flag. Co-authored-by: Jim Borden <[email protected]>
1 parent bddb88b commit e07fa42

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

LiteCore/Database/TreeDocument.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,12 @@ namespace litecore {
707707
RevTree tree(rec.body, rec.extra, 0_seq);
708708
auto current = tree.currentRevision();
709709

710+
if (remoteDBID == RevTree::kDefaultRemoteID && (rec.flags & DocumentFlags::kSynced)) {
711+
// CBL-2579: Special case where the main remote DB is pending local update
712+
// of its remote ancestor
713+
tree.setLatestRevisionOnRemote(RevTree::kDefaultRemoteID, current);
714+
}
715+
710716
// Does it exist in the doc?
711717
if (const Rev *rev = tree[revID]) {
712718
if (rev->isBodyAvailable())

LiteCore/Query/SQLiteFleeceFunctions.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,13 +496,14 @@ namespace litecore {
496496
#pragma mark - REVISION HISTORY:
497497

498498

499-
// fl_callback(docID, revID, body, extra, sequence, callback) -> string
499+
// fl_callback(docID, revID, body, extra, sequence, callback, flags) -> string
500500
static void fl_callback(sqlite3_context* ctx, int argc, sqlite3_value **argv) noexcept {
501501
RecordUpdate rec(valueAsSlice(argv[0]), valueAsSlice(argv[2]));
502502
rec.version = valueAsSlice(argv[1]);
503503
rec.extra = valueAsSlice(argv[3]);
504504
rec.sequence = sequence_t(sqlite3_value_int(argv[4]));
505-
auto callback = sqlite3_value_pointer(argv[5], kWithDocBodiesCallbackPointerType);
505+
rec.flags = (DocumentFlags)sqlite3_value_int(argv[5]);
506+
auto callback = sqlite3_value_pointer(argv[6], kWithDocBodiesCallbackPointerType);
506507
if (!callback || !rec.key) {
507508
sqlite3_result_error(ctx, "Missing or invalid callback", -1);
508509
return;
@@ -535,7 +536,7 @@ namespace litecore {
535536
{ "fl_bool", 1, fl_bool },
536537
{ "array_of", -1, array_of },
537538
{ "dict_of", -1, dict_of },
538-
{ "fl_callback", 6, fl_callback },
539+
{ "fl_callback", 7, fl_callback },
539540
{ }
540541
};
541542

LiteCore/RevTrees/RevTreeRecord.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ namespace litecore {
8686
// stored on the server, it may be the base of a merge in the future,
8787
// so preserve its body:
8888
setLatestRevisionOnRemote(kDefaultRemoteID, cur);
89+
_rec.clearFlag(DocumentFlags::kSynced);
8990
keepBody(cur);
9091
_changed = false;
9192
}

LiteCore/Storage/SQLiteKeyStore.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ namespace litecore {
478478

479479
// Construct SQL query with a big "IN (...)" clause for all the docIDs:
480480
stringstream sql;
481-
sql << "SELECT key, fl_callback(key, version, body, extra, sequence, ?) FROM kv_" << name()
481+
sql << "SELECT key, fl_callback(key, version, body, extra, sequence, flags, ?) FROM kv_" << name()
482482
<< " WHERE key IN ('";
483483
unsigned n = 0;
484484
for (slice docID : docIDs) {

0 commit comments

Comments
 (0)