Skip to content

Add TaskTracker::addFinal and async S3 multipart upload - #105487

Merged
asya-ch merged 11 commits into
masterfrom
asya/task_tracker
Jun 1, 2026
Merged

asya-ch merged 11 commits into
masterfrom
asya/task_tracker

Conversation

@asya-ch

@asya-ch asya-ch commented May 21, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Complete the final S3 multipart upload request asynchronously via the task tracker, so it can overlap with the last part upload instead of running serially in finalize.

Version info

  • Merged into: 26.6.1.307

@clickhouse-gh

clickhouse-gh Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [238105b]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_debug, targeted, old_compatibility) FAIL
Logical error: Column A B query tree node does not have valid source node after running C pass (STID: 0250-20a8) FAIL cidb IGNORED
Stress test (arm_tsan) FAIL
Assertion 'px != 0' failed (STID: 3678-2ebd) FAIL cidb IGNORED

AI Review

Summary

This PR adds TaskTracker::addFinal and uses it to run S3 multipart completion as a terminal task, with focused TaskTracker unit coverage. The previous ordering and deadlock issues in TaskTracker look addressed in the current code, but S3 finalization still has a correctness hole: a missing part ETag can make finalizeImpl report success without completing the multipart upload.

PR Metadata
  • 💡 The Changelog category is reasonable, but the entry says the final request can overlap with the last part upload. The code starts completeMultipartUpload only after all regular upload tasks have finished, so a more accurate entry would be:
    Complete the final S3 multipart upload request asynchronously via the task tracker, so it can start as soon as the last part upload finishes instead of after finalizeImpl has collected all upload futures.
Findings

❌ Blockers

  • [src/IO/WriteBufferFromS3.cpp:629] [dismissed by author -- https://github.com/Add TaskTracker::addFinal and async S3 multipart upload #105487#discussion_r3320335387] completeMultipartUpload still returns false when a part has no recorded ETag, which turns the final task into a successful future. If UploadPart returns success but a backend omits the ETag, all part futures are successful, waitAll gets the final future successfully, and finalizeImpl returns while multipart_upload_finished remains false; the destructor then aborts an upload the caller already observed as finalized. Keep the missing-ETag path exceptional; the final future is appended after the part futures, so a real part-upload exception is still surfaced first when one exists.
Tests
  • ⚠️ Add a focused S3 writer regression where UploadPart succeeds without setting an ETag and finalize throws instead of reporting success. That would pin the terminal-upload invariant at the user-visible boundary.
Final Verdict

Status: ❌ Block

Minimum required action: make the missing-ETag path throw again, add the regression test above, and adjust the changelog wording to match the actual scheduling point.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label May 21, 2026
Comment thread src/Common/ThreadPoolTaskTracker.cpp Resolved
Comment thread src/Common/ThreadPoolTaskTracker.cpp Resolved
@CheSema CheSema self-assigned this May 21, 2026
@@ -39,6 +39,11 @@ class TaskTracker

void add(Callback && func);

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.

lets harden the add method: if the final task is set, then no new ordinary task could be added. It is logical error.

else
{
writeMultipartUpload();
task_tracker->addFinal([this]()

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.

cool, all the changes and difficulties are in the common tool.

Comment thread src/IO/WriteBufferFromS3.cpp Outdated
if (tag.empty())
throw Exception(
ErrorCodes::LOGICAL_ERROR,
ErrorCodes::S3_ERROR,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No longer a logical error -- we now reach completeMultipartUpload even if an earlier upload fails. Need to throw in this case.

Per the logic in TaskTracker, the earlier upload failure will be surfaced first.

@CheSema CheSema May 21, 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.

You are right here.
lets do not throw ErrorCodes::S3_ERROR, this is not the error from s3 client and not the error at all
we could throw some generic like canceled + due to previous errors or even just ignore it and do not set the flag that MPU is finished. But later we need to make sure that is MPU is not finished that we have some error from previous steps.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

MPU will not be marked as finished if we throw from this function. And sure, will change to a more generic code.

@asya-ch
asya-ch force-pushed the asya/task_tracker branch from fe53a42 to 05b68ff Compare May 21, 2026 22:03
Comment thread src/Common/ThreadPoolTaskTracker.cpp Resolved
Comment thread src/Common/ThreadPoolTaskTracker.cpp Resolved
Comment thread src/Common/ThreadPoolTaskTracker.cpp Resolved
Comment thread src/IO/WriteBufferFromS3.cpp Resolved
@asya-ch
asya-ch enabled auto-merge May 28, 2026 22:25
@asya-ch
asya-ch disabled auto-merge May 28, 2026 22:25
@clickhouse-gh

clickhouse-gh Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.40% +0.00%
Functions 91.30% 91.40% +0.10%
Branches 76.90% 77.00% +0.10%

Changed lines: Changed C/C++ lines covered by tests: 155/156 (99.36%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@asya-ch
asya-ch added this pull request to the merge queue Jun 1, 2026
Merged via the queue into master with commit 044a9bb Jun 1, 2026
163 of 166 checks passed
@asya-ch
asya-ch deleted the asya/task_tracker branch June 1, 2026 19:21
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 1, 2026
pull Bot pushed a commit to sonvt1710/ClickHouse that referenced this pull request Jun 9, 2026
Add TaskTracker::addFinal and async S3 multipart upload
@alexey-milovidov

Copy link
Copy Markdown
Member

@asya-ch, this has a bug, see: #108730

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

Labels

pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants