reconciler: convergence loops
For Go code, follow the repository Go anti-pattern rules.
Metal specification · overview: Metal overview
Purpose
This package schedules convergence work. It owns no VM, image, snapshot, or traffic state.
Types
| Type | Responsibility |
|---|---|
VirtualMachineReconciler | Runs VM reconciliation passes. |
NewSleepTransferReconciler | Runs sleep staging, compression, upload, and eviction in a separate eight-worker pool. |
NewSleepRestoreReconciler | Reconciles sleeping VMs and restores remote artifacts in a separate eight-worker pool. |
ImageReconciler | Caches images, prunes unused images, kernels, and staged snapshots. |
MigrationReconciler | Advances each active destination migration. |
GuestChecker | Pings running guests every minute, so a silent guest counts as unavailable. |
CPUBurstLimiter | Runs Manager.LimitCPUBursts every 10 seconds, so a burstable VM above its baseline is limited. |
passScheduler | Runs a pass at startup, on an interval, and on request. |
Pass model
- Each operation has its own timeout.
- VM operations share a fixed number of slots across passes. A pass starts operations and does not wait for them, so one slow VM does not delay the next pass. A pass skips a VM whose operation still runs.
- A VM pass starts VMs with a pending change first. A wake ends a pass that waits for a slot, and the next pass resumes after the last routine VM, so a request does not wait for a full pass.
- An image pass runs up to five images at the same time. It reads the latest policy before it starts each image. A wake during the pass cancels each running image that the policy no longer caches.
- Sleep uploads and restores each use a separate pool of eight workers with the same timeout, backoff, wake, and shutdown behavior. They do not occupy normal VM reconciliation workers or wait for each other's pool.
- Errors are logged. A later pass retries safe operations.
- A failing VM waits twice as long after each failure, up to 1 minute. Wake clears the wait.
- Errors after cancellation are suppressed.
Ownership
- metald owns each goroutine and its context.
- The VM manager owns every state decision and per-VM lock.
Related
- internal/vm/SPEC.md owns VM reconciliation.
- internal/storage/SPEC.md owns image caching and pruning.