Skip to content

fix(tiles): one temporary name counter, and create_new lands whole or not at all - #2

Merged
HaoZeke merged 4 commits into
mainfrom
fix/posix-store-temp
Nov 16, 2026
Merged

HaoZeke merged 4 commits into
mainfrom
fix/posix-store-temp

Conversation

@HaoZeke

@HaoZeke HaoZeke commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Temporary names are now unique across every PosixStore in the process, and create_new writes a temporary file and links it at the path so a cut-short write leaves nothing there.

  • Each PosixStore::open started its own counter at 0 and named temporary files after the process id and that counter, so two handles on one root in one process drew the same name and truncated the other's file. The counter is now a static shared by all handles. The file is created with create_new, a name that is taken is passed over rather than truncated, and a temporary file whose write or sync fails is removed.
  • create_new opened the path itself and wrote into it, so a write that failed part way, or a crash, left a partial file, and every later create_new there answered that something was already stored. It now writes and syncs a temporary file, links it at the path, removes the temporary name and syncs the directory. The root needs hard links.
  • One test writes a temporary file through each of two handles and expects two paths, each with its own bytes. Another reruns under a file size limit, where create_new of 64 KiB fails with EFBIG, then expects nothing at the path or under .tmp and a create_new that succeeds.

The branch has towncrier fragments.

Each PosixStore::open starts its own counter at 0 and names temporary
files after the process id and that counter, so two handles on one root
in one process draw the same name and File::create truncates the other's
file before its rename. The test writes a temporary file through each of
two handles and expects two paths, each with its own bytes.
The counter behind temporary file names is now a static shared by all
handles in the process instead of one per open, so two handles on one
root never draw the same name. The file is created with create_new, and
a name that is taken, as by an earlier process with the same id, is
passed over rather than truncated. A temporary file whose write or sync
fails is removed.
The module doc says a write lands whole or not at all, but
PosixStore::create_new opens the path itself with create_new and writes
into it. A write that fails part way, or a crash, leaves the head of the
bytes at the path, and every later create_new there answers that
something is already stored. The test runs itself again under a file
size limit, where create_new of 64 KiB fails with EFBIG, then expects
nothing at the path or under .tmp and a create_new that succeeds.
create_new now writes and syncs a temporary file, links it at the path
with hard_link, which fails with AlreadyExists when something is there,
removes the temporary name and syncs the directory. A failed write
leaves nothing at the path, as put already did, so a retry can create
it. The tree-state and publish locks and rfc9162-log's run files are
made this way. The module and trait docs say so, and that the root needs
hard links.
@HaoZeke
HaoZeke merged commit 5923245 into main Nov 16, 2026
6 checks passed
@HaoZeke
HaoZeke deleted the fix/posix-store-temp branch November 16, 2026 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant