Skip to content

fix: detect standby count losses for shared names - #69

Merged
alexshapalov merged 1 commit into
pgrundev:mainfrom
DivyamTalwar:fix/detect-replica-count-loss
Sep 27, 2026
Merged

alexshapalov merged 1 commit into
pgrundev:mainfrom
DivyamTalwar:fix/detect-replica-count-loss

Conversation

@DivyamTalwar

Copy link
Copy Markdown
Contributor

What and why

Closes #67.

A boolean presence map collapsed multiple standbys with the same application name into one entry. Losing one of those standbys was invisible as long as another remained. Compare counts per existing stable key and emit one disconnect delta per shrinking group, carrying the actual before/after counts.

Application names remain stable across IP changes; unnamed standbys retain the client-address fallback. This detects a group-size loss, not an unproven identity change among equal-sized groups.

Verification

Verified commit: bbe15f07ce2e2302282a3cc89bdb20aacf82e8dc.

  • The shared-name 2-to-1 regression fails on unchanged base a1e6561e366455756c45a16a46647f882b3b6a1c because no disconnect delta is emitted.
  • go test -race ./internal/diff ./internal/findings: passed against the real dependencies.
  • go test -race ./internal/diff -run 'TestReplicaGone_detectsCardinality|TestReplicaCount' -count=20: passed.
  • Controls cover unchanged/growing groups, total disappearance, independent losses, unnamed address fallback, unknown identities, stable names with changing addresses and missing replication sections.
  • bash scripts/gate.sh: passed on committed HEAD: build, vet, pinned lint, tests and all six release-target builds.
  • go test -race ./...: passed. Formatting and git diff --check are clean.

Scope and risk

No collector SQL, dependencies, migrations, finding IDs or JSON fields change. The existing disconnect-delta count values now reflect group size instead of always being 1 and 0; its downstream finding consumer uses the same ID and subject. Tests use synthetic collected contexts rather than a live replication topology. PostgreSQL-dependent tests self-skip locally. Reverting this commit restores the previous comparison.

Checklist

  • Committed-HEAD gate and full race suite pass.
  • Read-only, privacy and deterministic-finding invariants are unchanged.
  • No new finding or JSON field; catalog/schema unchanged.

Standby presence was reduced to a boolean per application name, hiding a loss when another same-named standby remained. Compare group counts and emit one delta per shrinking key while preserving stable-name and address-fallback behavior.

Regression tests cover 2-to-1 loss, unchanged and growing groups, complete group loss, independent groups, address fallback, unknown identities and missing sections. The new regression fails on the base; affected diff and findings race tests pass.

Closes pgrundev#67
@alexshapalov
alexshapalov merged commit e63dfcd into pgrundev:main Sep 27, 2026
19 checks passed
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.

Replica loss is missed for duplicate standby application names

2 participants