8000 fix(inkless:s3): switch default S3 retry mode to standard and record call-level timeouts [KC-874] by jeqo · Pull Request #915 · aiven/inkless · GitHub
[go: up one dir, main page]

Skip to content

fix(inkless:s3): switch default S3 retry mode to standard and record call-level timeouts [KC-874] - #915

Merged
jeqo merged 3 commits into
mainfrom
jeqo/s3-throttling
Dec 1, 2026
Merged

jeqo merged 3 commits into
mainfrom
jeqo/s3-throttling

Conversation

@jeqo
@jeqo jeqo commented Nov 30, 2026 •
Copy link
Copy Markdown
Contributor

Brokers using the AWS SDK ADAPTIVE_V2 retry mode with a bounded s3.api.call.timeout (default 2000 ms) can lock up an S3 client until restart after throttling, while configured-timeout-errors stays at zero. Once a throttling response sets enabled = true on the SDK's RateLimiterTokenBucket, that flag never resets: either a throttling burst or a quiet period on a bursty client (which caps fillRate at 2 * measuredTxRate) can push token-bucket sleep times past apiCallTimeout, so every call fails with ApiCallTimeoutException before sending an HTTP attempt and never delivers the successful response required for CUBIC recovery. Because ApiCallTimeoutTrackingStage wraps ApiCallAttemptMetricCollectionStage, those pre-attempt timeouts produce no ApiCallAttempt child and only report boolean API_CALL_SUCCESSFUL = false on the root collection, leaving MetricCollector.publish() blind to them. Switching the default retry mode to STANDARD removes the client-side token bucket while keeping identical retry limits, backoff, and circuit-breaker protection, and registering MetricCollector as an ExecutionInterceptor surfaces call-level ApiCallTimeoutException failures in configured-timeout-errors.

Commits

  • fix(inkless:s3): record call-level timeouts in S3 metrics
  • fix(inkless:s3): default S3 retry mode to standard and add s3.retry.mode

