Repository navigation
[ISSUE #7826][ISSUE #7760] Reuse Divide keys and enforce one recovery probe - #7857
Conversation
Aias00
left a comment
There was a problem hiding this comment.
Review — Divide circuit-breaker key reuse and exclusive half-open probes
This is a carefully built change. I reviewed the production diff end to end (Upstream, UpstreamCircuitBreaker, CircuitBreakerCandidates, DividePlugin, AbstractHttpClientPlugin) and traced the state machine and the allocation paths rather than just reading the tests.
What I verified as correct
Key reuse is sound, including the invalidation rules.
Upstream.buildSelectorKey caches a single SelectorKey per upstream and compares (selectorId, url). I initially expected a missing protocol check to be a staleness bug, but protocolPrefix is private final transient, assigned once in the constructor from builder.protocol, and there is no setProtocol. So (selectorId, url) fully identifies the key, and setUrl correctly nulls the cache. The no-arg buildDomain() and buildSelectorKey also agree on the null-url case, so UpstreamCircuitBreaker.buildKey is behaviour-preserving.
Mutating the candidate list in place is safe.
CircuitBreakerCandidates.filter compacts the list with set/subList().clear(). UpstreamCacheManager.findUpstreamListBySelectorId returns new ArrayList<>(upstreamList), i.e. a fresh copy per call, so the shared cache is not at risk. The class comment states this invariant; worth keeping it there, because it is the one assumption the whole design rests on.
Probe exclusivity and generation fencing hold up.
tryAcquireHalfOpen moves OPEN → HALF_OPEN exactly once, acquireHalfOpenProbe captures state.generation under the state monitor, and recordProbeOutcome re-checks state == HALF_OPEN && generation == expected. A late CANCEL from a superseded probe therefore cannot reopen a newer incarnation, and recordSuccess bumping generation on a non-CLOSED transition correctly invalidates ordinary in-flight outcomes from the previous epoch. recordOrdinaryOutcome refusing to record unless state == CLOSED also prevents a request that started before the breaker opened from being double-counted.
Retry suppression for probes is the right call.
Forcing retryTimes = 0 when HALF_OPEN_PROBE is set is necessary: with failover enabled, another target's success would close a breaker whose own target is still failing. DefaultRetryStrategy filtering on isRequestAllowed is consistent with that, since a recovering target is no longer offered as a failover candidate.
P2C accounting stays balanced — the probe branch increments inflight and sets lastPicked only when the load balancer is P2C, and responseTrigger still decrements on the same path.
Non-blocking observations
tryAcquireHalfOpenProbeis now dead in production. AfterDividePlugin.filterByCircuitBreakerwas replaced, the only remaining callers areUpstreamCircuitBreakerTest. Consider deprecating it or folding it intoacquireHalfOpenProbeso the two acquisition paths cannot drift.isBlockingsemantics widened. It used to mean "open and still inside the wait window"; it now returns true forHALF_OPENas well. Today only tests consume it, so this is harmless, but if it is ever wired into a metric the name will be misleading.- Benchmark artifacts are heavy.
docs/benchmarks/divide-gateway/adds roughly 4.5k lines of raw sample dumps (baseline-execution-samples.txt,optimized-execution-samples.txt,profile-summary.csv,request-local-only.csv). The methodology, the README and the summary CSVs are genuinely useful; the raw per-request dumps are the kind of thing that is better hosted outside the repository (or attached to the PR) to keep the tree reviewable. Not a blocker — your call, and the maintainers may have a view. - The benchmark dependencies are correctly isolated in an opt-in
divide-gateway-benchmarkprofile withtestscope, so they do not leak into the default build.
CI
pr_build is currently red, but the failure is not from this PR:
shenyu-plugin-tracing TraceContinuityTest.testTheGatewayStartsTheTraceWithoutAnIncomingContext
onlyFinishedSpan:203 expected: <1> but was: <0>
That is the same span-timing flake I have seen on other PRs recently (it also hit #7867), and nothing in this diff touches the tracing module. Please re-run the job so the required check turns green — I am approving on the merits of the change, not on that run.
Nice work on the allocation numbers and on actually measuring them rather than asserting them.
The request completion can reach StepVerifier before TracingPlugin.doFinally ends and exports the gateway span. Await a finished span with a bounded timeout before retaining the exact count and parent/trace assertions.
Aias00
left a comment
There was a problem hiding this comment.
Re-review: Approved
Re-approving following the master merge in commit e057fdf06b (Merge master and reconcile exclusive circuit-breaker probe handling).
Verification:
- The previous intermittent span-timing failure in
shenyu-plugin-tracinghas been resolved with the tracing test fix merged from master. - Circuit breaker key caching per Upstream instance, exclusive half-open probe handling with generation gating, and retry suppression for probes remain sound and verified.
- All 46 CI checks passed with 0 failures, and
pr_buildis green.
Approved!
Build on the single half-open probe behavior merged in #7802 by reusing selector/domain breaker keys and tying every recovery request to its state and generation. This PR reduces candidate-filtering allocations, defers probe acquisition until subscription, and prevents stale request outcomes or retries through another target from resolving the wrong probe.
Closes #7826.
Closes #7760.
Builds on merged #7802.
Changes:
Validation:
The HTTP measurements cover the production gateway data plane on Windows loopback. Admin/data-sync transports and optional business/security plugins are outside this controlled fixture.
./mvnw clean install -Dmaven.javadoc.skip=true); targeted reactor installation and tests were run instead.Maintainer CI review follow-up — October 20
Address the reported
TraceContinuityTest.testTheGatewayStartsTheTraceWithoutAnIncomingContexttiming failure with the same focused test correction as #7867. Request completion can reach StepVerifier beforeTracingPlugin.doFinallyfinishes exporting the span;onlyFinishedSpannow waits for export with a five-second bound and retains its exact span-count, trace and parent assertions. Production tracing and circuit-breaker behavior are unchanged.All 71 tracing tests pass on Microsoft OpenJDK 17.0.18 with zero failures/errors/skips. Affected-reactor Checkstyle, Apache RAT and
git diff --checkpass. This commit starts a fresh CI run; repository permissions do not allow the PR author to rerun the prior upstream workflow directly.Conflict resolution against current master
Merge master
2777620105c434d42e23f3f3ce709a01568e0f36and reconcile the four overlapping breaker/Divide source and test files. Preserve the upstream three-argumentrecordOutcomeAPI and cancellation behavior while routing granted probes through state/generation-bound accounting. Keep all upstream breaker and Divide regression cases; align two cache mocks with the production cache's mutable request-owned snapshot. Add regressions for granted-probe success/failure and a stale completion arriving after a replacement probe has been granted.Validation on Microsoft OpenJDK 17.0.18: 192 distinct tests pass, with zero failures/errors/skips (156 breaker/model/Divide/HTTP client/tracing tests plus 36 retry strategy, body replay and timeout-budget tests). Affected-reactor Checkstyle and Apache RAT pass;
git diff --checkpasses. Benchmark measurements above are the previously recorded runs; they were not rerun for this merge. Full-repository and Docker E2E execution remain with CI.