Skip to content

PHOENIX-7872 Addendum record HA failover duration on the CRR-write path and add a connection-failed counter - #2605

Open
lokiore wants to merge 1 commit into
apache:PHOENIX-7562-feature-newfrom
lokiore:PHOENIX-7872-failover-metric-placement
Open

PHOENIX-7872 Addendum record HA failover duration on the CRR-write path and add a connection-failed counter#2605
lokiore wants to merge 1 commit into
apache:PHOENIX-7562-feature-newfrom
lokiore:PHOENIX-7872-failover-metric-placement

Conversation

@lokiore

@lokiore lokiore commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Follow-up to the HA failover observability metrics added under PHOENIX-7872, correcting where two metrics are recorded on the HA client path.

  • HA_FAILOVER_DURATION_MS moved to the CRR-write path. It was recorded inside FailoverPhoenixConnection.failover(long), which is only reached through wrapActionDuringFailoverFailoverPolicy.shouldFailover() (returns false under the default ExplicitFailoverPolicy) or the explicit static failover(Connection, long) helper — neither runs during an autonomous, cluster-role-record-driven failover. The measurement now lives in HighAvailabilityGroup.refreshClusterRoleRecord, where the cluster-role transition is actually dispatched and where HA_FAILOVER_COUNT is already gated by shouldCountFailover. The dispatch block is wrapped in a try/finally so the duration is recorded on every exit (success, timeout, policy failure, interrupt), which avoids a silent metric miss if a future exit path is added. The now-dead timing in failover(long) is removed.
  • New HA_FAILOVER_CONNECTION_FAILED_COUNTER (GLOBAL_HA_FAILOVER_CONNECTION_FAILED_COUNTER), incremented at the single SQLException throw funnel in connectActive (no active cluster, cluster demoted mid-connect, or the underlying connect threw).

Class touch points:

  • FailoverPhoenixConnection — remove dead duration timing + now-unused import.
  • HighAvailabilityGroup — record duration on the transition-dispatch try/finally; increment the new counter on the connectActive throw funnel.
  • MetricType / GlobalClientMetrics — add the new counter constant; correct the HA_FAILOVER_DURATION_MS description to reflect the CRR-write recording site.

Why are the changes needed?

As placed, HA_FAILOVER_DURATION_MS never moved in production: the default ExplicitFailoverPolicy.shouldFailover() returns false, so FailoverPhoenixConnection.failover(long) is not auto-invoked during a real, CRR-driven failover. Recording the duration on refreshClusterRoleRecord ties it to the path that actually drives failovers, alongside the existing HA_FAILOVER_COUNT. The new connection-failed counter gives operators visibility into failed active-cluster connection attempts independent of the configured failover policy.

Does this PR introduce any user-facing change?

No. Client-side metric placement/addition only; no API or query-behavior change. These metrics are on an unreleased feature branch.

How was this patch tested?

Three unit tests added to HighAvailabilityGroupTest:

  • testCountedTransitionRecordsFailoverCountAndDuration — a counted role-flip transition driven through refreshClusterRoleRecord increments HA_FAILOVER_COUNT and records an HA_FAILOVER_DURATION_MS sample on the CRR-write path.
  • testConnectActiveFailureIncrementsFailedCounter — a failed connectActive (no active cluster) increments the connection-failed counter on its SQLException funnel.
  • testConnectActiveSuccessLeavesFailedCounterUnchanged — a successful connectActive leaves the counter unchanged (non-vacuous negative assertion).

Results: HighAvailabilityGroupTest 16/16, FailoverPhoenixConnectionTest 8/8. spotless:check clean on the touched files.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.8)

🤖 Generated with Claude Code

…th and add a connection-failed counter

The HA failover observability metrics added under PHOENIX-7872 recorded
HA_FAILOVER_DURATION_MS inside FailoverPhoenixConnection.failover(long). That
method is only reached through wrapActionDuringFailover -> FailoverPolicy
.shouldFailover(), which returns false under the default ExplicitFailoverPolicy,
or through the explicit static failover(Connection, long) helper. Neither runs
during an autonomous, CRR-driven failover, so the duration metric never moved in
production.

Move the duration measurement to the path that actually drives failovers:
refreshClusterRoleRecord, where the cluster-role transition is dispatched and
where HA_FAILOVER_COUNT is already gated by shouldCountFailover. The dispatch
block is wrapped in a try/finally so the duration is recorded on every exit
(success, timeout, policy failure, or interrupt), avoiding a silent metric miss
if a future exit path is added. The now-dead timing in failover(long) is removed.

Add HA_FAILOVER_CONNECTION_FAILED_COUNTER, incremented at the single SQLException
throw funnel in connectActive (no active cluster, cluster demoted mid-connect, or
the underlying connect threw). This tracks real active-cluster connection failures
regardless of the configured failover policy.

Tests: three unit tests in HighAvailabilityGroupTest -- a counted role-flip
transition records both HA_FAILOVER_COUNT and an HA_FAILOVER_DURATION_MS sample on
the CRR-write path; a failed connectActive increments the connection-failed
counter; a successful connectActive leaves it unchanged. HighAvailabilityGroupTest
16/16, FailoverPhoenixConnectionTest 8/8.

Generated-by: Claude Code (Opus 4.8)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lokiore
lokiore marked this pull request as ready for review August 20, 2026 20:26
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.

1 participant