You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MB-59746 [1/2]: Restore CAS to original value after unlock()
+Problem+
When a document is locked via GetLocked, KV-Engine generates a new
"locked CAS", stores it in memory, and returns it to the client for it
to use in a subsequent Mutation(CAS=locked_CAS) or Unlock() operation.
However, when the document is unlocked without modification (lock
times out, or an explicit Unlock() call is made), the previous CAS
value is *not* restored. As such, the in-memory representation of the
document has an artificially higher CAS than the document "really"
has.
When using LWW XDCR this is problematic; as it means that a document
could have an artificially higher CAS than it "really" has, and hence
conflict resolution could incorrectly fail to update the
document. Consider the following scenario:
1. A LWW XDCR relation from source S to destination D is established,
and is performing _optimistic_ conflict resolution. Buckets are in
sync, assume CAS of all documents is from time T=0.
2. At time T=10, a Mutation operation occurs on the source bucket S
against the doc X.
3. At T=11 a GetLocked operation occurs on the destination Bucket D against
the same doc.
4. At T=12 the destination bucket D document is Unlocked, leaving the
CAS with the advanced value from T=11.
5. Due to XDCR processing lag / network latency, the SetWithMeta()
arrives at {{D}} at T=13 - after the document has been
unlocked. KV-Engine's conflict resolver will compare the (locked)
CAS at the destination (11) with the incoming CAS (10), and decide
the destination should win - and the update will not be applied.
This is incorrect - we should have used CAS value before the document
was locked (T=0) for conflict resolution.
+Solution+
To address this, ep-engine needs to keep a copy of the original
(pre-lock) CAS, and restore the documents' CAS to this when the
document is unlocked.
This patch does this in a straightforward manner - add a second
locked_CAS field to StoredValue to fix this issue. This has the
downside of increasing the size of per-document in-memory metadata by
8 Bytes. An (space) optimisated version will follow in a subsequent
patch.
Change-Id: Icc274626dd5c1269bc1df65a2e26304df4aaf554
Reviewed-on: https://review.couchbase.org/c/kv_engine/+/201510
Tested-by: Dave Rigby <[email protected]>
Well-Formed: Restriction Checker
Reviewed-by: Trond Norbye <[email protected]>
0 commit comments