fix(rust_brain): preserve HLC on snapshot restore and gossip receive#53
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(rust_brain): preserve HLC on snapshot restore and gossip receive#53cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
restore_from_file() dropped HLC timestamps from snapshots, assigning fresh (wall, 0, uuid) values instead. After disaster recovery, any causal successor write with the pre-crash HLC was rejected with TimestampRegression, causing silent data loss on replay/gossip. - Add _parse_hlc() for wire/snapshot normalisation with legacy fallback - restore_from_file: restore hlc, update global _hlc, hold lock during restore - bulk_write: pass through hlc from row payloads - gossip.receive: apply hlc, reject stale overwrites, skip missing-hlc updates Regression tests cover snapshot round-trip and gossip HLC ordering. 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
restore_from_file()andgossip.receive()dropped Hybrid Logical Clock (HLC) timestamps introduced in v0.6.0. After disaster recovery from a snapshot, restored nodes received fresh(wall, 0, uuid)HLCs instead of their original causal timestamps. Any subsequent write or gossip replay using the pre-crash HLC was rejected withTimestampRegression, causing silent data loss on recovery and cross-node sync.Concrete trigger: Node writes
remember("k", "v1", hlc=(5000, 10, "nodeA")), snapshots, crashes, restores. A causal successorremember("k", "v2", hlc=(5000, 11, "nodeA"))raisesTimestampRegressionbecause restore assigned a newer wall-clock HLC.Root cause
restore_from_file()constructedMemoryNodewithout passinghlcfrom the snapshot dict (defaulting to a fresh HLC).gossip.receive()similarly omittedhlc/ts_nswhen callingremember(). The global_hlcwas never advanced to the max restored timestamp.Fix
_parse_hlc()helper with legacyts_nsfallback for pre-v0.6.0 snapshotsrestore_from_file: restorehlc, call_hlc.update()per node, hold lock during restorebulk_write: pass throughhlcfrom row payloadsgossip.receive: applyhlc, reject stale overwrites, skip missing-HLC updates on existing keysValidation
test_restore_preserves_hlc_for_replication, gossip HLC ordering tests