Skip to content

feat(api): add rebalance option for clone and snapshot restore#488

Draft
kvaps wants to merge 3 commits intoLINBIT:masterfrom
kvaps:feat/auto-rebalance-after-clone-restore
Draft

feat(api): add rebalance option for clone and snapshot restore#488
kvaps wants to merge 3 commits intoLINBIT:masterfrom
kvaps:feat/auto-rebalance-after-clone-restore

Conversation

@kvaps
Copy link
Copy Markdown

@kvaps kvaps commented Mar 4, 2026

Summary

Add a rebalance boolean parameter to the clone (POST /v1/resource-definitions/{rscName}/clone) and snapshot restore (POST /v1/resource-definitions/{rscName}/snapshot-restore-resource/{snapName}) REST APIs.

When set to true, after clone/restore completes, replicas are migrated to autoplacer-optimal nodes via sequential migrate-disk (toggle-disk with MigrateFrom) calls. This prevents replica concentration on source nodes in golden-image use cases (many VMs cloned from one template).

How it works

  1. Autoplacer is queried for fresh optimal placement (ignoring existing replicas)
  2. Migration pairs are computed (current non-optimal nodes → optimal target nodes)
  3. Sequential resourceToggleDisk calls with migrateFrom trigger async data sync and source cleanup

Without the flag, behavior is unchanged.

Ref: #487

Changes

  • OpenAPI spec: add rebalance field to ResourceDefinitionCloneRequest and SnapshotRestore
  • REST endpoints: pass rebalance through to handlers
  • New CtrlRscRebalanceHelper: computes optimal placement and triggers migrate-disk
  • Clone/restore handlers: invoke rebalance helper when flag is set (best-effort, errors don't block the operation)

Test plan

  • ./gradlew compileJava passes (verified locally)
  • Manual test: clone with rebalance → verify replicas migrate to optimal nodes
  • Manual test: snapshot restore with rebalance → same
  • Without rebalance flag → no migration (backward compatible)

Note

CLI support (--rebalance flag) requires a corresponding change in linstor-client.

kvaps and others added 3 commits March 4, 2026 10:27
Add a `rebalance` boolean field to both ResourceDefinitionCloneRequest
and SnapshotRestore OpenAPI schemas. When set, replicas will be migrated
to autoplacer-optimal nodes after the operation completes.

Regenerate JsonGenTypes.java from the updated OpenAPI spec.

Ref: LINBIT#487

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Pass the new rebalance parameter from REST endpoints through to the
handler methods for both clone (CtrlRscDfnApiCallHandler) and snapshot
restore (CtrlSnapshotRestoreApiCallHandler). When rebalance is true,
CtrlRscRebalanceHelper.trigger() is called after the operation completes.

Existing callers (rollback, backup restore) pass null for rebalance.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
…igration

Implement a helper that migrates replicas to autoplacer-optimal nodes
after clone or snapshot restore. The helper queries the autoplacer for
fresh optimal placement, computes migration pairs, and sequentially
triggers migrate-disk (toggle-disk with MigrateFrom) for each pair.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
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.

1 participant