fix(rust_brain): preserve HLC on restore and gossip receive#21
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(rust_brain): preserve HLC on restore and gossip receive#21cursor[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
Critical data loss after snapshot restore. v0.6.0 switched monotonic write enforcement from
ts_nsto Hybrid Logical Clock (HLC), butrestore_from_file()did not round-trip HLC values from snapshots. After restart, restored nodes received fresh local HLC timestamps. Any legitimate post-crash write or gossip replay carrying the pre-crash HLC was rejected withTimestampRegression, causing silent data loss.Stale gossip overwrites.
gossip.receive()ignored remote HLC timestamps and calledremember()withouthlc=, assigning a fresh local clock. Late-arriving gossip events could overwrite newer local data on the same key.Root cause
Two call paths were missed when HLC enforcement landed in v0.6.0 (
07a1c75):restore_from_file()constructedMemoryNodewithout restoringhlcor advancing the process clock via_hlc.update().gossip.receive()did not passhlc,ts_ns, oredgesthrough toremember().Fix
_parse_hlc()helper with legacyts_nsfallback for pre-v0.6.0 snapshots.restore_from_file(): restore HLC per node and call_hlc.update()so the process clock stays ahead.bulk_write(): passhlcthrough when present in row dicts.gossip.receive(): apply remote HLC viaupdate_hlc(), reject stale writes, skip missing-HLC updates on existing keys.Validation
tests/test_enterprise_backup.py::test_restore_preserves_hlc_for_replicationtests/test_gossip.py: 4 new HLC ordering tests