Skip to content

Slow down all backup threads after S3 retryable errors, including ‘SlowDown’#84854

Merged
jkartseva merged 13 commits intoClickHouse:masterfrom
jkartseva:global-backoff-s3-retries
Aug 5, 2025
Merged

Slow down all backup threads after S3 retryable errors, including ‘SlowDown’#84854
jkartseva merged 13 commits intoClickHouse:masterfrom
jkartseva:global-backoff-s3-retries

Conversation

@jkartseva
Copy link
Copy Markdown
Member

@jkartseva jkartseva commented Aug 1, 2025

  • Introduce a new backup_slow_all_threads_after_retryable_s3_error setting.
  • Disables the AWS SDK’s per-thread retry mechanism if backup_slow_all_threads_after_retryable_s3_error is set. This allows for coordinated global backoff, causing all threads to sleep after a retryable S3 error occurs.
  • Follow-up to Slow down S3 client after network error #80035, with fixes.
  • Some parts of this PR (delay after the 1st retry, the test) are derived from Improve S3 Retry Strategy for backup and restore #84421, which is expected to be merged after this PR

Changelog category (leave one):

  • Improvement

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

Introduce a new backup_slow_all_threads_after_retryable_s3_error setting to reduce pressure on S3 during retry storms caused by errors such as SlowDown, by slowing down all threads once a single retryable error is observed.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@jkartseva jkartseva added the can be tested Allows running workflows for external contributors label Aug 1, 2025
@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Aug 1, 2025

Workflow [PR], commit [45275b7]

Summary:

@clickhouse-gh clickhouse-gh bot added the pr-improvement Pull request with some product improvements label Aug 1, 2025
Comment on lines +688 to +700
auto outcome = request_fn_(request_);

if (!outcome.IsSuccess()
/// AWS SDK's built-in per-thread retry logic is disabled.
&& client_configuration.s3_slow_all_threads_after_retryable_error
&& attempt_no + 1 < max_attempts
/// Retry attempts are managed by the outer loop, so the attemptedRetries argument can be ignored.
&& client_configuration.retryStrategy->ShouldRetry(outcome.GetError(), /*attemptedRetries*/ -1))
{
updateNextTimeToRetryAfterRetryableError(outcome.GetError(), attempt_no);
continue;
}
return outcome;
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.

This is the essential part.

Comment on lines -757 to -758
LOG_WARNING(log, "Request failed, now waiting {} ms before attempting again", sleep_ms);
sleepForMilliseconds(sleep_ms);
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.

I think this is incorrect because it changes the behavior of the old versions with s3_slow_all_threads_after_network_error disabled.

{"delta_lake_enable_expression_visitor_logging", false, false, "New setting"},
{"write_full_path_in_iceberg_metadata", false, false, "New setting."},
{"output_format_orc_compression_block_size", 65536, 262144, "New setting"},
{"backup_slow_all_threads_after_retryable_s3_error", false, true, "New setting"},
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.

I think it would be better to say is was always so. So, true, true IMO

