From 3025a182ccc087e43ac71c1f539d05e2d5e0c28d Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Wed, 28 Feb 2018 22:58:34 -0800 Subject: [PATCH] Fix two bugs in client synchronization. (#270) Both could occur if a client and server write to the same key and the server disconnects/reconnects (or restarts). Bug 1: the client did not properly update the sequence number in this case, so later server updates could be ignored until the sequence number wrapped. Bug 2: the client did not properly set the id and sequence number for the update message back to the server, so the server would ignore the message. --- src/main/native/cpp/Storage.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/native/cpp/Storage.cpp b/src/main/native/cpp/Storage.cpp index 8bb37f8..9f8a7a3 100644 --- a/src/main/native/cpp/Storage.cpp +++ b/src/main/native/cpp/Storage.cpp @@ -418,11 +418,12 @@ void Storage::ApplyInitialAssignments( StringRef name = msg->str(); Entry* entry = GetOrNew(name); + entry->seq_num = seq_num; + entry->id = id; if (!entry->value) { // doesn't currently exist entry->value = msg->value(); entry->flags = msg->flags(); - entry->seq_num = seq_num; // notify m_notifier.NotifyEntry(entry->local_id, name, entry->value, NT_NOTIFY_NEW); @@ -431,11 +432,11 @@ void Storage::ApplyInitialAssignments( // then we don't update the local value and instead send it back to the // server as an update message if (entry->local_write && !entry->IsPersistent()) { + ++entry->seq_num; update_msgs.emplace_back(Message::EntryUpdate( entry->id, entry->seq_num.value(), entry->value)); } else { entry->value = msg->value(); - entry->seq_num = seq_num; unsigned int notify_flags = NT_NOTIFY_UPDATE; // don't update flags from a <3.0 remote (not part of message) if (conn.proto_rev() >= 0x0300) { @@ -448,8 +449,7 @@ void Storage::ApplyInitialAssignments( } } - // set id and save to idmap - entry->id = id; + // save to idmap if (id >= m_idmap.size()) m_idmap.resize(id + 1); m_idmap[id] = entry; }