Repository navigation
lxd: Run replicator migration source in the Replicating instance operation - #19580
18Abhinav07 wants to merge 5 commits into
Conversation
…ation The local migration source was scheduled as a separate top-level "Migrating instance" operation, so clients showed the instance as migrating and the transfer progress was missing from the replicator run's operation tree. Cancelling the run now interrupts the transfer, so wrap the context error in that case to keep the operations ending as cancelled. Fixes canonical#19452 Signed-off-by: Abhinav Pangaria <127080854+18Abhinav07@users.noreply.github.com>
…tance operation Signed-off-by: Abhinav Pangaria <127080854+18Abhinav07@users.noreply.github.com>
kadinsayani
left a comment
There was a problem hiding this comment.
Thanks, this is the right direction. Running the source inside "Replicating instance" and disconnecting it on ctx.Done() also fixes the replicating-phase hang in #19599 for local instances, so it's worth mentioning that issue in the description too.
A few things:
- The path for an instance on another cluster member (
replicator_run.goL1219-L1239) still usessrcMigrateOp.Wait()anddestOp.Wait(), which ignore the run's context. Cancelling the run there still leaves the replicator in "Running". I wrote that up on #19599. Fine as a follow-up, but could the description say that this PR only fixes the local-member case? - The old "Migrating instance" operation was attached to the instance's entity URL. Has anything relied on it to show the instance as busy, or to keep other requests off it during the transfer? I'd expect the lock that
MigrateSendtakes to cover that, but it's worth confirming. - Neither the PR nor the follow-up has a test for cancelling a run yet. When you add
test_clustering_replicator_cancel, please cover an instance on the replicator's member and one on another member.
|
|
||
| // Guard against leaving the destination sink operation running if we fail | ||
| // before starting the source; disarmed once the source op is scheduled. | ||
| // before starting the source; disarmed once the transfer starts. |
There was a problem hiding this comment.
Nit: the guard is now disarmed before the transfer starts, not once it starts (see the comment on L1297). Something like "disarmed just before the source connects" would match the code.
| return srcMigration.Do(ctx, s, innerOp) | ||
| }, | ||
| } | ||
| destOpCancelled = true // source connects via websockets; cancel would interrupt an in-flight transfer |
There was a problem hiding this comment.
This disarms the guard before srcMigration.Do() runs. If Do() fails before the source connects (for example, during the 10-second wait for the control connection), the destination sink operation is left to time out on its own. Main has the same window, but now that Do() runs inline it's easy to close. One way is to cancel the sink explicitly on error:
err = srcMigration.Do(ctx, s, op)
if err != nil {
_ = destOp.Cancel()
...
}Cancelling a sink that has already failed is harmless, so this doesn't need to know how far the transfer got.
| destOpCancelled = true // source is now connected via websockets; cancel would interrupt an in-flight transfer | ||
| // Cancelling the run disconnects the migration, so report the cancellation rather than the | ||
| // resulting connection error. | ||
| if ctx.Err() != nil { |
There was a problem hiding this comment.
Wrapping with %w keeps errors.Is(err, context.Canceled) true, so the step ends as Cancelled. 👍
One thing to be aware of: with no Cancelled replicator status, the finalize hook still records the run as Failed and raises a ReplicatorRunFailure warning when a user cancels it. Is that intended, or should a cancelled run be treated differently?
The waits for an instance on another cluster member ignored the run's context, so cancelling the run left it Running. They now use it, and on cancel the source or sink operation on that member is cancelled over a fresh connection, because the run's member clients send every request with the cancelled context. Forward operations can't be cancelled while pending, so one that starts after the run was cancelled now skips its instance. If the local source fails, the destination sink is cancelled instead of left to time out. Signed-off-by: Abhinav Pangaria <127080854+18Abhinav07@users.noreply.github.com>
|
Thanks, all pushed. Remote member: fixed here too. The forward, snapshot and restore waits use the run context, and on cancel the member's op is cancelled over a fresh connection, since the run's member clients carry the cancelled context. Forward ops are |
There was a problem hiding this comment.
🟡 Changes recommended
An active moderate-severity cancellation-path issue remains in lxd/replicator_run.go, where a cancelled wait can leave the target instance-creation operation running.
1 open issue
What changed in this PR
Updates clustered replicator runs so local migration sources execute within the existing "Replicating instance" operation, with improved cancellation propagation across source members and target sinks.
Changes:
- Runs local migration sources directly on the replicator child operation while preserving transfer progress.
- Uses context-aware waits and fresh connections or contexts to cancel remote source and target operations.
- Adds clustering coverage for operation hierarchy, cancellation during snapshot and transfer phases, and successful reruns.
| File | Description |
|---|---|
| test/suites/clustering.sh | Adds operation-tree assertions and an end-to-end multi-member replicator cancellation and recovery test. |
| test/includes/test-groups.sh | Registers the new replicator cancellation test in the storage test group. |
| lxd/replicator_run.go | Runs local migration sources within replicator operations and improves distributed cancellation handling. |
Review effort: Lite
| destOpCancelled = true | ||
|
|
||
| return destOp.Wait() | ||
| return destOp.WaitContext(ctx) |
There was a problem hiding this comment.
Fixed in d3aaa5a: if the run is cancelled during the final wait, the sink is now cancelled too, in both paths. All 11 replicator suites pass, including clustering_replicator_cancel.
|
Hi @18Abhinav07, thanks for tackling this, CI is failing due to static analysis/ lint check. Can you check the logs and make static analysis green? |
d3aaa5a to
42f067c
Compare
|
Fixed the empty-test-fail lint in the replicator cancel test and folded it into the test commit. Static analysis should pass now. |
|
Now static analysis for test suite is failing can you check? |
Signed-off-by: Abhinav Pangaria <127080854+18Abhinav07@users.noreply.github.com>
Once the source finished, the deferred cancel of the destination sink was disabled, so cancelling the run during the final wait left the target's Creating instance operation running. Cancel the sink in that case. Signed-off-by: Abhinav Pangaria <127080854+18Abhinav07@users.noreply.github.com>
|
Fixed the jq --exit-status lint as well and ran the full static analysis and golangci-lint locally. Both pass now. |
42f067c to
0230390
Compare

What changed
lxd/replicator_run: the local migration source runs inside "Replicating instance". Waits on other members use the run context, and on cancel the member's op is cancelled over a fresh connection. A forward op that starts after a cancel skips its instance. Target sinks are cancelled over a fresh context when the source fails.test_clustering_replicator_cancel, with instances on two members.Why
Checklist