@jkartseva jkartseva enabled auto-merge August 5, 2025 04:45
@@ -463,9 +463,9 @@ When set to `true` than for all azure requests first two attempts are made with
When set to `false` than all attempts are made with identical timeouts.
)", 0) \
DECLARE(Bool, s3_slow_all_threads_after_network_error, true, R"(
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.

Do we really need two separate settings? Couldn't you just modify the logic of s3_slow_all_threads_after_network_error instead of adding a new setting?

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.

I enabled the new setting only for backups. In other places, wherever the S3 client is configured, the value of this setting is false, unlike s3_slow_all_threads_after_network_error, which is true.
For example:
src/Coordination/KeeperSnapshotManagerS3.cpp

static constexpr bool s3_slow_all_threads_after_network_error = true;
static constexpr bool s3_slow_all_threads_after_retryable_error = false;

The reason for this is that I prefer to avoid any unexpected delays outside of the backup ecosystem, and the setting s3_slow_all_threads_after_network_error is too broad for the use case.

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.

The setting s3_slow_all_threads_after_network_error was added only to resolve the backup issue, despite the fact it doesn't have the backup word in its name. Since you've found a better solution let's remove the previous setting or at least make it obsolete and make these settings work in exactly the same way. Just to avoid creating unnecessary complexity.

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.

The setting s3_slow_all_threads_after_network_error was added only to resolve the backup issue, despite the fact it doesn't have the backup word in its name.

It applies not solely to backups:

/home/ubuntu/src/jkartseva/ClickHouse//src/Coordination/KeeperSnapshotManagerS3.cpp:        static constexpr bool s3_slow_all_threads_after_network_error = true;
/home/ubuntu/src/jkartseva/ClickHouse//src/Coordination/KeeperSnapshotManagerS3.cpp:            s3_slow_all_threads_after_network_error,
/home/ubuntu/src/jkartseva/ClickHouse//src/Databases/DataLake/GlueCatalog.cpp:    extern const SettingsBool s3_slow_all_threads_after_network_error;
/home/ubuntu/src/jkartseva/ClickHouse//src/Databases/DataLake/GlueCatalog.cpp:    bool s3_slow_all_threads_after_network_error = global_settings[DB::Setting::s3_slow_all_threads_after_network_error];
/home/ubuntu/src/jkartseva/ClickHouse//src/Databases/DataLake/GlueCatalog.cpp:        s3_slow_all_threads_after_network_error,
/home/ubuntu/src/jkartseva/ClickHouse//src/Disks/ObjectStorages/S3/diskSettings.cpp:    extern const SettingsBool s3_slow_all_threads_after_network_error;
/home/ubuntu/src/jkartseva/ClickHouse//src/Disks/ObjectStorages/S3/diskSettings.cpp:    bool s3_slow_all_threads_after_network_error = static_cast<int>(global_settings[Setting::s3_slow_all_threads_after_network_error]);
/home/ubuntu/src/jkartseva/ClickHouse//src/Disks/ObjectStorages/S3/diskSettings.cpp:    if (!for_disk_s3 && local_settings.isChanged("s3_slow_all_threads_after_network_error"))
/home/ubuntu/src/jkartseva/ClickHouse//src/Disks/ObjectStorages/S3/diskSettings.cpp:        s3_slow_all_threads_after_network_error = static_cast<int>(local_settings[Setting::s3_slow_all_threads_after_network_error]);
/home/ubuntu/src/jkartseva/ClickHouse//src/Disks/ObjectStorages/S3/diskSettings.cpp:        s3_slow_all_threads_after_network_error,

This is why I introduced a new backup-specific setting.

I am fine with deprecating s3_slow_all_threads_after_network_error in favor of the new setting, but IMO its value for non-backup cases should be set to false.

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.

It applies not solely to backups

Yes, but I didn't have any intention to do anything specially for KeeperSnapshotManagerS3 or S3 object storage. My idea in #80035 was to provide a general fix for S3 client. Since you've modified that fix so it works only for backups now, then it seems better not to apply the previous insufficient fix #80035 to KeeperSnapshotManagerS3 or S3 object storage.



def check_backup_and_restore(
cluster,
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.

Why? It was handy not to always pass argument cluster around.

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.

I encountered errors when attempting to use the broken_s3 fixture with cluster defined as a global variable.
No idea why — I’ll share what it was.

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.

Okay, this run successfully: https://pastila.nl/?0007ca17/cd50b03b85732812330d9e5f7d259acc#sV+W48OJYF+VvST8Na3hSA==
So the argument change can be reverted

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.

@jkartseva jkartseva added this pull request to the merge queue Aug 5, 2025
Merged via the queue into ClickHouse:master with commit 957e0df Aug 5, 2025
242 of 244 checks passed
@jkartseva jkartseva deleted the global-backoff-s3-retries branch August 5, 2025 17:35
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 5, 2025
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 5, 2025
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 6, 2025
@vitlibar
Copy link
Copy Markdown
Member

vitlibar commented Aug 6, 2025

Test test_backup_restore_s3/test.py::test_backup_restore_with_s3_throttle seems flaky

@robot-clickhouse robot-clickhouse removed the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 6, 2025
jkartseva added a commit that referenced this pull request Aug 6, 2025
Cherry pick #84854 to 25.6: Slow down all backup threads after S3 retryable errors, including ‘SlowDown’
robot-clickhouse added a commit that referenced this pull request Aug 6, 2025
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 6, 2025
@jkartseva jkartseva mentioned this pull request Aug 6, 2025
1 task
clickhouse-gh bot added a commit that referenced this pull request Aug 7, 2025
Backport #84854 to 25.6: Slow down all backup threads after S3 retryable errors, including ‘SlowDown’
baibaichen pushed a commit to Kyligence/ClickHouse that referenced this pull request Aug 7, 2025
Fix rebase issue:
- 20250806 ClickHouse#84854
- 20250729 ClickHouse#84011
- 20250318 ClickHouse#77257

(cherry picked from commit e7061da)
baibaichen pushed a commit to Kyligence/gluten that referenced this pull request Aug 7, 2025
github-merge-queue bot pushed a commit that referenced this pull request Aug 8, 2025
baibaichen pushed a commit to Kyligence/ClickHouse that referenced this pull request Aug 8, 2025
Fix rebase issue:
- 20250806 ClickHouse#84854
- 20250729 ClickHouse#84011
- 20250318 ClickHouse#77257

(cherry picked from commit e7061da)
baibaichen pushed a commit to Kyligence/gluten that referenced this pull request Aug 8, 2025
baibaichen pushed a commit to Kyligence/ClickHouse that referenced this pull request Aug 11, 2025
Fix rebase issue:
- 20250806 ClickHouse#84854
- 20250729 ClickHouse#84011
- 20250318 ClickHouse#77257

(cherry picked from commit e7061da)
baibaichen pushed a commit to Kyligence/gluten that referenced this pull request Aug 11, 2025
baibaichen pushed a commit to Kyligence/ClickHouse that referenced this pull request Aug 12, 2025
Fix rebase issue:
- 20250806 ClickHouse#84854
- 20250729 ClickHouse#84011
- 20250318 ClickHouse#77257

(cherry picked from commit e7061da)
baibaichen pushed a commit to Kyligence/gluten that referenced this pull request Aug 12, 2025
baibaichen pushed a commit to Kyligence/ClickHouse that referenced this pull request Aug 13, 2025
Fix rebase issue:
- 20250806 ClickHouse#84854
- 20250729 ClickHouse#84011
- 20250318 ClickHouse#77257

(cherry picked from commit e7061da)
baibaichen pushed a commit to Kyligence/gluten that referenced this pull request Aug 13, 2025
baibaichen pushed a commit to Kyligence/ClickHouse that referenced this pull request Aug 14, 2025
Fix rebase issue:
- 20250806 ClickHouse#84854
- 20250729 ClickHouse#84011
- 20250318 ClickHouse#77257

(cherry picked from commit e7061da)
baibaichen pushed a commit to Kyligence/gluten that referenced this pull request Aug 14, 2025
baibaichen pushed a commit to Kyligence/ClickHouse that referenced this pull request Aug 15, 2025
Fix rebase issue:
- 20250806 ClickHouse#84854
- 20250729 ClickHouse#84011
- 20250318 ClickHouse#77257

(cherry picked from commit e7061da)
baibaichen pushed a commit to Kyligence/gluten that referenced this pull request Aug 15, 2025
baibaichen pushed a commit to Kyligence/ClickHouse that referenced this pull request Aug 16, 2025
Fix rebase issue:
- 20250806 ClickHouse#84854
- 20250729 ClickHouse#84011
- 20250318 ClickHouse#77257

(cherry picked from commit e7061da)
baibaichen pushed a commit to Kyligence/gluten that referenced this pull request Aug 16, 2025
baibaichen pushed a commit to Kyligence/ClickHouse that referenced this pull request Aug 18, 2025
Fix rebase issue:
- 20250806 ClickHouse#84854
- 20250729 ClickHouse#84011
- 20250318 ClickHouse#77257

(cherry picked from commit e7061da)
baibaichen pushed a commit to Kyligence/gluten that referenced this pull request Aug 18, 2025
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 pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-backports-created-cloud deprecated label, NOOP pr-improvement Pull request with some product improvements pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v25.6-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants