Repository navigation
feat(subnet-splitting): make destination orchestrators restart the replica - #11238
Conversation
bad2b0c to
3ef8534
Compare
3ef8534 to
fcfbf7e
Compare
fcfbf7e to
0599d90
Compare
0599d90 to
27c00d3
Compare
c525a8b to
b87847d
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Two moderate CUP-provider issues remain, including potentially unbounded repeated registry scans.
Pull request overview
Adds subnet-splitting support to CUP discovery and restarts destination replicas after subnet identity changes.
Changes:
- Detects scheduled splits and targets post-split CUP sources.
- Restarts destination replicas when subnet IDs change.
- Prevents registry CUP construction from split records.
File summaries
| File | Review |
|---|---|
rs/orchestrator/src/upgrade.rs |
Handles subnet changes and replica restarts. |
rs/orchestrator/src/registry_helper.rs |
Simplifies subnet lookup. |
rs/orchestrator/src/error.rs |
Adds invalid split-assignment errors. |
rs/orchestrator/src/catch_up_package_provider.rs |
Detects splits and fetches post-split CUPs. Two moderate issues remain: repeated expected warnings and unbounded registry-version scanning. |
rs/consensus/cup_utils/src/lib.rs |
Excludes splitting records from registry CUP construction. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🟡 Changes recommended
Restart state is not retry-safe, and chained destination-side splits can leave nodes targeting the wrong subnet.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
The pre-split-upgrade test writes the wrong subnet and replica version, leaving that interaction unverified.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
CUP signer metadata is unauthenticated but is used to update subnet assignment, enabling state loss or denial of service.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Balanced
|
✅ No security or compliance issues detected. Reviewed everything up to 975659b. Security Overview
Detected Code Changes
|
67217ba to
b5fa49c
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
It changes state-preserving subnet transition, recovery, CUP validation, and replica restart behavior in operationally critical paths.
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0 new
- Review effort level: Balanced
…inity#11768) During an NNS Recovery on Failover Nodes, the failover nodes' orchestrators detect it by consistently looking for a `cup_contents.registry_store_uri` in their subnet's `CatchUpPackageContents` at the latest registry version and download a recovery local store before restarting the orchestrator process. If the download fails, the upgrade loop retries at the next iteration. ## Problem Since the recovery CUP was persisted *before* attempting the download, the next iteration of the loop now tries to determine its `subnet_id` out of the recovery CUP, but the latter's registry version corresponds to the new registry, that we haven't extracted yet. The upgrade loop is then [stuck](https://sourcegraph.com/r/github.com/dfinity/ic@0422ba2f4e80356900dd4a3edde2abbfe203e1b6/-/blob/rs/orchestrator/src/upgrade.rs?L798-801) inside `fn get_subnet_id` because it doesn't have the CUP's registry version available. This download almost always fails the first time in `sr_nns_failover_nodes_test` because the UVM isn't fully ready yet by the time the nodes attempt to download. ## Then why did it not flake before? The system test setup is not 100% realistic as the original registry has 1 version and the parent NNS registry has 2 versions. The recovery CUP has registry version 2, which *by chance* (or non-chance), is still valid even when adding the parent NNS mutations on top of the original registry. By modifying the system test and adding a few dummy versions to the original registry (see changes), which is much more realistic, the test starts failing. ## Then why did it not appear in the mainnet NNS setup? The mainnet NNS setup also uses NNS recovery on failover nodes, and with an original registry with many more versions than the parent NNS, so why does it work there? We were lucky: in this setup, the UVM is already [setup before](https://sourcegraph.com/r/github.com/dfinity/ic@0422ba2f4e80356900dd4a3edde2abbfe203e1b6/-/blob/rs/tests/testnets/mainnet_nns/src/lib.rs?L244-245) attempting this whole process, so the download never fails and we never stay stuck in a loop. ## Why did it appear only now? dfinity#11238 recently made the upgrade loop read the `subnet_id` between the CUP is persisted but before attempting to download the local store. This is the exact same `fn get_subnet_id` that returns an error in the scenario described above. ## Proposed solution Make a failed download retry-safe. To do so, we propose to not persist a CUP when it actually corresponds "to a different registry". This means we should look for the `registry_store_uri` before determining the latest CUP (which persists it). Though this is not sufficient: when restarting the orchestrator process, we want to have persisted the recovery CUP (such that the new process sees it). Thus, persist it precisely just before restarting the process. If the download failed, the CUP wouldn't get persisted and we retry the download in the next iteration. P.S.: also stop leaking tempdirs if anything fails P.S. 2: also remove the name on the restored IC to collect IC node logs of the latter (see how [`sync_with_vector`](https://sourcegraph.com/r/github.com/dfinity/ic@0422ba2f4e80356900dd4a3edde2abbfe203e1b6/-/blob/rs/tests/driver/src/driver/vector_vm.rs?L144) only reads the unnamed IC)
dfinity#11744) There is quite a lot going on in this PR. It is more of a `refactor` of the orchestrator's process manager but it still introduces the following functional changes (motivated by existing issues, thus `fix`): - Today, when `stop`ping a process, we just send a `SIGTERM` and instantly return. There's no guarantee that the process actually terminated, just that "it probably will in the future". This is great for not blocking the thread, but it is in contradiction with - The logic of stopping the replica before removing the state when leaving a subnet (today, there's technically a race where the state is removed while the replica is still running for a bit), - The logic of stopping-then-starting the replica when a recovery CUP is observed or the subnet ID changes, - The logic of stopping-then-starting `ic-boundary` when the domain name changes, - The [upcoming](dfinity#11349) logic of stopping-then-starting `ic-gateway` when its config changes. This PR thus modifies `stop` to block until the process actually terminated: if `stop` returned `Ok(())`, the process is guaranteed to have terminated, which fixes the cases above. - Moreover, `stop` does so by waiting up to 30 seconds, then tries again with `SIGKILL` for up to 10 seconds. This is in concordance with how systemd does it and allows force-killing a stuck process. This also means that this function could take up to 40 seconds to return, and blocks a tokio worker thread doing so (though I think that's acceptable since it should be very rare and the runtime has many threads). - The previous point means that the upgrade loop could hold a write-lock on `MultipleProcessesManager` for up to 40 seconds, preventing the dashboard from serving the processes' PIDs (that need a read-lock to that manager). Provide the dashboard with only a view of the processes' PIDs, not needing a lock on the entire manager. Also generalize over any number of processes with a type-erased `trait ProcessObserver`. - P.S.: We now display `ic-boundary`'s PID on the dashboard. - Today, the `stop_replica_if_recovery_cup_or_subnet_changed` function in the upgrade loop is fragile because it assumes we will always reach it on the iteration where we observe the recovery CUP or subnet-split. Though, if there was an error between the observation and that call, then the next iteration would not re-observe it and the replica would not be restarted (this was already mentioned [here](dfinity#11238)). - We fix this by moving this responsibility out of the upgrade loop and move it to every implementer of `Process`. This allows to simplify the upgrade loop and to remove the `IcBoundaryManager`'s custom restart logic by including it directly into `ProcessManager<P>` for any `P: Process`.
This PR implements changes to the orchestrator to support subnet splitting.
Today, the orchestrator tries to determine the latest CUP by looking at its local CUP's subnet ID. It contacts peers determined by this subnet's membership at the latest registry version and looks for a potential recovery (or genesis for a new subnet) CUP for this subnet, also at the latest registry version.
The proposed change are the following:
Note that, unlike @kpop-dfinity's original design, the proposed implementation does not change the existing behaviour during membership changes that are independent of a subnet split. In his approach, orchestrators would fetch & verify CUPs from the subnet ID they were part of at the latest registry version. Though simpler, this could negatively affect situations where nodes get moved from one subnet to the other without a split, since they would leave the subnet before being able to finish their work. It would also make recoveries harder.
Happy path
Note: if an upgrade was scheduled shortly before or after a split, it should still "just work" (except if we are unlucky, see later below). If it was scheduled after, the subnet anyways does not bump the registry version past the scheduled split, so the upgrade will simply be triggered on a following summary. If it was scheduled shortly before in such a way that its registry version ends up in the
Scheduled(and thus alsoPostSplit) summary, the orchestrators will execute the upgrade right at the same time as the split. It shouldn't lead to misbehaviour.Unhappy paths
An upgrade was scheduled shortly before a split but we're unlucky
As explained previously, destination orchestrators will not pick up CUPs created between the moment the registry schedules the split and the split actually triggers:
H=498, replicas create a summary at heightH=500withoutScheduledstatus because the registry version is not stable, then create a CUP. Then, destination orchestrators will not adopt this CUP because the signature doesn't verify. If this CUP indicates an upgrade (scheduled during the previous interval), half of the subnet (intended for source) will upgrade while the other half (intended for destination) will stay stuck. We'd have to split the state manually and recover both halves individually, just like in the next scenario.Subnet stalls between the registry scheduled the split but before the subnet actually triggers it
Any recovery CUP would pin the latest registry version, which contains the post-split topology. This mean that if such a scenario were to happen, we would have to split the state manually and upload them to the respective halves. All orchestrators are looking for potential recovery CUPs according to the post-split membership already as soon as the registry changes are observed, so the two subnets can be recovered individually.
One half manages to create a post-split CUP and make progress while the other half stays stuck
Be it source or destination, orchestrators will always fetch peer/registry CUPs according to their post-split membership and will not be confused by the other half's "normal" CUPs that will be created past the split. For the same reason, it is also possible to recover this stuck half without affecting the other one.