Skip to content

Make storage upload atomic - #325

Open
damilolaedwards wants to merge 1 commit into
ethpandaops:masterfrom
damilolaedwards:fix/storage-upload-atomicity
Open

Make storage upload atomic#325
damilolaedwards wants to merge 1 commit into
ethpandaops:masterfrom
damilolaedwards:fix/storage-upload-atomicity

Conversation

@damilolaedwards

Copy link
Copy Markdown

Summary

Upload opened the destination directly with O_TRUNC and streamed the
request body straight into it. The source is a live sandbox HTTP stream
that can break mid-transfer, which is a normal occurrence, not an edge
case, but a mid-copy failure had already truncated whatever was at that
key. A re-upload to the same filename, which happens any time a script or
session step reruns and writes the same output name again, could destroy a
prior good file and replace it with a partial one while the caller was
told the upload failed and nothing happened.

Writes to a temp file in the same directory instead and renames it over
the destination only once the copy and close both succeed. Any failure
along the way removes the temp file and leaves the existing key untouched.

Test plan

  • go test -race ./pkg/storage/...
  • New tests cover a failed re-upload to an existing key (prior file
    must survive) and a failed upload to a brand-new key (nothing should
    be left behind); confirmed both fail on the old code
  • go build ./..., go vet ./...

Upload opened the destination directly with O_TRUNC and streamed the
request body straight into it. The source is a live sandbox HTTP
stream that can break mid-transfer, which is a normal occurrence, not
an edge case, but a mid-copy failure had already truncated whatever
was at that key. A re-upload to the same filename, which happens any
time a script or session step reruns and writes the same output name
again, could destroy a prior good file and replace it with a partial
one while the caller was told the upload failed and nothing happened.

Write to a temp file in the same directory instead and rename it over
the destination only once the copy and close both succeed. Any
failure along the way removes the temp file and leaves the existing
key untouched.
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