Skip to content

Commit 86e8b82

Browse files
committed
Merge branch '309-empty-snapshot' into 'master'
fix: prevent panics if a clone snapshot has been deleted manually (#309) See merge request postgres-ai/database-lab!399
2 parents 17e62d1 + 385e5cb commit 86e8b82

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

Diff for: internal/cloning/base.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,10 @@ func (c *Base) DestroyClone(cloneID string) error {
306306
}
307307

308308
c.deleteClone(cloneID)
309-
c.decrementCloneNumber(w.Clone.Snapshot.ID)
309+
310+
if w.Clone.Snapshot != nil {
311+
c.decrementCloneNumber(w.Clone.Snapshot.ID)
312+
}
310313
c.observingCh <- cloneID
311314

312315
c.SaveClonesState()

Diff for: internal/cloning/snapshots.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ func (c *Base) fetchSnapshots() error {
3434
numClones := 0
3535

3636
for cloneName := range c.clones {
37-
if c.clones[cloneName] != nil && c.clones[cloneName].Clone.Snapshot.ID == entry.ID {
37+
if c.clones[cloneName] != nil && c.clones[cloneName].Clone.Snapshot != nil &&
38+
c.clones[cloneName].Clone.Snapshot.ID == entry.ID {
3839
numClones++
3940
}
4041
}

Diff for: internal/cloning/storage.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ func (c *Base) restartCloneContainers(ctx context.Context) {
6262

6363
if err := c.provision.ReconnectClone(ctx, cloneName); err != nil {
6464
log.Err(fmt.Sprintf("Clone container %s cannot be reconnected to the internal network: %s", cloneName, err))
65+
continue
6566
}
6667

6768
if err := c.provision.StartCloneContainer(ctx, cloneName); err != nil {
6869
log.Err(fmt.Sprintf("Clone container %s cannot start: %s", cloneName, err))
70+
continue
6971
}
7072

7173
log.Dbg(fmt.Sprintf("Clone container %s is running", cloneName))
@@ -79,7 +81,8 @@ func (c *Base) filterRunningClones(ctx context.Context) {
7981
snapshotCache := make(map[string]struct{})
8082

8183
for cloneID, wrapper := range c.clones {
82-
if wrapper.Clone == nil || wrapper.Session == nil || wrapper.Clone.Status.Code == models.StatusFatal {
84+
if wrapper.Clone == nil || wrapper.Clone.Snapshot == nil || wrapper.Session == nil ||
85+
wrapper.Clone.Status.Code == models.StatusFatal {
8386
delete(c.clones, cloneID)
8487
continue
8588
}

0 commit comments

Comments
 (0)