One importer when committed sites federate¶
Status: Implemented.
Problem¶
With layoutManagement.siteRole unset every site is a layout writer. When two
sites that each already hold a committed layout configure remoteClusters for
each other, both operators run the federated import
(addRemoteNodesToLayoutLocked) on their first federation pass. Each stages the
other's roles on its own layout and applies the next version. ApplyClusterLayout
checks the version against the local copy only, so the sites commit two
different layouts of the same version, and every process logs:
ERROR garage_rpc::layout::history: Inconsistent layout histories: different
layout compositions for version 2. Your cluster will be broken as long as this
layout version is not replaced.
The layout-writer design record
documents the mechanism; siteRole: Follower avoids it, but the default
configuration races. The main flow of hack/e2e-multicluster.sh reproduces it:
over 20 runs of that flow on main, Garage logged post-federation version
conflicts in 9 runs (298 lines), and one full suite run failed
test_automatic_layout_management because site 1's layout never gained site
2's roles within the window.
Decision¶
When committed sites (layout version above 0) need to import each other,
exactly one of them imports. federatedImportDesignatedImporter ranks this
site and every configured remote that serves a committed layout, and picks the
site with the highest layout version; of equal versions, the site whose
GarageCluster UID is lexicographically smaller. A remote's UID is read from
the cluster-uid: tag on the committed roles of its configured zone in its own
layout; it must be the only UID in that zone.
The version comes first because Garage only appends a version equal to
current + 1 (LayoutHistory::merge). If the site behind imported, its merged
layout would reuse version numbers the other site already holds, and it would
then adopt the other site's newer layout, which lacks its own roles. When the
site ahead imports, its new version is above every other site's current one, so
each of them appends it (or, when the incoming history no longer stores their
version, replaces its history with it).
The decision is total across all remotes, not pairwise. With three committed sites A < B < C, a pairwise rule lets A import B and C while B imports C, which commits two different layouts with the same version. Here only A imports; B and C defer. The import reads every remote's layout at most once per federation pass (lazily, with the pass's context) and uses its fresh read of the remote it is importing from.
Every other site defers: addRemoteNodesToLayoutLocked logs "Deferring
federated import to the remote site that imports for all committed sites" with
the designated importer and returns without staging. The importer's merged
layout reaches it through Garage's gossip.
The deferral is bounded. A process-local record of when it started lets the
site import itself after federatedImportDeferral (2 minutes), so a designated
site that never imports (one-directional federation, an operator that is down
or older) cannot block the layout. The record is cleared when nothing is left
to import, when this site becomes the importer, or after an apply. After an
operator restart the site simply defers once more.
The tie-break applies only when it can be decided safely; otherwise behavior is exactly as before:
- this site's layout still at version 0 (a shared bootstrap, including the
staged-peer-role path in
garageNodeStagingIntent), or no UID on this site; - remotes that are unreachable, still at version 0, have untagged roles, or roles of several GarageClusters in their zone are not ranked, so they are never designated and never block this site.
Compatibility and data safety¶
No API, CRD, status, or generated-file change. The only behavioral difference
is that the higher-UID site withholds an import for at most two minutes while
the lower-UID site performs it, which removes a write that would have created a
conflicting layout version. siteRole: Follower keeps its current behavior (a
Follower never imports). Rolling back restores the race.
Alternatives considered¶
- Require
siteRolefor federation. A breaking change for every existing multi-writer deployment and for the default configuration. - Detect a conflict and re-apply a union layout. Both sites would detect it at the same time and could race again on the next version; the conflict is still logged first.
- Random backoff. Reduces but does not remove the race and makes tests nondeterministic.
Test plan¶
- Unit (
federated_import_tiebreak_test.go): UID extraction (single UID, other zones ignored, mixed or untagged roles rejected); the importer choice for two and three sites with equal and unequal versions and for unrankable remotes; and the bounded deferral with a test clock (defers within the bound, imports at it, resets when the tie-break stops applying, per remote). - envtest (
federated_import_tiebreak_envtest_test.go): the real import performs no layout write when the peer has the lower UID or a higher version, stages and applies when this site wins, defers to a third configured site that wins, and imports itself once the bound has passed; the existingaddRemoteNodesToLayoutspecs are unchanged. - e2e (
hack/e2e-multicluster.sh): newtest_federated_layout_history_consistentin the main flow fails when either site's Garage logged a conflict for any version from 2 on. Version 1 is excluded because both sites bootstrapped their own version 1 before federation.