Skip to content

feat(streamingwrites): abort parallel uploads on unlink, destroy and upload failure - #5232

Open
PranjalC100 wants to merge 8 commits into
masterfrom
parallel-upload/uwh-abort
Open

PranjalC100 wants to merge 8 commits into
masterfrom
parallel-upload/uwh-abort

Conversation

@PranjalC100

@PranjalC100 PranjalC100 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Description

Second and last part of the unbuffered write handler, after #5215. It implements Unlink and Destroy, and aborts the upload on failure (design: go/gcsfuse-grpc-parallel-upload-v1-integration, "Unlink & Abort Cleanup" and "Observability & Debuggability").

  • gcs.Writer gets Abort(), and gcs.Bucket gets AbortUpload(ctx, writer), which discards the parts uploaded so far. throttledBucket doesn't throttle it, the other wrappers and the mocks pass it through, and the fake marks the writer aborted so later writes and finalizes fail.
  • Unlink marks the handler unlinked and aborts the upload. After that, writes and truncates only update the size that fstat reports, and Sync/Flush do nothing, without an error and without touching the writer, so the deleted object isn't created.
  • handleUploadFailure records the sticky error, then aborts the upload. Destroy aborts an upload that hasn't been finalized.
  • abort runs at most once, before the writer context is canceled.
  • Metrics and tracing:
    • monitoringBucket records AbortUpload in gcs/request_count and gcs/request_latencies as gcs_method="AbortUpload" (added to metrics.yaml, generated code updated).
    • Each abort runs in a new write.streaming.upload.abort span, documented in docs/tracing.md.
    • WriteHandler.Unlink/Destroy, Inode.Unlink, FileHandle.Destroy and FileInode.DeRegisterFileHandle take the FUSE operation's context, so the abort span nests under fs.unlink/fs.file.release_handle.
  • The handler drops blockSize and passes 0 as the chunk size, which parallel uploads don't use. bucketHandle will set their part size from its write config (b/581184469).
  • cloud.google.com/go/storage v1.70.0 doesn't implement Writer.Abort yet (b/540721232 tracks the SDK release with parallel uploads), so for now the error is logged and the writer context is canceled.
  • Nothing creates the handler yet (b/581184469), so there's no behavior change.

Link to the issue in case of a bug fix.

b/581184283

