Repository navigation
fix(multiorch): require the initial cohort to be failure-safe at bootstrap - #1349
Merged
Merged
Conversation
…strap ShardNeedsInitializationAnalyzer/ShardInitAction previously bootstrapped a shard as soon as the initialized-pooler count merely satisfied the durability policy (e.g. exactly 2 for AT_LEAST_N(2)), locking in a cohort with zero redundancy from the moment it was created — losing either member immediately after would leave the shard unable to elect a new leader. Added cohortSurvivesMemberLoss/CohortSurvivesAnyMemberLoss to go/common/consensus/cohort_safety.go (shared with the existing IsCohortMemberRemovalSafe, refactored to use the same primitive) and gate ShardInitAction on it, both before claiming and after resolving the committed cohort (crash-retry can commit a different, smaller set). Give ShardInitAction a short grace period so a merely-slower pooler has a chance to join before the cohort locks in; a shard that only ever has enough poolers to satisfy the policy but not survive a loss stays uninitialized until another pooler is added — this is intentional, not a bug: it's the only way to guarantee the initial cohort isn't fragile by construction. Signed-off-by: David Weitzman <[email protected]>
CohortMismatchAnalyzer already deferred removing a cohort member that was merely missing from the cache (not confirmed dead) until IsCohortMemberRemovalSafe allowed it, but a member self-reporting INELIGIBLE was removed unconditionally with no such gate — it could leave the shard unable to survive a subsequent leader failure. Apply the same gate to both removal paths. Signed-off-by: David Weitzman <[email protected]>
… e2e-friendly The failure-safe bootstrap gate added in the previous commit is strict by default (matching production), but that default would break most of the e2e suite: shardsetup.New()'s default pooler count is 2, and nearly every test package relies on that default via shared TestMain fixtures plus another dozen+ explicit 2-pooler test-level setups. Bumping every affected test to 3 poolers would also add real compute cost (an extra postgres instance + backup/restore cycle) suite-wide for tests that don't care about cohort redundancy at all. Added config.Config.allowUnsafeInitialCohort (--allow-unsafe-initial- cohort, default false/strict) so ShardInitAction can skip the failure-safe checks when a test explicitly wants to exercise a minimum-size cohort (e.g. spurious_failover_recovery_test.go's regression test for a 2-member cohort). Also moved ShardInitAction's grace period from a hardcoded constant to config.Config.shardInitGracePeriodBase/MaxJitter (mirroring leader-failover's existing pattern) — it was previously unconfigurable and would have added a real 4-12s delay to every e2e test that bootstraps a shard, unlike every other grace period in this codebase which e2e tests default to 0s. Wired shardsetup to default new multiorch instances to --allow-unsafe-initial-cohort and a 0s grace period (consistent with how every other grace period is defaulted for e2e speed), so the existing suite's 2-pooler setups keep working unchanged. Added WithRequireFailureSafeInitialCohort() and WithShardInitGracePeriod() for tests that want to opt into the strict, production-matching behavior. Signed-off-by: David Weitzman <[email protected]>
…of the failure-safety gate The localprovisioner e2e suite provisions exactly one pooler per zone on the same shard, so the cohort can never survive losing its only other member — never failure-safe by construction, per the new ShardInitAction gate. This permanently blocked shard bootstrap (confirmed via the "aren't failure-safe" error looping forever in the multiorch log), which two tests' bootstrap-wait loops surfaced as a hard timeout. Plumb the existing --allow-unsafe-initial-cohort flag through the local provisioner (MultiorchConfig field -> getCellServiceConfig -> process args, mirroring pooler-health-check-interval/recovery-cycle-interval) and set it in the shared test cluster config, since this suite tests provisioning and connectivity, not HA. Signed-off-by: David Weitzman <[email protected]>
Same root cause as the localprovisioner e2e fix: this single-machine demo's 2-3 total poolers all share one shard, so the cohort can never survive losing any single member. Patch the generated multigres.yaml to set allow-unsafe-initial-cohort: true for every cell's multiorch, the same way trim_cells/set_gateway_ports/set_pg_user already patch cluster init's output. Signed-off-by: David Weitzman <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…t-safety Signed-off-by: David Weitzman <[email protected]>
A permanently-broken INELIGIBLE member can never be removed from a standard 3-node AT_LEAST_N(2) shard under IsCohortMemberRemovalSafe. Intentional for now, not a bug: relaxing it needs a fallback that can still recruit an "ineligible" member for quorum in a genuine emergency, which doesn't exist yet. Signed-off-by: David Weitzman <[email protected]>
…grow Once a shard's init claim commits a cohort, ClaimShardInitialization always returns that same list on retry and never a fresh proposal -- by design, to avoid two coordinators each committing a different, non-overlapping initial cohort. But the failure-safety error still told operators to "add another pooler to this shard", which cannot possibly help once the cohort is committed. Distinguish the two cases: a currently-unreachable committed member may still come back, but if every committed member is already present and it's still not failure-safe, the cohort is stuck for good -- point at an externally-certified rule change (multiadmin) instead. Signed-off-by: David Weitzman <[email protected]>
…ed rule ReconcileCohortAction independently re-derived the current consensus rule via its own store read to both judge removal safety and anchor its UpdateConsensusRule CAS. That read could in principle disagree with the rule the engine's pre-execution recheck had just re-verified the problem against moments earlier, and the safety re-check itself duplicated logic the analyzer already applies against that same rule. Bundle the redetected problem and the rule it was verified against into a single RecheckedProblem value threaded through RecoveryAction.Execute, so mismatching them is a compile error rather than a calling-convention discipline problem. ReconcileCohortAction now CASes on that exact rule and no longer needs its own safety re-check or store.FindShardMembers call. Also makes the undecided-rule-proposal rejection explicit instead of an incidental side effect of the leader-liveness check. Signed-off-by: David Weitzman <[email protected]>
…t-safety Signed-off-by: David Weitzman <[email protected]>
dweitzman
marked this pull request as ready for review
August 21, 2026 16:05
ShardInitAction's own grace period was solving a problem the failure-safe cohort check (added alongside it) already solves: the check makes bootstrap retry-until-safe on its own, and collision avoidance with another coordinator is handled by the shared rule-change pipeline's collective recruitment backoff, not by this action. Return nil from GracePeriod(), like every other action with nothing to defer for. Also drops the duplicate shard-init-grace-period-* config knobs (identical defaults to the existing leader-failover-grace-period-* pair, no differentiated use) and the nil-config fallback code in ShardInitAction, which only existed to support tests that can now just construct a real config like every other action's tests do. Signed-off-by: David Weitzman <[email protected]>
simonbtomlinson
approved these changes
Aug 26, 2026
shanurwan
added a commit
to shanurwan/multigres-operator
that referenced
this pull request
Nov 26, 2026
Since multigres/multigres#1349, multiorch only initializes a shard whose initial cohort can lose any one pooler and still meet its durability policy. The resolver defaulted a single-cell pool to 2 poolers and a two-cell pool to 1 per cell, so those shards never got a primary. Default replicasPerCell to ceil(3 / cells), warn in the webhook when an explicit layout meets the policy but cannot bootstrap (judged by upstream consensus.CohortSurvivesAnyMemberLoss), and update the docs and tests that described 2 poolers as enough. Fixes multigres#684 Signed-off-by: Wan Nur Shafiqah <[email protected]>
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.
ShardInitAction bootstrapped as soon as pooler count merely satisfied the durability policy (e.g. exactly 2 for AT_LEAST_N(2)) — zero redundancy from the start.
CohortSurvivesAnyMemberLoss(shared primitive withIsCohortMemberRemovalSafe), checked before claiming and after resolving the cohort.--allow-unsafe-initial-cohortlets e2e tests opt out and use smaller, non-failure-safe cohorts.