Skip to content

fix: retry QCloud PUT with seekable reader - #24917

Merged
mergify[bot] merged 6 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix-qcloud-put-retry
Jun 11, 2026
Merged

mergify[bot] merged 6 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix-qcloud-put-retry

Conversation

@jiangxinmeng1

@jiangxinmeng1 jiangxinmeng1 commented Jun 10, 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) does this PR fix or relate to?

Fixes #24916

What this PR does / why we need it:

  • retry QCloud COS raw PUT when the input reader is seekable
  • seek back to the original offset before each retry so a failed PUT cannot leave the reader half consumed
  • fall back to single-concurrency multipart upload for large non-seekable readers
  • add a QCloud PUT retry unit test that simulates connection reset by peer after the first body read

Fixes #24916

Tests

  • go test ./pkg/fileservice -run '^TestQCloudSDKWriteRetriesSeekablePut$' -count=1 -v\n- go test ./pkg/fileservice -run 'TestQCloudSDKWriteRetriesSeekablePut|TestCOSParallelMultipart'\n\nNote: go test ./pkg/fileservice currently fails locally in TestMinioSDK/file_service/basic with Access Denied. from localhost:9007, unrelated to this QCloud change.

@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 →

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

I found one high-confidence correctness issue here. The new non-seekable large-write fallback routes known-size streams into WriteMultipartParallel, but that path no longer preserves the original sizeHint contract when the reader ends early: an empty reader can now succeed with no upload, and a short reader can be rewritten to the shorter actual size and uploaded successfully. Before this PR, the putObject path passed ContentLength=sizeHint and could surface truncated bodies as a size-mismatch error. This means a truncated known-size stream can now turn into a silent short write, which is a real blocker. Also, the added retry test uses bytes.NewReader, which is already seekable and already retried by the COS SDK itself, so it does not prove the new wrapper logic.

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

I re-checked the latest update. The earlier sizeHint/truncation issue is fixed now, but I still see one substantive problem in the current version. The new seekable PUT retry path in pkg/fileservice/qcloud_sdk.go wraps putObject in MatrixOne's outer DoWithRetry, but the COS SDK still has its own built-in retry for seekable Put requests enabled by default. In production that means one transient failure is retried twice: once by the COS SDK itself, and then again by MatrixOne's outer loop. That multiplies request count and can stretch failure latency significantly. The strongest evidence is in the new test itself: it explicitly sets client.Conf.RetryOpt.Count = 0 before exercising the new logic, which avoids the production configuration. In the actual constructor path, NewQCloudSDK does not disable the SDK retry, and the COS SDK default is still RetryOpt.Count = 3. I think this should be resolved before approval: either disable the COS SDK retry for this PUT path when using the outer retry wrapper, or remove the outer retry and rely on the SDK's existing seekable-body retry behavior.

The COS SDK enables retry by default (RetryOpt.Count = 3). MatrixOne wraps
all operations in its own DoWithRetry, so one transient failure was retried
twice — first by the SDK and then by MatrixOne's outer loop — multiplying
request count and stretching failure latency.

Set client.Conf.RetryOpt.Count = 0 in NewQCloudSDK so only MatrixOne's
DoWithRetry handles retries.

Co-Authored-By: Claude Fable 5 <[email protected]>

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

I re-checked the latest update. The previous retry-layering issue is fixed now: the PR correctly disables COS SDK built-in retry so the new seekable PUT retry path no longer stacks two retry systems. However, that global change introduces a new issue: client.Conf.RetryOpt.Count = 0 disables COS retries for the entire client, including paths that are not wrapped in MatrixOne's DoWithRetry. In particular: client.Bucket.Head during initialization and AbortMultipartUpload during multipart cleanup. Both are still direct SDK calls, so with this patch they become single-shot network operations. A transient COS failure can now fail service startup or cause multipart abort cleanup to be dropped, even though those paths previously had the SDK's default retries. I think the fix should be scoped more narrowly: disable SDK retries only for the raw PUT path that now has an outer retry wrapper, or add explicit DoWithRetry around the other unwrapped COS operations.

client.Conf.RetryOpt.Count = 0 disables COS SDK built-in retries globally,
but two direct SDK calls were not wrapped in MatrixOne's DoWithRetry:
- client.Bucket.Head during NewQCloudSDK initialization
- AbortMultipartUpload during WriteMultipartParallel error cleanup
Both are now wrapped so transient COS failures won't fail startup or drop cleanup.

Co-Authored-By: Claude Fable 5 <[email protected]>

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

Reviewed the fileservice changes with a focus on retry semantics, size-mismatch handling, and multipart cleanup on unhappy paths. I do not see a blocking correctness issue in the seekable PUT retry flow, the non-seekable multipart fallback, or the abort-on-error handling, so this looks good to merge.

@mergify

mergify Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-06-11 02:34 UTC · Rule: main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-06-11 03:38 UTC · at 23d84eb0ba58215f10bf0490ffc8a1843d39e45d · squash

This pull request spent 1 hour 4 minutes 15 seconds in the queue, including 1 hour 3 minutes 55 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage

@jiangxinmeng1 jiangxinmeng1 mentioned this pull request Jun 11, 2026
1 of 7 tasks

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

Follow-up after a deeper unhappy-path pass: I found two blocking issues.

  1. pkg/fileservice/qcloud_sdk.go:112 disables the COS SDK retry loop, but IsRetryableError still does not treat COS HTTP 5xx responses as retryable. That drops existing retry coverage for body-less operations like Bucket.Head, Object.Head, list/delete, and multipart init, so transient 503/500 responses now fail immediately.

  2. pkg/fileservice/io.go:64-69 lets exactSizeReader return (0, nil) when Expected == 0 and the wrapped reader returns (0, nil). Callers that use io.ReadFull/ReadAtLeast can spin instead of getting EOF. This should normalize to io.EOF once the expected byte count is exhausted.

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.

[Bug]: COS fileservice PUT connection reset during Load

3 participants