Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6f0fc48

Browse files
Merge branch '625-traverse-on-branch-delete' into 'dle-4-0'
fix: traversing the tree of snapshots in both directions (up and down) when deleting a branch (#625) See merge request postgres-ai/database-lab!1032
2 parents b31ca19 + d10beff commit 6f0fc48

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

‎engine/internal/srv/branch.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,8 @@ func (s *Server) deleteBranch(w http.ResponseWriter, r *http.Request) {
551551

552552
toRemove := snapshotsToRemove(repo, snapshotID, branchName)
553553

554+
log.Dbg("Snapshots to remove", toRemove)
555+
554556
if len(toRemove) > 0 {
555557
// Pre-check.
556558
preCheckList := make(map[string]int)
@@ -618,18 +620,26 @@ func cleanupSnapshotProperties(repo *models.Repo, fsm pool.FSManager, branchName
618620
}
619621

620622
func snapshotsToRemove(repo *models.Repo, snapshotID, branchName string) []string {
623+
removingList := []string{}
624+
625+
// Traverse up the snapshot tree
626+
removingList = append(removingList, traverseUp(repo, snapshotID, branchName)...)
627+
628+
// Traverse down the snapshot tree
629+
removingList = append(removingList, traverseDown(repo, snapshotID)...)
630+
631+
return removingList
632+
}
633+
634+
func traverseUp(repo *models.Repo, snapshotID, branchName string) []string {
621635
snapshotPointer := repo.Snapshots[snapshotID]
622636

623637
removingList := []string{}
624638

625639
for snapshotPointer.Parent != "-" {
626-
if len(snapshotPointer.Root) > 0 {
627-
break
628-
}
629-
630640
for _, snapshotRoot := range snapshotPointer.Root {
631641
if snapshotRoot == branchName {
632-
break
642+
returnremovingList
633643
}
634644
}
635645

@@ -640,6 +650,19 @@ func snapshotsToRemove(repo *models.Repo, snapshotID, branchName string) []strin
640650
return removingList
641651
}
642652

653+
func traverseDown(repo *models.Repo, snapshotID string) []string {
654+
snapshotPointer := repo.Snapshots[snapshotID]
655+
656+
removingList := []string{}
657+
658+
for _, snapshotChild := range snapshotPointer.Child {
659+
removingList = append(removingList, snapshotChild)
660+
removingList = append(removingList, traverseDown(repo, snapshotChild)...)
661+
}
662+
663+
return removingList
664+
}
665+
643666
func (s *Server) destroyBranchDataset(fsm pool.FSManager, branchName string) error {
644667
branchDatasetName := fsm.Pool().BranchName(fsm.Pool().Name, branchName)
645668

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /