Keep a snapshot past down and recreate the VM on restore
What changes
A lab can be left and returned to. down --keep-snapshot deletes the VM and its firewall rules and keeps the recorded snapshot, a reserved copy of the VM's address and the state record, at phase: suspended. restore on a VM that is gone builds a disk from the recorded snapshot and creates the VM in the recorded zone, with the recorded machine type, rig metadata and address, and a fresh max run.
flowchart LR
live[rig live] --> snap[lab snapshot<br/>records snapshot_id, snapshot_seconds]
snap --> keep[down --keep-snapshot<br/>VM and rules deleted, address reserved]
keep --> susp[phase suspended<br/>snapshot, address, record kept]
susp --> restore[lab restore<br/>disk from snapshot, VM created]
restore --> live
susp --> plain[plain down]
plain --> gone[snapshot, address, record removed]
live --> down[plain down]
down --> gone
susp -.->|reap leaves it| susp- Nothing is orphaned silently:
listandstatusshow the suspended record,reapleaves it, and a plaindownremoves the snapshot, the address and the record. snapshotrecordssnapshot_seconds.status --jsonmoves toschema_version8 with that one new key.- A second fix rides along because the proof found it: after any restore, the boot disk is named for the restore, and
snapshotaddressed the disk by instance name, so every snapshot after a restore failed with a 404.snapshotnow reads the boot disk from the instance. - The docs line is paid for by cutting the same number of words elsewhere in
gce/operations.md; the word budget is unchanged.
Why the snapshot time varies
Measured on one rig (100 GB boot disk, c2d-standard-8, running VM), one snapshot each:
| Snapshot | Data on disk | Seconds |
|---|---|---|
| first, full | 11 GB | 89 |
| second, nothing written between | 11 GB | 52 |
| after writing 20 GB of random data | 30 GB | 163 |
| third, nothing written between | 30 GB | 100 |
| first of the restored disk, full | 30 GB | 221 |
Time follows the data written since the previous snapshot of the disk, or the whole used disk for a first snapshot: about 7 to 8 s per GB in the three cases that wrote data. Two snapshots with nothing written between them differed by 2x (52 s and 100 s), so a service-side swing of that size is in the noise. At that rate 73 s is about 9 GB and 389 s about 48 GB, which would fit a rig that wrote far more between the two. That rig's fill was not recorded, so the cause of its 389 s is unmeasured.
Proof on a rig
SIM_OWNER=reentry, instance sim-reentry1, caproni base with --no-aigw: up, create the project root/reentry-marker, snapshot, down --keep-snapshot (instance list empty, snapshot READY, address RESERVED, phase suspended), restore (2 min), sign-in 200 and the project present at the same IP, then a plain down. Afterwards no instance, snapshot, address or disk of sim-reentry remained.
The selftest cases for each new behaviour are in gce/engine-selftest.sh; each fails without its change.
Closes #35 (closed)