Skip to content

Remove ACCESS_DENIED and INVALID_ACCESS_KEY_ID from unretryable S3 errors - #109021

Open
JingYanchao wants to merge 3 commits into
ClickHouse:masterfrom
JingYanchao:johnjing/remove-unretry-s3-error
Open

JingYanchao wants to merge 3 commits into
ClickHouse:masterfrom
JingYanchao:johnjing/remove-unretry-s3-error

Conversation

@JingYanchao

@JingYanchao JingYanchao commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Relative issue

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix data parts on S3-backed disks being marked as broken after a transient S3 authentication error, such as an expired or rotated credential.

Motivation

S3 access keys are configured via configuration files and support hot-reload, and may also use temporary credentials. Currently, if the access key is
misconfigured or not updated in time, all queried parts that depend on S3 become broken immediately without retry, resulting in significant recovery costs.

@JingYanchao

Copy link
Copy Markdown
Contributor Author

@nickitat Could you please help with a review? Thanks!

@nickitat

nickitat commented Aug 3, 2026

Copy link
Copy Markdown
Member

@arsenmuk, can you take a look at this one pls.

@evillique evillique added the can be tested Allows running workflows for external contributors label Aug 6, 2026
@clickhouse-gh clickhouse-gh Bot closed this Aug 6, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [795450b]

Summary: ❌

job_name test_name status info comment
Stress test (amd_asan_ubsan) FAIL
Sanitizer (STID: 2064-22d0) FAIL cidb
Stress test (arm_asan_ubsan, s3) FAIL
Hung check failed, possible deadlock found FAIL cidb
Stress test (arm_tsan) FAIL
Hung check failed, possible deadlock found FAIL cidb

AI Review

Summary

This PR stops S3 credential/authentication errors from being treated as permanent part corruption by making isRetryableException accept S3Exception::isAccessTokenExpiredError. That avoids the original broken-part path, but the current wiring also changes startup and checksum-verification flows in ways that can either abort table loading after the retry budget is exhausted or report a skipped verification as success. I do not think the current change is safe to merge as-is.

Findings

❌ Blockers

  • [src/Storages/MergeTree/checkDataPart.cpp:79] ACCESS_DENIED / INVALID_* now enter the generic retryable path that MergeTreeData::loadDataPart rethrows instead of marking broken (src/Storages/MergeTree/MergeTreeData.cpp:2550-2574). loadDataPartWithRetries only retries three times and then rethrows (src/Storages/MergeTree/MergeTreeData.cpp:2628-2660), so a delayed credential rotation during startup or ATTACH can now abort table loading instead of keeping the table available and detaching the affected parts. Narrow the new classification to the broken-part/reporting sites, or add a separate "not broken, recheck later" path for loaders instead of falling into the generic retry budget.

⚠️ Majors

  • [src/Storages/MergeTree/checkDataPart.cpp:79] checkDataPart turns any retryable exception into empty checksums (src/Storages/MergeTree/checkDataPart.cpp:542-551 and 575-584). After this change, S3 auth failures can therefore make StorageMergeTree::checkDataNext return success (src/Storages/StorageMergeTree.cpp:3458-3462) and ReplicatedMergeTreePartCheckThread::checkPartImpl log Part {} looks good. (src/Storages/MergeTree/ReplicatedMergeTreePartCheckThread.cpp:401-416) even though verification never finished. Treat empty() as "indeterminate" in these callers, or keep throwing for this class of error.
Tests
  • ⚠️ Add a focused regression test for an S3-backed part where ACCESS_DENIED or INVALID_SIGNATURE happens during startup or CHECK TABLE, showing that the part is neither detached as broken nor reported as successfully verified without an actual re-read.
Final Verdict

Request changes.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 91.90% 91.80% -0.10%
Branches 79.00% 79.00% +0.00%

Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Aug 6, 2026
@JingYanchao
JingYanchao force-pushed the johnjing/remove-unretry-s3-error branch from a18daf1 to 0adc3d4 Compare August 7, 2026 03:40
Comment thread src/IO/S3Common.cpp Resolved
Comment thread src/IO/S3Common.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

No arm_release build profile data for commit 795450b - the build was skipped, reused from cache, or predates profile upload.

@JingYanchao
JingYanchao force-pushed the johnjing/remove-unretry-s3-error branch from 0adc3d4 to c2e265b Compare August 10, 2026 03:48
catch (const S3Exception & s3_exception)
{
return s3_exception.isRetryableError();
return s3_exception.isRetryableError() || s3_exception.isAccessTokenExpiredError();

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 helper is used by startup and ATTACH load paths too, not only by the "do not mark this part broken" sites. In MergeTreeData::loadDataPart, both the part builder and loadColumnsChecksumsIndexes rethrow any exception for which isRetryableException returns true (src/Storages/MergeTree/MergeTreeData.cpp:2550-2574). loadDataPartWithRetries then retries only 3 times and rethrows on the last attempt (src/Storages/MergeTree/MergeTreeData.cpp:2628-2660).

So an ACCESS_DENIED / INVALID_ACCESS_KEY_ID / INVALID_SIGNATURE blip during startup no longer becomes "mark the part broken and keep loading"; after a few hundred milliseconds it aborts ATTACH or table load entirely. That seems worse than the bug this PR is trying to fix, because a delayed credential rotation can now keep the table from loading at all.

I think the relaxed classification needs to stay out of the generic isRetryableException path, or the startup loaders need a separate "not broken, recheck later" handling instead of the current throw-after-3-tries behavior.

catch (const S3Exception & s3_exception)
{
return s3_exception.isRetryableError();
return s3_exception.isRetryableError() || s3_exception.isAccessTokenExpiredError();

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.

Making these auth errors retryable also changes checkDataPart semantics: the wrapper swallows any retryable exception and returns empty checksums (src/Storages/MergeTree/checkDataPart.cpp:542-551 and 575-584). Some callers already treat empty() as "could not verify" (src/Storages/MergeTree/DataPartsExchange.cpp:969-978), but the verification paths here do not:

  • StorageMergeTree::checkDataNext returns CheckResult(..., true, "") after checkDataPart(...) when checksums.txt already exists (src/Storages/StorageMergeTree.cpp:3458-3462).
  • ReplicatedMergeTreePartCheckThread::checkPartImpl ignores the return value and logs Part {} looks good. (src/Storages/MergeTree/ReplicatedMergeTreePartCheckThread.cpp:401-416).

After this change, an S3 auth failure during verification can therefore be reported as a successful CHECK TABLE or replica part check even though the checksum read was skipped entirely. These callers need an explicit empty() guard, or checkDataPart needs to keep throwing for this class of error.

@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 4, 2026
@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026
@clickhouse-gh clickhouse-gh Bot added comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 19, 2026

This branch has not been deployed

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

Labels

can be tested Allows running workflows for external contributors comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... external Author is not a member of the ClickHouse organization pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants