fix(rust_brain): preserve HLC on restore and in gossip receive#22
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(rust_brain): preserve HLC on restore and in gossip receive#22cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
v0.6.0 switched monotonic enforcement from ts_ns to HLC but two call paths were not updated: - restore_from_file() dropped HLC from snapshots, assigning fresh clocks that blocked legitimate post-restore replication and broke causal order. - gossip.receive() omitted HLC, so late-arriving events got a fresh local timestamp and could overwrite newer data on the same key. Restore now round-trips HLC (with ts_ns fallback for legacy snapshots) and advances the process clock. Gossip applies remote HLCs via update_hlc(), rejects stale writes, and skips unordered updates to existing keys when no HLC is present. Regression tests added for both paths. Co-authored-by: Daniel <DJLougen@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug and impact
v0.6.0 switched monotonic write enforcement from
ts_nsto Hybrid Logical Clock (HLC), but two replication paths were not updated:restore_from_file()— snapshots include HLC in node payloads, but restore ignored them and assigned fresh local clocks. After a crash-recovery restore, legitimate post-restore writes/replication with pre-crash HLC timestamps are rejected (TimestampRegression), causing silent data loss on distributed recovery.gossip.receive()— gossip events were applied without HLC, so stale remote events received a fresh local timestamp and could overwrite newer local data on the same key.Root cause
HLC was added to
remember()andto_dict()in v0.6.0, butrestore_from_file(),bulk_write(), andgossip.receive()were not updated to round-trip or apply remote HLC values.Fix
_parse_hlc()helper with legacyts_nsfallback for pre-v0.6.0 snapshotsrestore_from_file(): restore HLC per node and advance the process clock via_hlc.update()bulk_write(): pass through HLC when presentgossip.receive(): apply remote HLC viaupdate_hlc(), reject stale writes, skip unordered updates to existing keys when HLC is missingValidation
test_enterprise_backup.pyandtest_gossip.py