8000 feat(inkless:control-plane): add standby circuit breaker with primary fallback [KC-858] by jeqo · Pull Request #910 · aiven/inkless · GitHub
[go: up one dir, main page]

Skip to content

feat(inkless:control-plane): add standby circuit breaker with primary fallback [KC-858] - #910

Merged
giuseppelillo merged 1 commit into
mainfrom
jeqo/kc-858-standby-circuit-breaker
Dec 2, 2026
Merged

giuseppelillo merged 1 commit into
mainfrom
jeqo/kc-858-standby-circuit-breaker

Conversation

@jeqo
@jeqo jeqo commented Nov 27, 2026
Copy link
Copy Markdown
Contributor

Builds on #906.

When a PostgreSQL read replica restarts or becomes unreachable during a switchover, findBatches calls against readDataSource stall up to the pool or socket timeout and fail with UNKNOWN_SERVER_ERROR until DNS failover completes.

Add StandbyCircuitBreaker when both read.* and read.primary.* are configured:

  • Classify standby connectivity and timeout failures across the cause, nextException, and suppressed chains (08*, 57P01, 57P02, 57P03, SQLTransientConnectionException, SocketTimeoutException, ConnectException, UnknownHostException), excluding query and serialization errors (40001, 40P01).
  • Fall back immediately to primaryReadJooqCtx through the fail-fast concurrency limiter on every standby connectivity failure (including failures before reaching the trip threshold) and while OPEN, returning per-partition retriable KAFKA_STORAGE_ERROR when the limiter rejects or the primary query throws.
  • Trip CLOSED -> OPEN after standby.circuit.breaker.failure.threshold (default 3) consecutive failures, soft-evict idle standby pool connections so recovery resolves fresh DNS, and probe the standby with SELECT 1 on a daemon thread every standby.circuit.breaker.probe.interval.ms (default 10000) using fixed-delay scheduling. Close on the first successful probe and bump a generation counter so late in-flight failures from an earlier outage can't re-trip the recovered circuit.
  • Publish StandbyCircuitOpen (CAS-detached on close() so rebuilt control planes don't clobber each other's gauge), StandbyFallbackRate, and StandbyFallbackFailureRate on PostgresControlPlaneMetrics, reusing FindBatchesPrimaryQueryTime and PrimaryReadLimitRejectedRate, and regenerate the config and metrics reference docs.

Testing

  • StandbyCircuitBreakerTest verifies failure classification, cycle safety, CLOSED -> OPEN -> CLOSED transitions, soft eviction, stale-generation protection, rebuild-safe gauge detachment, and non-blocking close().
  • PostgresControlPlaneStandbyProtectionTest exercises a local TCP proxy in front of Testcontainers PostgreSQL to verify pre-trip fallback, tripping open, bypassing the dead standby while open, concurrency-limit rejection and primary failure returning per-partition KAFKA_STORAGE_ERROR, and automatic recovery via the background SELECT 1 probe.
  • PostgresControlPlaneConfigTest and PostgresControlPlaneMetricsTest verify the new config defaults, ranges, and metrics.

@jeqo
jeqo added this pull request to stack #912 November 27, 2026 14:07
Base automatically changed from jeqo/kc-859 to main November 30, 2026 15:57
@giuseppelillo
giuseppelillo force-pushed the jeqo/kc-858-standby-circuit-breaker branch from 85884c1 to a362102 Compare November 30, 2026 15:57
@jeqo
jeqo requested a balanced review from Copilot December 1, 2026 08:36
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 remain for the standby circuit-breaker and automatic primary-fallback changes.

No open issues 🎉

What changed in this PR

Builds on #906’s standby-read protection by adding automatic primary fallback when the PostgreSQL standby becomes unreachable. Protection activates when both read.* and read.primary.* are configured.

Changes:

  • Add a standby circuit breaker with immediate primary fallback, background recovery probes, and per-partition retriable errors when fallback fails.
  • Add configurable failure thresholds, probe intervals, and circuit-breaker metrics.
  • Add unit and integration coverage for outages, recovery, concurrency limits, and lifecycle safety.
