Improve client connection synchronization behavior.

The original synchronization behavior was troublesome for two reasons:
- It had unpredictable behavior for updated values
- It brought back to life deleted values

Instead of relying on the server to inform the client regarding reconnections,
the client keeps track of what values have been modified by user code on the
client.  When the client connects to the server, the following occurs.

For entries that have been modified by user code on the client:
- If the entry is not persistent, the server value is overwritten with the
  client value
- If the entry does not exist on the server, the client sends an assignment
  to the server to recreate it on the server

For entries that have not been modified by user code on the client:
- The client value is overwritten with the server value
- If the entry does not exist on the server, the client deletes the entry

Fixes #8.
This commit is contained in:
Peter Johnson
2017-08-13 10:11:29 -07:00
parent 8099d6dbd7
commit 7c1d2f4bc4
2 changed files with 40 additions and 16 deletions

View File

@@ -156,6 +156,10 @@ class Storage : public IStorage {
// Sequence number for update resolution.
SequenceNumber seq_num;
// If value has been written locally. Used during initial handshake
// on client to determine whether or not to accept remote changes.
bool local_write{false};
// RPC handle.
unsigned int rpc_uid{UINT_MAX};
@@ -220,6 +224,8 @@ class Storage : public IStorage {
std::unique_lock<std::mutex>& lock, bool local);
// Must be called with m_mutex held
template <typename F>
void DeleteAllEntriesImpl(bool local, F should_delete);
void DeleteAllEntriesImpl(bool local);
Entry* GetOrNew(StringRef name, bool* is_new = nullptr);
};