Repository navigation
Conversation
Database::create_new fsynced keyspaces/ before the meta keyspace (keyspaces/0) existed, and wrote the version marker before creating it, so the keyspaces/0 directory entry was never durable. It also created 0.jnl before keyspaces/0, so a failure to create the meta keyspace left a journal behind without a version marker; retrying then took the create_new path again and failed with AlreadyExists on 0.jnl. Create the meta keyspace and fsync keyspaces/ before creating the journal and the version marker, so the 0.jnl window is gone and both directory entries (keyspaces/0 and keyspaces/<id>) are durable. Keyspace::create_new now fsyncs keyspaces/ after creating keyspaces/<id>; without it a power loss after creating a keyspace and persisting writes could lose the keyspace directory entry, causing recovery to omit the keyspace and skip its journal records. Add a test that obstructs keyspaces/0, asserts creation fails, and asserts that a retry succeeds and reads back the persisted data.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the keyspace directory-sync durability changes.
No open issues 🎉
What changed in this PR
This PR addresses #356 by syncing the keyspaces/ directory after creating metadata and user keyspace folders, closing a Unix power-loss durability gap.
Changes:
- Creates the metadata tree and syncs its parent directory before creating the journal and version marker.
- Syncs the parent directory of new user keyspaces before registering them in metadata.
- Adds an integration test verifying retry after metadata-tree creation fails, followed by successful persistence and reopening.
| File | Description |
|---|---|
| tests/db_open.rs | Tests retry after failed metadata-tree creation and data recovery after reopening. |
| src/keyspace/mod.rs | Syncs keyspaces/ after opening a new keyspace tree. |
| src/db.rs | Moves metadata-tree creation and directory syncing before journal and version-marker creation. |
Review effort: Balanced
Closes #356
Database::create_newcalledfsync_directoryonkeyspaces/before creatingkeyspaces/0, andKeyspace::create_newnever calledfsync_directoryonkeyspaces/after creatingkeyspaces/<id>. On Unix, losing either unsynced directory entry on power loss could drop committed keys afterPersistMode::SyncAllor causerecover_keyspacesto remove intact user keyspaces.Changes:
Database::create_new, open the meta tree (keyspaces/0) and callfsync_directoryonkeyspaces/before creating0.jnland writing the version marker, sokeyspaces/0is durable before bootstrap completes and a failed meta tree creation does not strand0.jnlon retry.Keyspace::create_new, callfsync_directoryonkeyspaces/after opening the new keyspace tree and before recording it inmeta_keyspace.Verified on Linux with
strace(keyspaces/is now synced afterkeyspaces/0beforeversion, and afterkeyspaces/1),cargo fmt --all -- --check,cargo clippy,cargo test --features lz4, and whitebox tests.Summary by CodeRabbit