Skip to content

fix(fileservice): abort canceled parallel multipart uploads - #29312

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
ck89119:issue-29267-main
Sep 24, 2026
Merged

mergify[bot] merged 5 commits into
matrixorigin:mainfrom
ck89119:issue-29267-main

Conversation

@ck89119

@ck89119 ck89119 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #29267

What this PR does / why we need it:

Record cancellation observed by multipart part workers in both S3 and COS implementations. Reject an incomplete upload even when no parts finished, so the existing abort path cleans up the owned upload instead of reporting success without creating an object.

Add an AWS regression test that cancels after multipart initialization; retain the existing COS cancellation test.

Validation (Go 1.26.4): focused cancellation tests, full pkg/fileservice tests, focused and full package race tests, and go vet passed. Multipart functions have 89.2% (AWS) and 88.7% (COS) statement coverage. Incremental golangci-lint v2.6.2 built with Go 1.26.4 passed for pkg/fileservice (0 issues). This does not claim a full-repository lint pass.

@fengttt fengttt 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.

This looks correct to me; only minor nits below.

I checked the full WriteMultipartParallel functions, not just the diff:

  • Abort after cancellation works. The deferred AbortMultipartUpload runs whenever err != nil and uses context.WithoutCancel(parentCtx), so it still goes out after the context is canceled. The canceled upload is cleaned up rather than leaked.
  • Removing if len(parts) == 0 { return nil } is safe. Empty input (firstPart == nil) and input below minMultipartPartSize take the single-Write path before a multipart upload is created. On the multipart path sendJob(firstPart) always counts at least one part. So "no part finished" now always hits the existing multipart upload incomplete error and the abort, instead of returning success with no object. That was the real hazard: a caller would believe the object was written.
  • Coverage is complete. AWS and COS are the only real implementations. objectStorageHTTPTrace, objectStorageMetrics and objectStorageSemaphore delegate to them.
  • The read loop was already right. A readChunk error, including cancellation while acquiring buffer budget, goes through setErr. The silent path was only in the part workers, which is what this fixes.
  • The tests hit the right boundary. They cancel after a worker holds its slots and assert aborted, not completed, with no parts. The AWS init-cancellation case is a good addition.

Returning the raw ctx.Err() is also the right shape: callers above (e.g. the parallel-scope scheduler) recognise a canceled sibling with errors.Is(err, context.Canceled).

Possible follow-up, not for this PR: workers wait for the upload semaphore / slots without watching ctx, and check it only after acquiring them. That's correct and doesn't leak, but with many queued parts a canceled upload drains the queue slot by slot before returning.

Comment thread pkg/fileservice/object_storage.go Resolved
Comment thread pkg/fileservice/parallel_sdk_test.go Resolved
@ck89119
ck89119 marked this pull request as ready for review September 24, 2026 06:48
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@XuPeng-SH XuPeng-SH 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.

GPT-6 high review — APPROVE.

Reviewed the current diff and affected cancellation/abort paths. The cancellation propagation fix and abort behavior are covered; no blocking findings.

@mergify mergify Bot added the queued label Sep 24, 2026
@mergify

mergify Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-24 09:15 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-24 09:16 UTC · at b72087c2d64c45fd10e8e9a00030a200b452de24 · squash

This pull request spent 54 seconds in the queue, including 4 seconds running CI.

Required conditions to merge

@mergify
mergify Bot merged commit b72087c into matrixorigin:main Sep 24, 2026
27 of 28 checks passed
@mergify mergify Bot removed the queued label Sep 24, 2026
@ck89119
ck89119 deleted the issue-29267-main branch September 24, 2026 10:05
XuPeng-SH added a commit that referenced this pull request Oct 21, 2026
## What type of PR is this?

- [x] BUG
- [x] Improvement

## Which issue(s) this PR fixes:

Fixes #30737

## What this PR does / why we need it:

Cancelling asynchronous CSV/JSON conversion can leave a missing batch
result and make export finalization spin indefinitely. Finalization now
waits on ordered results or cancellation, releases completed entries,
and rejects incomplete closed streams.

