Skip to content

fix(cubemaster): clean job rows after snapshot delete#559

Merged
kinwin-ustc merged 1 commit into
TencentCloud:masterfrom
xiaojunxiang2023:fix/snapshot-delete-orphan-job-list
Jun 27, 2026
Merged

fix(cubemaster): clean job rows after snapshot delete#559
kinwin-ustc merged 1 commit into
TencentCloud:masterfrom
xiaojunxiang2023:fix/snapshot-delete-orphan-job-list

Conversation

@xiaojunxiang2023

Copy link
Copy Markdown
Contributor

Summary

Fixes a bug where deleted snapshots still appeared in template list APIs until a second delete.

After the first DELETE /templates/{snapshotID}:

  • Single-snapshot lookup correctly returned not found
  • GET /templates and cubemastercli tpl ls still listed the deleted snapshot
  • A second delete was required to remove it from the list
image

Root cause

Snapshot delete (runSnapshotDeleteJob) removed template_definition metadata but did not remove related template_image_job rows.

ListTemplates appends orphan job records when no definition exists:

for _, job := range jobs {
    if _, ok := seen[job.TemplateID]; ok {
        continue
    }
    out = append(out, templateInfoFromJob(&job))
}

So the deleted snapshot was resurrected in list responses via job fallback entries.

On the second delete, has_snapshot returned false (definition gone, job fallback has no Kind), routing the request through template delete (cleanupTemplateJobs) instead of snapshot delete.

Fix

  • Call cleanupTemplateJobs after successful snapshot metadata cleanup, matching template delete behavior
  • Return terminal READY job info from executeSnapshotDeleteJob without re-querying job rows that were just deleted

Deploy And Verify

image

Comment thread CubeMaster/pkg/templatecenter/snapshot_ops.go Outdated
@xiaojunxiang2023 xiaojunxiang2023 force-pushed the fix/snapshot-delete-orphan-job-list branch from 2c77322 to 879453f Compare June 15, 2026 06:22
Comment thread CubeMaster/pkg/templatecenter/job_dto.go
Comment thread CubeMaster/pkg/templatecenter/snapshot_ops_test.go
Comment thread CubeMaster/pkg/templatecenter/snapshot_ops_test.go
@cubesandboxbot

cubesandboxbot Bot commented Jun 15, 2026

Copy link
Copy Markdown

PR #559 Review: fix(cubemaster): clean job rows after snapshot delete

Overview

This PR correctly fixes a bug where deleted snapshots reappeared in ListTemplates due to orphan template_image_job rows creating fallback entries. The fix replaces the old updateTemplateImageJob (set job row to READY) with runTemplateJobCleanup (DELETE job rows) and returns a terminal READY view from cloneTemplateImageJobInfo instead of re-querying deleted rows.

The changes are well-scoped, the root-cause analysis in the PR description is accurate, and the test suite covers the new behavior effectively. After reviewing across code quality, performance, test coverage, security, and documentation dimensions, I found a few areas worth addressing:

Notable Findings

1. Retry-failure returns success silently - snapshot_ops.go:730-738
When both the initial runTemplateJobCleanup and its retry fail, the function logs WARN and returns nil (success). While the snapshot metadata is already gone so returning success is correct, orphaned job rows remain unreconciled. The second failure should be logged at Errorf rather than Warnf so it is visible in production triage.

2. Empty-slice inconsistency in cloneTemplateImageJobInfo - job_dto.go:60
The len(src.RedoScope) > 0 guard means a non-nil empty slice []string{} is not deep-copied. Removing the guard makes the copy consistent for all slice states at negligible allocation cost.

3. Missing doc on terminalSnapshotDeleteJobInfo - snapshot_ops.go:694
This function constructs the terminal response without re-querying deleted DB rows but lacks a doc comment explaining why it exists.

Overall Assessment

The fix is correct and well-implemented. The clone-and-stamp pattern in executeSnapshotDeleteJob is the right approach - it avoids a DB ound-trip for a record that has just been deleted. The test coverage is comprehensive for the PR scope, and the performance impact is positive (fewer DB calls per delete operation). None of the findings above are blocking; they are refinements for production robustness and maintainability.

