Repository navigation
Conversation
… 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #906.
When a PostgreSQL read replica restarts or becomes unreachable during a switchover,
findBatchescalls againstreadDataSourcestall up to the pool or socket timeout and fail withUNKNOWN_SERVER_ERRORuntil DNS failover completes.Add
StandbyCircuitBreakerwhen bothread.*andread.primary.*are configured:nextException, and suppressed chains (08*,57P01,57P02,57P03,SQLTransientConnectionException,SocketTimeoutException,ConnectException,UnknownHostException), excluding query and serialization errors (40001,40P01).primaryReadJooqCtxthrough the fail-fast concurrency limiter on every standby connectivity failure (including failures before reaching the trip threshold) and whileOPEN, returning per-partition retriableKAFKA_STORAGE_ERRORwhen the limiter rejects or the primary query throws.CLOSED -> OPENafterstandby.circuit.breaker.failure.threshold(default3) consecutive failures, soft-evict idle standby pool connections so recovery resolves fresh DNS, and probe the standby withSELECT 1on a daemon thread everystandby.circuit.breaker.probe.interval.ms(default10000) 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.StandbyCircuitOpen(CAS-detached onclose()so rebuilt control planes don't clobber each other's gauge),StandbyFallbackRate, andStandbyFallbackFailureRateonPostgresControlPlaneMetrics, reusingFindBatchesPrimaryQueryTimeandPrimaryReadLimitRejectedRate, and regenerate the config and metrics reference docs.Testing
StandbyCircuitBreakerTestverifies failure classification, cycle safety,CLOSED -> OPEN -> CLOSEDtransitions, soft eviction, stale-generation protection, rebuild-safe gauge detachment, and non-blockingclose().PostgresControlPlaneStandbyProtectionTestexercises 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-partitionKAFKA_STORAGE_ERROR, and automatic recovery via the backgroundSELECT 1probe.PostgresControlPlaneConfigTestandPostgresControlPlaneMetricsTestverify the new config defaults, ranges, and metrics.