Refactor snapshot parent updates: replace full metadata reload with UpdateSnapshotParentID method, enhance functional test logging, and add CleanOnRestore option.

This commit is contained in:
2025-07-07 21:04:34 +03:00
parent 223a63ee6d
commit 8fe593bb6f
4 changed files with 46 additions and 16 deletions

View File

@ -207,18 +207,8 @@ func (data *SnapshotManagerData) DeleteSnapshot(ctx context.Context, snapshotID
// Update parent references for any snapshots that have this one as a parent
for _, info := range allSnapshots {
if info.ParentID == snapshotID {
// Get the full snapshot details
childSnapshot, err := data.metadataStore.GetSnapshotMetadata(ctx, info.ID)
if err != nil {
data.logger.Printf("WARNING: failed to get child snapshot %s details: %v", info.ID, err)
continue
}
// Update the parent ID to point to the deleted snapshot's parent
childSnapshot.ParentID = parentID
// Save the updated snapshot
if err := data.metadataStore.SaveSnapshotMetadata(ctx, *childSnapshot); err != nil {
// Используем новый, более надежный метод для обновления только parent_id
if err := data.metadataStore.UpdateSnapshotParentID(ctx, info.ID, parentID); err != nil {
data.logger.Printf("WARNING: failed to update parent reference for snapshot %s: %v", info.ID, err)
} else {
data.logger.Printf("Updated parent reference for snapshot %s from %s to %s", info.ID, snapshotID, parentID)