See the commit messages for the reasoning behind each step (including why #442 → #562 → #791 exposed the lockout and why current upstream AWS SDK v2 releases still queue timed-out sync waiters in RateLimiterTokenBucket.doNotify()).

Configuration and operator impact

  • New config s3.retry.mode (under inkless.storage.): valid values standard and adaptive_v2 (case-insensitive), default standard. Supports per-role overrides through inkless.storage.<role>.s3.retry.mode (for example, opting background back into adaptive_v2 if needed) and is documented in docs/inkless/configs.rst.
  • SDK behavior diff (ADAPTIVE_V2 → STANDARD): max attempts (3), non-throttle exponential backoff (100 ms base, 20 s max), throttling exponential backoff (1 s base, 20 s max), retryable error predicates, and the retry-quota circuit breaker (500 tokens, cost 5 per retry including throttles, +1 per success) remain identical. Only the pre-attempt client-side CUBIC token bucket is removed; first attempts no longer sleep before HTTP transmission, while concurrency and rate stay bounded by Inkless's thread pools and optional fetch.lagging.consumer.request.rate.limit.
  • Metric impact: configured-timeout-errors-rate and configured-timeout-errors-total (global and per-operation, updated in docs/inkless/metrics.rst) now include call-level ApiCallTimeoutException failures via ExecutionInterceptor.onExecutionFailure() in addition to attempt-level timeouts. When a call timeout fires mid-attempt, AWS SDK's attempt stage also records OTHER for the interrupted attempt; keeping the interceptor stateless accepts that SDK quirk (dashboards do not sum other-errors and configured-timeout-errors) rather than bridging to publish() with a ThreadLocal. Existing latency metrics (*-time-avg / *-time-max, backed by API_CALL_DURATION) are unchanged and already include wait time and timed-out calls.

Test plan

  • S3ThrottlingRecoveryTest (new WireMock integration suite): pins concurrent fetch recovery after 503 SlowDown throttling with the default standard mode (reproduces a permanent timeout stall on adaptive_v2) and verifies under explicit adaptive_v2 that concurrent pre-attempt timeouts increment both global and operation="GetObject" configured-timeout-errors-total by the exact observed delta above post-arming baselines while fewer HTTP requests reach WireMock than timeouts occurred.
  • S3ErrorMetricsTest: adds an integration test verifying call-level ApiCallTimeoutException updates global and per-operation configured-timeout-errors.
  • MetricCollectorTest, S3StorageConfigTest, and 8000 S3ClientBuilderTest: unit tests covering onExecutionFailure filtering (no double counting of ApiCallAttemptTimeoutException), s3.retry.mode validation, and builder wiring for both retry modes and the execution interceptor.

`MetricCollector.publish()` reads `CoreMetric.ERROR_TYPE` only from `ApiCallAttempt` child collections. Because `ApiCallTimeoutTrackingStage` wraps `ApiCallAttemptMetricCollectionStage` in the AWS SDK sync pipeline, an `ApiCallTimeoutException` never appears on an attempt child. When a call times out before an HTTP attempt starts (such as during a backoff or rate-limiter wait) or while an attempt is in flight, `configured-timeout-errors` stays at zero even though requests time out.

Have `MetricCollector` implement `ExecutionInterceptor` and register it on the S3 client in `S3ClientBuilder`. On `onExecutionFailure`, record `CONFIGURED_TIMEOUT` globally and per operation when the failure is an `ApiCallTimeoutException`. Attempt-level `ApiCallAttemptTimeoutException` failures stay handled by `publish()` without double counting.

Assisted-by: Gemini 4 Neon
Copilot AI 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.

🟡 Changes recommended

The test’s timeout assertions can pass using counts from the initial fetch, leaving the concurrent pre-attempt timeout behavior unverified.

1 open issue
What changed in this PR

This PR addresses S3 read stalls after throttling in Inkless by switching the default retry mode to STANDARD and making call-level timeouts visible in existing metrics.

Changes:

  • Add case-insensitive s3.retry.mode configuration with standard as the default and adaptive_v2 as an option.
  • Record call-level timeouts globally and per operation through an execution interceptor.
  • Add unit and integration coverage for retry configuration, timeout metrics, and throttling recovery.
File Description
storage/​inkless/​src/​test/​java/​io/​aiven/​inkless/​storage_backend/​s3/​S3StorageConfigTest.java Test retry-mode defaults and validation.
storage/​inkless/​src/​test/​java/​io/​aiven/​inkless/​storage_backend/​s3/​S3ClientBuilderTest.java Check retry strategy and interceptor wiring.
storage/​inkless/​src/​test/​java/​io/​aiven/​inkless/​storage_backend/​s3/​MetricCollectorTest.java Test call-timeout recording and attempt-timeout filtering.
storage/​inkless/​src/​test/​java/​io/​aiven/​inkless/​storage_backend/​s3/​integration/​S3ThrottlingRecoveryTest.java Add concurrent recovery and pre-attempt timeout scenarios.
storage/​inkless/​src/​test/​java/​io/​aiven/​inkless/​storage_backend/​s3/​integration/​S3ErrorMetricsTest.java Add call-level timeout metric assertions.
storage/​inkless/​src/​main/​java/​io/​aiven/​inkless/​storage_backend/​s3/​S3StorageConfig.java Define and parse the retry-mode setting.
storage/​inkless/​src/​main/​java/​io/​aiven/​inkless/​storage_backend/​s3/​S3ClientBuilder.java Apply the configured retry mode and register the interceptor.
storage/​inkless/​src/​main/​java/​io/​aiven/​inkless/​storage_backend/​s3/​MetricCollector.java Capture call-level timeout failures in error metrics.
docs/​inkless/​configs.rst Document retry-mode options and the default.

Review effort: Balanced

With a bounded `s3.api.call.timeout` (default 2000 ms), the AWS SDK `ADAPTIVE_V2` client-side token bucket can enter a self-sustaining lockout after S3 throttling. Once a throttling response sets `enabled = true` on `RateLimiterTokenBucket`, that flag never resets. If a throttling burst or a quiet period drops `fillRate` below concurrent request demand, callers subtract tokens into negative capacity and sleep in `RetryableStage2` past `apiCallTimeout`. Timed-out calls fail before sending an HTTP attempt, never refund their tokens, and never deliver the successful response required for CUBIC recovery, so the client stays stuck until broker restart. Current upstream AWS SDK v2 releases still queue timed-out sync waiters without skipping cancelled futures in `RateLimiterTokenBucket.doNotify()`.

`ADAPTIVE_V2` was enabled in #442 when `s3.api.call.timeout` defaulted to unbounded (`null`) and hot and cold reads shared one fetch client. Later changes split out a dedicated cold-path client (#562, which sees idle gaps between bursts that drag `fillRate` down via `2 * measuredTxRate`) and set the default `s3.api.call.timeout` to 2000 ms (#791), exposing the lockout cliff. AWS SDK Javadoc also cautions against `ADAPTIVE_V2` when predictable latency matters or a single client serves multiple resources, and upstream AWS SDK v2 now defaults to `STANDARD`.

Add `s3.retry.mode` (valid values `standard` and `adaptive_v2`, case-insensitive) to `S3StorageConfig`, wire it in `S3ClientBuilder`, and switch the default to `standard`. `STANDARD` keeps jittered exponential backoff and the SDK retry quota circuit breaker without the client-side rate limiter. Per-role overrides (such as `inkless.storage.fetch.s3.retry.mode`) work through the existing `InklessConfig` role layering.

Add `S3ThrottlingRecoveryTest` to verify concurrent fetches recover after `503 SlowDown` throttling with the default mode and that pre-attempt timeouts with `adaptive_v2` increment `configured-timeout-errors`.

Assisted-by: Gemini 4 Neon
Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the S3 retry-mode and timeout-metrics changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@jeqo
jeqo marked this pull request as ready for review November 30, 2026 15:06
@jeqo
jeqo requested a review from viktorsomogyi November 30, 2026 15:31
@viktorsomogyi viktorsomogyi 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.

Just had one minor comment to this.

// ApiCallTimeoutTrackingStage wraps ApiCallAttemptMetricCollectionStage, so an
// ApiCallTimeoutException never appears on an ApiCallAttempt child. Record it here so
// call-level timeouts (including waits before any HTTP attempt starts) remain visible.
if (context.exception() instanceof ApiCallTimeoutException) {
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.

"When the call timeout fires mid-attempt, the attempt child already records OTHER via publish() (line 371), so this call now counts in both other-errors and configured-timeout-errors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch! TimeoutExceptionHandlingStage throws a raw InterruptedException on mid-attempt call timeouts, so the SDK attempt stage records OTHER.
Instead of suppressing this which would require ThreadLocal mechanism to bridge onExecutionFailure to publish, I'm documenting this double-counting to keep the interceptor stateless. Last fixup commit is updating docs and testing for this.

@jeqo
jeqo requested a review from viktorsomogyi December 1, 2026 08:55
@jeqo
jeqo enabled auto-merge (squash) December 1, 2026 10:02
@jeqo
jeqo merged commit 149e3e1 into main Dec 1, 2026
10 of 11 checks passed
@jeqo
jeqo deleted the jeqo/s3-throttling branch December 1, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0