fix(rust_brain): preserve HLC on snapshot restore and gossip receive#48
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(rust_brain): preserve HLC on snapshot restore and gossip receive#48cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
After snapshot restore, nodes were assigned fresh HLC timestamps instead of the stored values from the snapshot. Post-restore causal writes with legitimate successor HLCs were rejected as TimestampRegression, causing silent data loss in disaster-recovery and multi-node gossip scenarios. - Add _parse_hlc() for snapshot/wire HLC normalisation - Restore HLC on snapshot load and advance global _hlc - Pass HLC through bulk_write and gossip receive - Reject stale gossip updates; skip HLC-less updates on existing keys - Add regression tests for restore round-trip and gossip 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
After snapshot restore,
restore_from_file()assigned fresh HLC timestamps instead of the values stored in the snapshot. Post-restore causal writes with legitimate successor HLCs were rejected asTimestampRegression, causing silent data loss in disaster-recovery and multi-node gossip scenarios.Concrete trigger: Node writes
k=v1withhlc=(5000, 10, nodeA), snapshots, crashes, restores. A causal successor writek=v2withhlc=(5000, 11, nodeA)is rejected because restore assigned a fresh wall-clock HLC far in the future.Gossip had the same class of bug:
receive()ignored HLC from peer events, allowing stale overwrites or rejecting valid updates.Root cause
restore_from_file()createdMemoryNodewithout passinghlc, so the default factory assigned_hlc.now(). The global_hlcwas never advanced from restored nodes.bulk_write()andgossip.receive()also omitted HLC passthrough.Fix
_parse_hlc()for snapshot/wire HLC normalisation (with legacy fallback for pre-v0.6.0 snapshots)_hlcbulk_writeandgossip.receive()restore_from_fileandgc_expiredValidation
test_restore_preserves_hlc_for_replication, gossip HLC ordering tests