File Description
storage/​inkless/​src/​test/​java/​io/​aiven/​inkless/​control_plane/​postgres/​StandbyCircuitBreakerTest.java Tests classification, state transitions, eviction, and lifecycle safety.
storage/​inkless/​src/​test/​java/​io/​aiven/​inkless/​control_plane/​postgres/​PostgresControlPlaneStandbyProtectionTest.java Tests outage fallback, primary failures, limiter rejection, and recovery through a TCP proxy.
storage/​inkless/​src/​test/​java/​io/​aiven/​inkless/​control_plane/​postgres/​PostgresControlPlaneMetricsTest.java Verifies fallback meters and circuit-state gauge registration.
storage/​inkless/​src/​test/​java/​io/​aiven/​inkless/​control_plane/​postgres/​PostgresControlPlaneConfigTest.java Verifies circuit-breaker defaults and configuration limits.
storage/​inkless/​src/​main/​java/​io/​aiven/​inkless/​control_plane/​postgres/​StandbyCircuitBreaker.java Implements failure classification, circuit state, connection eviction, and recovery probes.
storage/​inkless/​src/​main/​java/​io/​aiven/​inkless/​control_plane/​postgres/​PostgresControlPlaneMetrics.java Adds circuit-state and fallback metrics with rebuild-safe gauge detachment.
storage/​inkless/​src/​main/​java/​io/​aiven/​inkless/​control_pla 8000 ne/​postgres/​PostgresControlPlaneConfig.java Defines failure-threshold and probe-interval settings.
storage/​inkless/​src/​main/​java/​io/​aiven/​inkless/​control_plane/​postgres/​PostgresControlPlane.java Integrates the breaker, limited primary fallback, and shutdown cleanup.
docs/​inkless/​metrics.rst Documents the three new standby-protection metrics.
docs/​inkless/​configs.rst Documents circuit-breaker settings, defaults, and valid ranges.

Review effort: Balanced

@jeqo
jeqo marked this pull request as ready for review December 1, 2026 08:56
… fallback [KC-858]

When a PostgreSQL read replica restarts or becomes unreachable during a
switchover, `findBatches` calls against `readDataSource` stall up to the
pool or socket timeout and fail with `UNKNOWN_SERVER_ERROR` until DNS
failover completes.

Add `StandbyCircuitBreaker` when both `read.*` and `read.primary.*` are
configured:

- Classify standby connectivity and timeout failures across the cause,
  `nextException`, and suppressed chains (`08*`, `57P01`, `57P02`,
  `57P03`, `SQLTransientConnectionException`, `SocketTimeoutException`,
  `ConnectException`, `UnknownHostException`), excluding query and
  serialization errors (`40001`, `40P01`).
- Fall back immediately to `primaryReadJooqCtx` through the fail-fast
  concurrency limiter on every standby connectivity failure (including
  failures before reaching the trip threshold) and while `OPEN`,
  returning per-partition retriable `KAFKA_STORAGE_ERROR` when the
  limiter rejects or the primary query throws.
- Trip `CLOSED -> OPEN` after `standby.circuit.breaker.failure.threshold`
  (default `3`) consecutive failures, soft-evict idle standby pool
  connections so recovery resolves fresh DNS, and probe the standby with
  `SELECT 1` on a daemon thread every
  `standby.circuit.breaker.probe.interval.ms` (default `10000`) using
  fixed-delay scheduling. Close on the first successful probe and bump a
  generation counter so late in-flight failures from an earlier outage
  cannot re-trip the recovered circuit.
- Publish `StandbyCircuitOpen` (CAS-detached on `close()` so rebuilt
  control planes do not clobber each other's gauge),
  `StandbyFallbackRate`, and `StandbyFallbackFailureRate` on
  `PostgresControlPlaneMetrics`, reusing `FindBatchesPrimaryQueryTime`
  and `PrimaryReadLimitRejectedRate`, and regenerate the config and
  metrics reference docs.

Testing

- `StandbyCircuitBreakerTest` verifies failure classification, cycle
  safety, `CLOSED -> OPEN -> CLOSED` transitions, soft eviction,
  stale-generation protection, rebuild-safe gauge detachment, and
  non-blocking `close()`.
- `PostgresControlPlaneStandbyProtectionTest` exercises a local TCP
  proxy in front of Testcontainers PostgreSQL to verify pre-trip
  fallback, tripping open, bypassing the dead standby while open,
  concurrency-limit rejection and primary failure returning
  per-partition `KAFKA_STORAGE_ERROR`, and automatic recovery via the
  background `SELECT 1` probe.
- `PostgresControlPlaneConfigTest` and `PostgresControlPlaneMetricsTest`
  verify the new config defaults, ranges, and metrics.

Assisted-by: Gemini 4 Neon
Co-authored-by: Cursor <cursoragent@cursor.com>
@jeqo
jeqo force-pushed the jeqo/kc-858-standby-circuit-breaker branch from a362102 to 48b494b Compare December 1, 2026 17:03
@jeqo
jeqo requested a review from giuseppelillo December 1, 2026 17:03
@giuseppelillo
giuseppelillo merged commit f9ebbbb into main Dec 2, 2026
7 of 8 checks passed
@giuseppelillo
giuseppelillo deleted the jeqo/kc-858-standby-circuit-breaker branch December 2, 2026 12:08
jeqo pushed a commit that referenced this pull request Dec 4, 2026
The 0.53 entry records the standby protection of the control plane, the
new default S3 retry mode, the switch fixes, and the first release of
`inkless-4.4`. It adds two upgrade notes that the generator draft
doesn't produce: the retry mode default changes from `ADAPTIVE_V2` to
`standard`, and the standby protection is opt-in.

The new `PostgresControlPlane` metrics trace to #906 and #910, so they
are shipped metrics, not documentation catch-up.

Assisted-by: Claude Opus 5.5
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