Skip to content

Commit d4e6ea9

Browse files
committed
Close physical restore storage
1 parent 1a61904 commit d4e6ea9

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

pbm/restore/physical.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ type PhysRestore struct {
120120

121121
stopHB chan struct{}
122122
stopCleanupHB chan struct{}
123+
hbWG sync.WaitGroup
123124

124125
log log.LogEvent
125126
logBuff *logBuff
@@ -212,6 +213,16 @@ func NewPhysical(
212213
}, nil
213214
}
214215

216+
func (r *PhysRestore) closeStoragesAfterHeartbeats() {
217+
r.hbWG.Wait()
218+
219+
storage.Close(r.bcpStg, r.log)
220+
r.bcpStg = nil
221+
222+
storage.Close(r.stg, r.log)
223+
r.stg = nil
224+
}
225+
215226
// peeks a random free port in a range [minPort, maxPort]
216227
func peekTmpPort(current int) (int, error) {
217228
const (
@@ -277,6 +288,7 @@ func (r *PhysRestore) close(noerr bool, progress nodeStatus) (err error) {
277288
if r.stopHB != nil {
278289
close(r.stopHB)
279290
}
291+
r.closeStoragesAfterHeartbeats()
280292
}()
281293

282294
// resolve and exec cleanup
@@ -2461,9 +2473,11 @@ func (r *PhysRestore) startHB(l log.LogEvent) {
24612473
}
24622474

24632475
r.stopHB = make(chan struct{})
2476+
r.hbWG.Add(1)
24642477
go func() {
24652478
tk := time.NewTicker(time.Second * hbFrameSec)
24662479
defer func() {
2480+
r.hbWG.Done()
24672481
tk.Stop()
24682482
r.stopHB = nil
24692483
l.Debug("heartbeats stopped")
@@ -2524,9 +2538,11 @@ func (r *PhysRestore) startCleanupHb() {
25242538
}
25252539

25262540
r.stopCleanupHB = make(chan struct{})
2541+
r.hbWG.Add(1)
25272542
go func() {
25282543
tk := time.NewTicker(hbCleanupFrame)
25292544
defer func() {
2545+
r.hbWG.Done()
25302546
tk.Stop()
25312547
r.stopCleanupHB = nil
25322548
r.log.Debug("cleanup heartbeats stopped")
@@ -3174,6 +3190,7 @@ func PhysRestoreFinish(l log.LogEvent, cmd *ExtFinishCmd) error {
31743190
if r.stopHB != nil {
31753191
close(r.stopHB)
31763192
}
3193+
r.closeStoragesAfterHeartbeats()
31773194
}()
31783195

31793196
excfg, err := r.prepareExtRestore(l)
@@ -3253,6 +3270,12 @@ func physRestoreFromExtDump(
32533270
if err != nil {
32543271
return nil, nil, errors.Wrap(err, "get storage")
32553272
}
3273+
closeStorage := true
3274+
defer func() {
3275+
if closeStorage {
3276+
storage.Close(stg, l)
3277+
}
3278+
}()
32563279

32573280
extDumpF := fmt.Sprintf("%s/%s/rs.%s/node.%s.%s",
32583281
defs.PhysRestoresDir, cmd.RestoreName, cmd.RS, cmd.Node, extDumpSuffix)
@@ -3307,6 +3330,7 @@ func physRestoreFromExtDump(
33073330
physRestore.secOpts = mongodCfg.Security
33083331
}
33093332

3333+
closeStorage = false
33103334
return &physRestore, restoreMeta, nil
33113335
}
33123336

0 commit comments

Comments
 (0)