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
// sleep until the server's CAS would have caught up to the generated version, then re-stamp the CAS on the document so cv.ver <= cas holds for XDCR replication
3259
-
time.Sleep(time.Duration(gap))
3265
+
// Sleep until the CAS-assigning clock has advanced far enough that a fresh CAS would reach the
3266
+
// generated version, then re-stamp so cv.ver <= cas holds for XDCR.
3267
+
//
3268
+
// The catch depends on three clocks, not two. The version is stamped from Sync Gateway's HLC;
3269
+
// the CAS is stamped from the HLC of whatever assigns it (a Couchbase Server node, or Rosmar under unit tests).
3270
+
// Either way, the sleep is the third clock: time.Sleep waits on the monotonic clock, which is a separate time
3271
+
// source from the wall clock used by CAS generation on Windows. This means sleeping for the physical gap may
3272
+
// still leave the CAS just short of the next physical-tick boundary.
3273
+
//
3274
+
// That tiny shortfall is amplified because version and CAS are compared after being floored to
3275
+
// physical ticks (the low HLCLogicalBits are cleared). The success margin is already sub-tick, so a
3276
+
// CAS clock that lands even 1ns before the target tick boundary produces a re-stamped CAS a whole
3277
+
// tick (~65us) below the version. This is most visible under Rosmar, where the version and CAS share
3278
+
// the same in-process clock and so land right on the boundary. Padding the sleep past the boundary
3279
+
// makes us overshoot it regardless of the drift; the resulting CAS is at most versionCASCorrectionSlack
3280
+
// larger than strictly required, which is harmless.
// Verify the re-stamp actually resolved the invariant. It may not when the version was ahead only within
3278
-
// the logical-counter bits (the physical gap, and so the sleep, was ~0 and the server advanced its CAS by
3279
-
// only a logical tick). We deliberately do not retry; a later mutation will resolve it, but surface a
3280
-
// warning so the (likely clock-skew/divergence) condition is visible.
3299
+
// With the sleep padded past the tick boundary, a CAS still below the version indicates real clock
3300
+
// skew/divergence rather than a rounding miss. We deliberately do not retry; a later mutation will
3301
+
// resolve it, but surface a warning so the condition is visible.
3281
3302
ifdoc.HLV.Version>cas2 {
3282
3303
base.WarnfCtx(ctx, "Re-stamped CAS %d for doc %q is still below the generated version %d; not retrying - the document may be skipped by XDCR until a later mutation", cas2, base.UD(doc.ID), doc.HLV.Version)
0 commit comments