fix: route shard saves through durable_write for crash safety - #28
Merged
Conversation
Shard rotation, save, and compact were calling usearch's native Index.save(path) which writes directly to disk without fsync or atomic rename. Replace with buffer serialization + durable_write (temp file, fdatasync, atomic os.replace). Persistence ordering is bloom → shard → tombstones so that tombstone removals only become visible after the shard data they depend on is durable. Also adds automatic bloom rebuild on load when the bloom file is missing or corrupt, and extracts _persist_bloom/_persist_tombstones helpers to eliminate duplication.
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.
Summary
Closes #26
Index.save(path)calls inShardedIndexwith buffer serialization +durable_write(temp file, fdatasync, atomicos.replace). Affectssave(),_rotate_shard(), andcompact()._load_bloom_if_exists._persist_bloom()and_persist_tombstones()helpers to eliminate duplicated save logic.Test plan
test_save_uses_durable_write— monkeypatchesdurable_writeto verify it's called for savetest_rotation_uses_durable_write— verifies rotation goes throughdurable_writetest_compact_uses_durable_write— verifies compact goes throughdurable_writetest_original_shard_intact_on_durable_write_failure— original file untouched when write failstest_rotation_persistence_order— bloom < shard < tombstones ordering verifiedtest_tombstone_removal_safe_across_crash— deleted key stays deleted after failed shard writetest_bloom_rebuild_on_corrupt_file— corrupt bloom triggers rebuildtest_bloom_missing_file_rebuilds_on_load— missing bloom triggers rebuildtest_tombstone_file_missing_on_reload— no crash, keys reappear as expectedtest_no_direct_save_path_in_sharded— AST audit: no.save(str(...))calls remaintest_save_progress_callback_preserved— progress callback passes through to buffer serialization