fix(store): relocate LocalStore temporary files to configurable tmp_dir#4173
fix(store): relocate LocalStore temporary files to configurable tmp_dir#4173omar-merhebi wants to merge 1 commit into
Conversation
`LocalStore` now writes temporary files to a dedicated `tmp_dir` rather than directly inside the store path. Previously, `_atomic_write` wrote temp files ending in `.partial` inside the store which triggered `ZarrUserWarning` during concurrent reading and listing of the store. The location defaults to the system temporary directory (via `tempfile.gettempdir()`), and is overridable via the `tmp_dir` argument to `LocalStore` or globally via the `store.local.tmp_dir` config option (env var `ZARR_STORE__LOCAL__TMP_DIR`). The temporary directory must be on the same filesystem as the store, otherwise `_atomic_write` will raise `OSError` with `EXDEV`. The pre-existing try/except now also has a specific catch for `EXDEV` and re-raises, informing the user to change the `tmp_dir` value to a location on the same filesystem rather than emitting a raw `OSError`. Documented this new option in config.md and storage.md. Fixes zarr-developers#4161.
4ae0f4e to
a8f6db7
Compare
|
Flagging this before anyone digs into the failing CIs Both failures have the same root cause: temps default to the system temp dir, which is on a different filesystem than the store, so the RTD (Linux): temp dir Windows (windows-latest, py3.14): the temp dir is on ubuntu-latest: This passes because the Ubuntu runners keep temp on the checkout's disk so it's the same filesystem on those runners and it works. Ubuntu moved to using Therefore, any setup where a store isn't on the temp dir's filesystem (e.g., a |
Summary
LocalStorenow writes temporary files to a dedicatedtmp_dirrather than directly inside the store path. Previously,_atomic_writewrote temp files ending in.partialinside the store which triggeredZarrUserWarningduring concurrent reading and listing of the store.The location defaults to the system temporary directory (via
tempfile.gettempdir()), and is overridable via thetmp_dirargument toLocalStoreor globally via thestore.local.tmp_dirconfig option (env varZARR_STORE__LOCAL__TMP_DIR). The temporary directory must be on the same filesystem as the store, otherwise_atomic_writewill raiseOSErrorwithEXDEV. The pre-existing try/except now also has a specific catch forEXDEVand re-raises, informing the user to change thetmp_dirvalue to a location on the same filesystem rather than emitting a rawOSError. Documented this new option in config.md and storage.md. Fixes #4161.For reviewers
I added a specific catch in the try/except block of
_atomic_write()that specifically catchesOSErrorcaused byEXDEVand instructs the user to pick a temporary directory on the same filesystem if the atomic write fails. Happy to modify the message, change logic, or remove it entirely if preferred. I also verified thaterrno.EXDEVis theerrnothat is raised on both Unix and Windows. Used the convention of naming the config arg and vars astmp_dirto copy the oldtmp_pathvariable in_atomic_write(). Also happy to change that naming scheme if preferable. I specifically avoidedshutil.move()here to keepLocalStoreatomic (shutil.move()attemptsos.rename()and falls back to copying if it fails). This follows the design discussed in #4161.Author attestation
TODO
docs/user-guide/*.mdchanges/