-
Notifications
You must be signed in to change notification settings - Fork 700
internal/filesystem consolidation, part 3 (no rename WriteFile, disaster recovery and rollbacks) #4324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1d98065
to
f315d4a
Compare
1dd7373
to
de499d0
Compare
No merge conflict, but could you rebase just in case |
|
||
import "github.com/containerd/nerdctl/v2/pkg/internal/filesystem" | ||
|
||
func InitFS(path string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a explanation comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
Rebased and comment added. |
Comment seems still missing |
My bad. Added it to the call: https://github.com/containerd/nerdctl/pull/4324/files#diff-202c9b24bcda33888c16a71750bd47809ffd474e126bfd2be11857033c0272f0R149 Will add more to the func declaration then. |
WriteFile now: - no longer relies on Rename, hence no longer changing files inodes - have disaster recovery and rollback Signed-off-by: apostasie <spam_blackhole@farcloser.world>
CI failures:
|
Added expanded comment to function declaration (along with comment on function call). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
err := ensureRecovery(fp) | ||
assert.NilError(t, err) | ||
|
||
cn, _ := os.ReadFile(fp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to check err?
// Create file | ||
dir := t.TempDir() | ||
fp := filepath.Join(dir, "pre-existing-file") | ||
_ = os.WriteFile(fp, []byte("original content"), 0o600) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to check err?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is indeed a bit lazy - though, given the (test) codepath, if this is failing, presumably everything is failing...
I see you merged.
If this is important, I can update in a follow on.
This is part 3 of internal/FS series.
<!> unlike the previous PRs that were essentially consolidation and enforcing atomic writes, this here is more ambitious, and adds net new features (eg: rollbacks and disaster recovery) - as such, it may be more controversial, so, open to discussion here, as usual <!>
This expands on the previous goal (Atomicity and Durability of
WriteFile
) by providing a new version ofWriteFile
that no longer relies on file renames - hence no longer changing inode - making it now 100% compatible withos.WriteFile
and usable everywhere (including when files are mounted).Furthermore, it also focuses on enabling Consistency, by introducing:
WriteFile
fails, the file is immediately reverted to its previous version (or removed if it did not exist prior)WriteFile
is hard interrupted for any reason, the nextReadFile
orWriteFile
call will first revert it to its original content (or remove it if it did not exist)WriteFileWithRollback
will return a rollback function that can revert changesrollback
should be used in the future to ensure higher-level operations consistency and to facilitate cleanup in case of failures. This should make higher-level operations failures able to revert state / cleanup leftover easier.I do appreciate this is additional complexity, and some of the code is not trivial.
But then:
container.Create
and other places that are manually rollbacking in a baroque / ad-hoc formFinally note that this changeset is purely internal to the
filesystem
package and does not change anything in the rest of nerdctl codebase.Let me know your thoughts overall, and if this is desirable or not.