refactor: dedup helpers across cmd/hypervisor/snapshot#59
Merged
Conversation
3 tasks
6856f27 to
24a9988
Compare
- hypervisor.ResolveAndLoad combines ResolveRef+LoadRecord under one DB lock; collapses 3 call sites (CH console, FC console, CH extend's runningVMClientWithRecord) - cmdcore.CloseOnCancel wraps context.AfterFunc(stream.Close); 4 call sites (cmd/snapshot/handler.go × 2, cmd/vm/run.go × 2) shrink to one defer line each - snapshot/localfile.insertRecord folds the 18-line name-collision + Snapshots[id]+Names[name] block shared by Create (Pending) and Import - cmd/vm/status_test.go: equalStrings → slices.Equal (Go stdlib)
24a9988 to
cbacfea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
4 small dedup extractions from the final master audit (reuse agent findings #1, #2, #5, #22). Net -29 LOC.
hypervisor.ResolveAndLoad(ctx, ref) (id, VMRecord, error)combinesResolveRef+LoadRecordunder a single DB lock. 3 call sites:hypervisor/cloudhypervisor/console.go,hypervisor/firecracker/console.go,hypervisor/cloudhypervisor/extend.go'srunningVMClientWithRecord.cmdcore.CloseOnCancel(ctx, c) func() boolwraps thecontext.AfterFunc(...stream.Close)+defer stop()boilerplate. 4 call sites:cmd/snapshot/handler.go× 2,cmd/vm/run.go× 2.snapshot/localfile.insertRecordfolds the 18-line name-collision check +Snapshots[id]+Names[name]insert shared byCreate(Pending) andImport(finalized).cmd/vm/status_test.goswaps hand-rolledequalStringsforslices.Equal.Followups:
perf/batch-tx-and-cache(separate PR) for List off-lock IO + DeleteAll batch tx + FindVMMByCmdline per-batch cache.Based on
chore/ship-ready-cleanup(PR #58) to avoidhypervisor/inspect.goconflict.Test plan
make fmt-check && make lint && go test -race ./...— 21 packages green, lint 0, fmt 0