ExportConfig owns cancellation and joining of conversion workers, file
pipes, the sink, and the per-file cancellation callback. Cleanup
preserves the primary error's concrete identity and keeps request
metadata alive until all users exit. Ordinary OUTFILE, DATA BRANCH CSV,
and stored-result dumping use this cleanup boundary. DATA BRANCH
coordination runs outside the converter pool and observes producer
cancellation once while draining results.

Stored-result dumping creates its own cancellation context and passes it
to the sink. A known header/source error therefore cancels a
context-cooperative sink before joining, even if it is waiting on
existence checks or admission rather than consuming the pipe. Dump
remains synchronous and allocates no unused conversion queue. The parent
request, borrowed shared service, process, and saved metadata retain
their ownership.

Rebased onto the target branch and aligned all `ExportConfig` method
receiver names, resolving CI staticcheck ST1016 without changing cleanup
behavior or suppressing diagnostics.

The 4.2-dev PR also backports #29344 for #29266: unknown-size empty S3
writes publish zero-byte objects, and failed multipart writes reach
bounded Abort cleanup. Sequential/parallel Abort retains context values,
survives caller cancellation, and has a 30-second deadline. Successful
Abort preserves primary error identity. SDK dependencies, nonempty chunk
sizing and successful request sequence remain unchanged.

## Validation

- Final frontend owning-package normal and full `-race -count=1` suites:
**1599 root tests passed in each**, with one existing skip.
- Rebase preserved all three functional commits. Backend source and
dependencies are unchanged; prior backend evidence remains applicable.
- New actual `doDumpQueryResult` regression covers oversized headers, a
source-file read failure after sink startup, parent cancellation,
primary error identity, joined sink, and continued
shared-service/metadata usability. Retained evidence from the identical
regression source records **100 race repetitions per branch**; all three
scenarios also passed in the post-rebase full race suites. A pre-repair
production-function overlay makes the source-error cell fail as expected
until independent parent cancellation; the probe cancels and drains
itself.
- Existing public SQL lifecycle test passed under race: exact CSV
contents, destination failure and same-session reuse. Existing
multi-block stored-result dump content test passed.
- Scoped `go vet`, configured `molint`, formatting, license-eye and
incremental configured `golangci-lint` passed. Full affected-package
lint reports 41 diagnostics: a separate clean `b7d2cc7b56` worktree
produces the identical complete diagnostic set after normalizing line
offsets. No new findings, no ST1016, no suppression. License-eye checked
all changed files (7 main / 11 release), 0 invalid; policy unchanged.
- Separate `gpt-6.1-sol` / `xhigh` design and final complete-PR review
passed with no unresolved material blocker. Local results are distinct
from remote CI.
- Retained backend evidence remains applicable: fileservice
owning-package suite (299 roots), affected AWS/S3 race tests (51 roots),
controlled HTTP Abort deadlines/errors, real SQL empty-object
publication, and combined SQL cancellation/prepared reuse. The later
unmodified-binary blackbox comparison reproduced the 4.2 baseline hang,
while this PR's export lifecycle passed 32/32 timed cancellations with
same-session health and correct normal CSV contents. No backend source
or dependencies changed in this follow-up.

Local validation artifacts:
`/home/xupeng/.codex/issue-to-pr/matrixone/30737/rebase-review/`
(`scope.json`, `results.json`, `run-validation.sh`, `*-normal.jsonl`,
`*-race.jsonl`, `*-public.jsonl`, `*-vet.log`, `*-molint.log`,
`*-lint.log`, `*-license.log`, exit receipts). The release baseline
comparison is `42-lint-comparison.json`; retained stress/negative
controls are in the adjacent `review-ci-repair/` directory.

## Performance and limits

Retains asynchronous conversion. Blocking finalizer waits replace busy
spinning. Stored-result dumping adds one child context; it adds no
conversion queue, worker or success-path backend request. No broad
throughput or long-soak guarantee is claimed.

Global admission bounds and arbitrary I/O that ignores cancellation
remain outside this fix. The separately tracked borrowed-service SQL
DATA BRANCH DIFF issue #30755 is unchanged.
Failed S3 writes can wait for the bounded Abort operation; the 30-second
cleanup budget does not bound the entire SQL request or arbitrary source
readers. Remote reclamation requires a successful Abort. The pre-upload
parallel cancellation schedule addressed by main #29312 remains a
separate known gap.

Remote CI is pending for the updated revision.

This branch was previously deployed

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

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants