Repository navigation
fix(local): sync the directories a durable write actually creates; bound the unsynced set - #5
Merged
Conversation
`create_parent_dirs` recorded the deepest existing ancestor, called `create_dir_all`, and synced from the new parent up to that ancestor. A concurrent delete with automatic cleanup can remove the ancestor in between; `create_dir_all` recreated it, and its new entry in the directory above was never synced. Create the missing components one `create_dir` at a time, registering each before creating it, and sync every directory from the deepest one created up to the one holding the highest one's entry. That also covers a directory another creation made in between, which holds an entry made here.
…ed creation A creation that failed before creating anything (EACCES, ENOSPC) still recorded its would-be directories in the process-global unsynced set, and nothing cleared them. Record only directories that exist, or whose state cannot be determined.
There was a problem hiding this comment.
🔵 Needs a closer look
Concurrent directory creation and crash-durability guarantees require final human validation of synchronization interleavings.
No open issues 🎉
What changed in this PR
This follow-up strengthens LocalFileSystem durable writes by tracking directories actually created during concurrent cleanup and reducing stale entries in the process-wide unsynced set.
Changes:
- Creates directories individually and syncs the range covering newly created directories and their parent entries.
- Excludes confirmed nonexistent or non-directory paths from failed-creation tracking, with regression tests for cleanup races and failed writes.
- Documents that stores with different
fsyncsettings must not share a root within one process.
| File | Description |
|---|---|
src/local.rs |
Updates directory creation, durability tracking, documentation, and regression tests. |
Review effort: Balanced
This was referenced Nov 13, 2026
reidkaufmann
added a commit
that referenced
this pull request
Nov 13, 2026
…directory chain Mirrors upstream draft local-durable-dir-creation (8de2a2d, on apache main 279572e) and replaces the fork's implementation from #3 and #5. `create_parent_dirs` delegates to `create_dir_all_durable(dir, create, sync)`, which registers the missing directories in `CREATING_DIRS`, creates them one component at a time while registering each one it tries, and syncs from `dir` up to the parent of the highest registered directory. A durable write into a directory being created waits on `DIRS_CHANGED` (parking_lot `Condvar`). Differences from the fork's code this replaces: the walk starts at `dir` and stops at the parent of the highest registered directory, not the highest one this call created, so it also covers a directory an untracked creator made after the snapshot and runs when this call created nothing; tests inject `create` and `sync` closures instead of the `#[cfg(test)]` hooks `BEFORE_CREATE_DIR` and `SYNCED_DIRS`, and assert the exact sync sequence; the `with_fsync` doc paragraph is the draft's shorter one. The fork's unsynced records and their tests are removed here and return in the next commit in the upstream draft's form; the in-between-creation test is dropped, as upstream did, because the new walk covers that case by construction. (cherry picked from commit f21a592)
reidkaufmann
added a commit
that referenced
this pull request
Nov 13, 2026
…as unsynced Mirrors upstream draft local-unsynced-after-failed-creation (fbb5ef0, stacked on 8de2a2d). `CREATING_DIRS` becomes `DIRS: Mutex<DirRegistry>` with the `creating` counts and an `unsynced` set. `create_dir_all_registering` records every registered directory that exists after its `create_dir` in `CreatingDirs::reached`; unless the creation synced them, `Drop` moves those records to `unsynced`. A durable write under an unsynced directory syncs from its parent up to the parent of the highest unsynced ancestor (`fsync_parent_dir_with`, which tests call with a recording closure) and then clears the records on that chain. Differences from the fork's unsynced set (#3, bounded in #5): `Drop` does no I/O; a registered directory whose `create_dir` was never tried is not recorded, and one deleted after it was reached still is; the 0o555 `put` loop test is replaced by a direct test of the recorded set; `wait_for_ancestor_creation` returns early when nothing is registered and no record exists. (cherry picked from commit 22ad666)
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.
Follow-up to #4 for two of Copilot's findings on
create_parent_dirs.Snapshot race (#4 r4379279400).
create_parent_dirsrecorded the deepest existing ancestor, calledcreate_dir_all, and synced up to that ancestor. Withwith_automatic_cleanup(true), a concurrent delete can remove the ancestor in between;create_dir_allrecreated it, and its new entry in the directory above was never synced.Fix: create the missing components one
create_dirat a time, registering each before creating it (so concurrent durable writes into it keep waiting, as before), and sync every directory from the deepest one this call created up to the one holding the highest one's entry. That range also covers a directory another creation made in between, which holds an entry made here.Tests, both failing without the fix:
fsync_creation_syncs_an_ancestor_removed_by_concurrent_cleanup(a#[cfg(test)]hook beforecreate_dirremoves the ancestor; the root must be synced) andfsync_creation_syncs_a_directory_another_creation_made_in_between(the hook createsx/ybetween this call's creation ofxand ofx/y/z;x/ymust be synced).Unbounded
unsyncedset (#4 r4379279468). A creation that failed before creating anything (EACCES, ENOSPC) still recorded its would-be directories in the process-globalunsyncedset, and nothing cleared them.Fix: on drop without a completed sync, record only directories that exist or whose state cannot be determined.
Test:
fsync_failed_creation_records_only_directories_that_exist(50 failed puts under an unwritable directory leave the set unchanged); fails without the fix.fsync_write_syncs_directories_a_failed_creation_leftstill covers the existing-directory case.Docs (#4 r4379279335):
with_fsyncnotes that stores with differentfsyncsettings must not share a root within one process. No behaviour change.For influxdata/influxdb_pro#6332; influxdb_pro will pin this branch's head.