Testing details

  1. Manual - NA
  2. Unit tests - New tests cover the abort on unlink, destroy and upload failure (through AbortUpload, before the writer context is canceled, on the operation's context), a failing abort, unlink and destroy without an active upload, operations after unlink and the size they report, the fake writer after Abort, the context FileInode passes to the handler, and AbortUpload in bucketHandle, the prefix bucket and the stat-cache bucket. make build passes, and go test -race passes for the changed packages.
  3. Integration tests - NA (the handler isn't wired in yet).

Any backward incompatible change? If so, please explain.

No. Only internal interfaces change.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements the Abort method for the GCS Writer interface and integrates it into the unbufferedWriteHandlerImpl to support Destroy and Unlink operations. Specifically, it introduces an Abort method to discard unfinalized uploads, updates the fake and mock writers to support this behavior, and ensures that subsequent operations (such as writes, syncs, flushes, and truncates) are safely ignored or handled after an unlink. Extensive unit tests have been added to verify these abort, unlink, and destroy flows. No review comments were provided, and the implementation is clean and well-tested.

…upload failure

Implement Unlink and Destroy in the unbuffered write handler, and abort
the upload when it fails.

- Add Abort to gcs.Writer, and AbortUpload to gcs.Bucket as the
  counterpart of FinalizeUpload. monitoringBucket records it as
  gcs_method "AbortUpload", throttledBucket doesn't throttle it, and the
  other wrappers pass it through.
- Unlink marks the handler unlinked and aborts the upload. After that,
  writes and truncates are discarded and Sync and Flush do nothing,
  without an error and without touching the writer, so the deleted
  object isn't created.
- An upload failure records the sticky error and then aborts the upload.
- Destroy aborts an upload that hasn't been finalized.
- Abort runs at most once, before the writer context is canceled, in a
  write.streaming.upload.abort span.
- WriteHandler.Unlink and Destroy, Inode.Unlink, FileHandle.Destroy and
  FileInode.DeRegisterFileHandle take the FUSE operation's context, so
  the abort's metrics and span are linked to that operation.

cloud.google.com/go/storage v1.70.0 doesn't implement Writer.Abort yet,
so the abort error is logged and canceling the writer context is the
only cleanup for now.
- Drop blockSize from the unbuffered write handler and pass 0 as the chunk
  size, which parallel uploads don't use (TODO b/581184469).
- Tests: drop a redundant AssertNotCalled, use setup ops and literal offsets
  in the after-unlink test, add errAbortFailure, cover Destroy after an
  upload failure, and finalize after the abort in the prefix-bucket test.
- Comments: drop the repeated ctx sentences and claims that aren't true yet.
@PranjalC100
PranjalC100 changed the base branch from parallel-upload/uwh-core to master November 23, 2026 08:59
@PranjalC100
PranjalC100 force-pushed the parallel-upload/uwh-abort branch from e1b0ce9 to 1c0926b Compare November 23, 2026 08:59
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.14607% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.32%. Comparing base (9f8bc62) to head (e394a74).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
internal/monitor/bucket.go 0.00% 4 Missing ⚠️
internal/storage/debug_bucket.go 0.00% 4 Missing ⚠️
internal/storage/testify_mock_bucket.go 0.00% 2 Missing ⚠️
internal/fs/inode/base_dir.go 0.00% 1 Missing ⚠️
internal/ratelimit/throttled_bucket.go 0.00% 1 Missing ⚠️
internal/storage/dummy_io_bucket.go 0.00% 1 Missing ⚠️
internal/storage/mock_bucket.go 91.66% 1 Missing ⚠️
...ternal/streamingwrites/unbuffered_write_handler.go 97.14% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5232      +/-   ##
==========================================
+ Coverage   85.19%   85.32%   +0.12%     
==========================================
  Files         181      182       +1     
  Lines       19957    20054      +97     
==========================================
+ Hits        17003    17111     +108     
+ Misses       2953     2942      -11     
  Partials        1        1              
Flag Coverage Δ
unittests 85.32% <83.14%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- Replace the one-off abort tests with tables: AbortsUpload,
  AbortErrorIsReturnedOnlyByDestroy and DoesNotAbortWithoutActiveUpload.
- Cover truncates and a pending forward truncate after unlink, the fake
  writer after Abort, the context FileInode passes to the handler, and
  the SDK's unsupported Abort error in bucketHandle.
- Point the Writer.Abort TODO at b/540721232, and add TODOs for aborting
  staged parallel uploads (b/581184469) and the fake writer's context
  (b/584925513).
@PranjalC100
PranjalC100 marked this pull request as ready for review November 24, 2026 09:24
@PranjalC100
PranjalC100 requested a review from a team as a code owner November 24, 2026 09:24
@github-actions github-actions Bot added the remind-reviewers Auto remind reviewers in attention set for review post 24hrs of inactivity on PR. label Nov 24, 2026
- Split AbortErrorIsReturnedOnlyByDestroy into DestroyReturnsAbortError
  and UploadFailureDoesNotReturnAbortError, which checks that a failed
  write or finalize doesn't return the abort error.
- Comments: Flush marks the writer closed, uploadError is returned until
  Unlink, and throttledBucket never delays or blocks the abort.
@github-actions

Copy link
Copy Markdown

Hi @vadlakondaswetha, @vipnydav, your feedback is needed to move this pull request forward. This automated reminder was triggered because there has been no activity for over 24 hours. Please provide your input when you have a moment. Thank you!

Comment thread metrics/metrics.yaml Resolved
Comment thread tracing/span_names.go Resolved
// and Sync and Flush do nothing, without touching the writer, so that the
// deleted object isn't created. They return no error, even after an upload
// failure, so that applications holding the file open can finish cleanly.
unlinked bool

@vipnydav vipnydav Nov 26, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vadlakondaswetha WDYT about keeping unlinked here vs. checking f.IsUnlinked() in file.go?

Today fs.go / file.go already skip FlushFile, SyncFile, and SetMtime when f.IsUnlinked(), so unlinked is only needed here because FileInode still forwards Write and Truncate to streamingWriteHandler after Unlink. (BufferedWriteHandler didn't track unlinked and instead suppressed context.Canceled in uploadBlock.)

Are we fine keeping unlinked in unbufferedWriteHandlerImpl or should we check f.IsUnlinked() in FileInode's streaming-write helpers so neither handler gets called after Unlink?

The only downside I see is that fstat after unlink and writes would return pre unlinked sizes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PranjalC100 If we decide to keep the unlinked here, we should update totalSize / truncatedSize in Write and Truncate when wh.unlinked is true so WriteFileInfo().TotalSize (fstat(fd)) stays accurate, matching bwh.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept unlinked. After Unlink, Write/Truncate now update totalSize/truncatedSize like bwh, so fstat stays accurate. A FileInode check would hide them from both handlers, so fstat would show the pre-unlink size.

Comment thread internal/storage/gcs/bucket.go Resolved
- Flush and abort set the writer to nil, and abort returns early when
  there's no writer, replacing the writerClosed flag.
- Remove the SDK TODO from abort and the "counterpart of FinalizeUpload"
  sentence from gcs.Bucket.AbortUpload.
Comment thread internal/storage/gcs/bucket.go Resolved
Comment thread internal/storage/bucket_handle_test.go Resolved
- Reword the Abort and AbortUpload docs: they cancel the parallel upload,
  release its buffers and abort the upload session on GCS, so uploaded
  parts are discarded. The dummy IO bucket uses the same wording.
- Drop the comment on aborting before the writer context is canceled and
  the UnsupportedBySDK test case, and fix the abort test comment: the
  abort's trace span nests under the operation's span.
After Unlink, Write and Truncate update totalSize and truncatedSize
without touching the writer, so fstat keeps reporting the size the
application wrote, as with the buffered write handler.
@PranjalC100
PranjalC100 requested a review from vipnydav November 30, 2026 06:47
- After Unlink, every truncate sets the size, so the totalSize comment
  is exact. Test a truncate that was pending when the file was unlinked.
- Drop a Sync assertion that can't fail, rename a duplicate writeErr in
  the unlink test, and reword the uploadError comment.

@vipnydav vipnydav left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. We can merge once we align on whether we want to keep the unlinked variable in uwh or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

execute-integration-tests Run only integration tests execute-integration-tests-on-zb To run E2E tests on zonal bucket. remind-reviewers Auto remind reviewers in attention set for review post 24hrs of inactivity on PR.

4 participants