Skip to content

Commit

Permalink
[PBM-1173] avoid collection drop. delete all docs (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
defbin authored Sep 8, 2023
1 parent d21f1de commit dae0235
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pbm/restore/physical.go
Original file line number Diff line number Diff line change
Expand Up @@ -1169,15 +1169,15 @@ func (r *PhysRestore) prepareData() error {

ctx := context.Background()

err = c.Database("local").Collection("replset.minvalid").Drop(ctx)
_, err = c.Database("local").Collection("replset.minvalid").DeleteMany(ctx, bson.D{})
if err != nil {
return errors.Wrap(err, "drop replset.minvalid")
}
err = c.Database("local").Collection("replset.oplogTruncateAfterPoint").Drop(ctx)
_, err = c.Database("local").Collection("replset.oplogTruncateAfterPoint").DeleteMany(ctx, bson.D{})
if err != nil {
return errors.Wrap(err, "drop replset.oplogTruncateAfterPoint")
}
err = c.Database("local").Collection("replset.election").Drop(ctx)
_, err = c.Database("local").Collection("replset.election").DeleteMany(ctx, bson.D{})
if err != nil {
return errors.Wrap(err, "drop replset.election")
}
Expand Down Expand Up @@ -1360,11 +1360,11 @@ func (r *PhysRestore) resetRS() error {
ctx := context.Background()

if r.nodeInfo.IsConfigSrv() {
err = c.Database("config").Collection("mongos").Drop(ctx)
_, err = c.Database("config").Collection("mongos").DeleteMany(ctx, bson.D{})
if err != nil {
return errors.Wrap(err, "drop config.mongos")
}
err = c.Database("config").Collection("lockpings").Drop(ctx)
_, err = c.Database("config").Collection("lockpings").DeleteMany(ctx, bson.D{})
if err != nil {
return errors.Wrap(err, "drop config.lockpings")
}
Expand Down Expand Up @@ -1431,14 +1431,15 @@ func (r *PhysRestore) resetRS() error {
return errors.WithMessage(err, "list cache collections")
}
for _, coll := range colls {
if err := c.Database("config").Collection(coll).Drop(ctx); err != nil {
_, err := c.Database("config").Collection(coll).DeleteMany(ctx, bson.D{})
if err != nil {
return errors.Wrapf(err, "drop %q", coll)
}
}

const retry = 5
for i := 0; i < retry; i++ {
err = c.Database("config").Collection("system.sessions").Drop(ctx)
_, err = c.Database("config").Collection("system.sessions").DeleteMany(ctx, bson.D{})
if err == nil || !strings.Contains(err.Error(), "(BackgroundOperationInProgressForNamespace)") {
break
}
Expand Down

0 comments on commit dae0235

Please sign in to comment.