Skip to content

Commit 623d2c4

Browse files
committed
Fix applying fallback and cleaning up procedure
1 parent f2ce7ad commit 623d2c4

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

pbm/restore/physical.go

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,26 +234,33 @@ func (r *PhysRestore) close(noerr, cleanup bool) {
234234
if err != nil && !errors.Is(err, os.ErrNotExist) {
235235
r.log.Warning("remove file <%s>: %v", backup.FilelistName, err)
236236
}
237-
} else if cleanup { // clean-up dbpath on err if needed
238-
r.log.Debug("wait for cluster status")
239-
cStatus, err := r.waitClusterStatus()
237+
}
238+
239+
r.log.Debug("wait for cluster status")
240+
cStatus, err := r.waitClusterStatus()
241+
if err != nil {
242+
r.log.Warning("waiting for cluster status during cleanup: %v", err)
243+
}
244+
if cStatus == defs.StatusError {
245+
r.log.Warning("apply db data from %s", fallbackDir)
246+
err := r.migrateFromFallbackDirToDBDir()
240247
if err != nil {
241-
r.log.Warning("waiting for cluster status during cleanup: %v", err)
248+
r.log.Error("migrate from fallback dir: %v", err)
242249
}
243-
244-
if cStatus == defs.StatusError {
245-
err := r.migrateFromFallbackDirToDBDir()
246-
if err != nil {
247-
r.log.Error("migrate from fallback dir: %v", err)
248-
}
249-
} else { // cluster status is done or partlyDone
250-
r.log.Debug("clean-up dbpath")
251-
err := removeAll(r.dbpath, nil, r.log)
252-
if err != nil {
253-
r.log.Error("flush dbpath %s: %v", r.dbpath, err)
254-
}
250+
} else if cleanup { // clean-up dbpath on err if needed (cluster is done or partlyDone)
251+
r.log.Debug("clean-up dbpath")
252+
err := removeAll(r.dbpath, nil, r.log)
253+
if err != nil {
254+
r.log.Error("flush dbpath %s: %v", r.dbpath, err)
255+
}
256+
} else { // free space by just deleting fallback dir in any other case
257+
r.log.Debug("remove fallback dir")
258+
err := r.removeFallback()
259+
if err != nil {
260+
r.log.Error("flush fallback: %v", err)
255261
}
256262
}
263+
257264
if r.stopHB != nil {
258265
close(r.stopHB)
259266
}
@@ -428,6 +435,14 @@ func (r *PhysRestore) moveToFallback() error {
428435
)
429436
}
430437

438+
// removeFallback removes fallback dir
439+
func (r *PhysRestore) removeFallback() error {
440+
dbpath := filepath.Clean(r.dbpath)
441+
fallbackPath := filepath.Join(dbpath, fallbackDir)
442+
err := os.RemoveAll(fallbackPath)
443+
return errors.Wrap(err, "remove fallback db path")
444+
}
445+
431446
func nodeShutdown(ctx context.Context, m *mongo.Client) error {
432447
err := m.Database("admin").RunCommand(ctx, bson.D{{"shutdown", 1}}).Err()
433448
if err == nil || strings.Contains(err.Error(), "socket was unexpectedly closed") {

0 commit comments

Comments
 (0)