Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

Commit

Permalink
Fix two bugs in client synchronization. (#270)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
PeterJohnson authored Mar 1, 2018
1 parent c80b0de commit 3025a18
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/native/cpp/Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 3025a18

Please sign in to comment.