@xiaojunxiang2023 xiaojunxiang2023 force-pushed the fix/snapshot-delete-orphan-job-list branch from 879453f to 8530777 Compare June 15, 2026 06:31
Comment thread CubeMaster/pkg/templatecenter/snapshot_ops_test.go Outdated
@xiaojunxiang2023 xiaojunxiang2023 force-pushed the fix/snapshot-delete-orphan-job-list branch 2 times, most recently from da06591 to a72e918 Compare June 25, 2026 15:04
Comment thread CubeMaster/pkg/templatecenter/snapshot_ops_test.go
Comment thread CubeMaster/pkg/templatecenter/job_dto_test.go
Comment thread CubeMaster/pkg/templatecenter/snapshot_ops.go
@xiaojunxiang2023 xiaojunxiang2023 force-pushed the fix/snapshot-delete-orphan-job-list branch 2 times, most recently from bb29ce1 to 52de0c7 Compare June 25, 2026 15:26
Comment thread CubeMaster/pkg/templatecenter/snapshot_ops.go
@xiaojunxiang2023 xiaojunxiang2023 force-pushed the fix/snapshot-delete-orphan-job-list branch from 52de0c7 to 82c25af Compare June 25, 2026 15:30
Comment thread CubeMaster/pkg/templatecenter/snapshot_ops.go
Comment thread CubeMaster/pkg/templatecenter/snapshot_ops_test.go
@xiaojunxiang2023 xiaojunxiang2023 force-pushed the fix/snapshot-delete-orphan-job-list branch from 82c25af to f960975 Compare June 25, 2026 15:38
Comment thread CubeMaster/pkg/templatecenter/snapshot_ops.go
@xiaojunxiang2023 xiaojunxiang2023 force-pushed the fix/snapshot-delete-orphan-job-list branch 2 times, most recently from f9e1be3 to 5b0d15a Compare June 25, 2026 15:46
Comment thread CubeMaster/pkg/templatecenter/snapshot_ops.go Outdated
Comment thread CubeMaster/pkg/templatecenter/job_dto.go Outdated
Comment thread CubeMaster/pkg/templatecenter/snapshot_ops.go Outdated
@xiaojunxiang2023 xiaojunxiang2023 force-pushed the fix/snapshot-delete-orphan-job-list branch from 5b0d15a to 7ea0c4f Compare June 25, 2026 15:55
Comment thread CubeMaster/pkg/templatecenter/snapshot_ops.go
Comment thread CubeMaster/pkg/templatecenter/job_dto_test.go
@xiaojunxiang2023 xiaojunxiang2023 force-pushed the fix/snapshot-delete-orphan-job-list branch from 7ea0c4f to 085b5f1 Compare June 25, 2026 16:05
Comment thread CubeMaster/pkg/templatecenter/snapshot_ops.go
Comment thread CubeMaster/pkg/templatecenter/job_dto_test.go
Snapshot delete removed template_definition but left template_image_job
rows, so ListTemplates still surfaced deleted snapshots via orphan job
fallback. Mirror template delete by calling runTemplateJobCleanup after
metadata cleanup, and return a terminal READY job view without
re-querying deleted rows.

Signed-off-by: xiaojunxiang <xiaojunxiang@kingsoft.com>
@xiaojunxiang2023 xiaojunxiang2023 force-pushed the fix/snapshot-delete-orphan-job-list branch from 085b5f1 to 5a8e857 Compare June 26, 2026 00:24
Comment thread CubeMaster/pkg/templatecenter/job_dto_test.go
Comment thread CubeMaster/pkg/templatecenter/snapshot_ops_test.go
@kinwin-ustc kinwin-ustc merged commit 34fc237 into TencentCloud:master Jun 27, 2026
13 of 17 checks passed
zyl1121 pushed a commit to zyl1121/CubeSandbox that referenced this pull request Jul 2, 2026
…ud#559)

Snapshot delete removed template_definition but left template_image_job
rows, so ListTemplates still surfaced deleted snapshots via orphan job
fallback. Mirror template delete by calling runTemplateJobCleanup after
metadata cleanup, and return a terminal READY job view without
re-querying deleted rows.

Signed-off-by: xiaojunxiang <xiaojunxiang@kingsoft.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.

3 participants