Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PBM-1341] retry shutdown on ConflictingOperationInProgress #979

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions pbm/restore/physical.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const (

tryConnCount = 5
tryConnTimeout = 5 * time.Minute

maxShutdownTriesOnStandaloneRecovery = 10
)

type files struct {
Expand Down Expand Up @@ -1259,7 +1261,17 @@ func (r *PhysRestore) prepareData() error {
}

func shutdown(c *mongo.Client, dbpath string) error {
err := c.Database("admin").RunCommand(context.TODO(), bson.D{{"shutdown", 1}}).Err()
return shutdownImpl(c, dbpath, false)
}

func forceShutdown(c *mongo.Client, dbpath string) error {
return shutdownImpl(c, dbpath, true)
}

func shutdownImpl(c *mongo.Client, dbpath string, force bool) error {
res := c.Database("admin").RunCommand(context.TODO(),
bson.D{{"shutdown", 1}, {"force", force}})
err := res.Err()
if err != nil && !strings.Contains(err.Error(), "socket was unexpectedly closed") {
return err
}
Expand All @@ -1285,12 +1297,24 @@ func (r *PhysRestore) recoverStandalone() error {
return errors.Wrap(err, "connect to mongo")
}

err = shutdown(c, r.dbpath)
if err != nil {
return errors.Wrap(err, "shutdown mongo")
for i := 0; i != maxShutdownTriesOnStandaloneRecovery; i++ {
err = shutdown(c, r.dbpath)
if err == nil {
return nil // OK
}

if strings.Contains(err.Error(), "ConflictingOperationInProgress") {
r.log.Warning("retry shutdown in 5 seconds. reason: %v", err)
time.Sleep(5 * time.Second)
continue
}

return errors.Wrap(err, "shutdown mongo") // unexpected
}

return nil
r.log.Debug("force shutdown")
err = forceShutdown(c, r.dbpath)
return errors.Wrap(err, "force shutdown mongo")
}

func (r *PhysRestore) replayOplog(
Expand Down
Loading