Fix atomicity and durability + some small fixes#366
Open
bigerl wants to merge 17 commits into
Open
Conversation
This reverts commit 7a4a21e.
liss-h
force-pushed
the
feature/durable-file-handling
branch
from
July 24, 2026 09:42
e757931 to
b5df68f
Compare
KIwabuchi
self-requested a review
July 25, 2026 23:27
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.
Hi @KIwabuchi
it has been a while since we have been active in metall. We ran lately into some problems with persistence and durability. Here the PR to fix them. @liss-h (See dice-group#17) already reviewed it from our side.
This PR fixes the properly-closed mark, introduces full error handling around files and fixes some minor other issues found along the way. The changes are guarded by regression tests.
Problems with the previous implementation
close()ignored errors. It discarded the results of the metadata serialization and the segment sync and created the mark unconditionally. A failed write (ENOSPC, EIO) still produced a datastore thatconsistent()reported as good.create()andremove()could clear the directory of a datastore that another process had open.snapshot()andcopy()New design
Two files with separate roles replace the overloaded mark:
<base>/mds_lock). It is never deleted and carries the flock: exclusive for writers, shared for readers.create(),open(),remove(),snapshot(), andcopy()all take it, so destroying or replacing an open datastore is refused instead of executed. Existing datastores get the lockfile on first open.Writes acked by the close mark are now durable and atomic:
write_file_atomicallythat does: temp file in the same directory, fsync, rename, parent directory fsync to make the operation atomic and durable.close()now returns a bool that is only true if all steps were successful.<destination>/.tmp_datastore, the whole tree is fsynced, the mark is written inside, and the result is published with a single rename plus directory fsync. A half-written snapshot is never visible under the final path.Misc Fixes
mdtl::munmap(..., call_msync = true)never unmapped. It now syncs and unmaps. This has been there since the initial commit.msync(MS_SYNC)is skipped on Linuxextend_file_size_manuallywrote an uninitialized buffer instead of zeros and ignored pwrite results.Behavior changes
manager_kernel::close()returns bool instead of void.create(),remove(),snapshot(), andcopy()fail if the datastore or the destination is open elsewhere. Previously they proceeded and could scramble data.mds_lock.Tests
test/utility/file_durability_test.cpp: the new file primitives, including that a failed atomic write keeps the old content.test/sandbox.hpp: utility ported from https://github.com/dice-group/dice-template-library/blob/main/include/dice/template-library/sandbox.hpp for crashing a process within a test without dragging the whole test framework down.test/kernel/durability_test.cpp: exercise crashes, concurrent access throughout the API