Skip to content

Commit

Permalink
[PBM-1151] handle error
Browse files Browse the repository at this point in the history
  • Loading branch information
defbin committed Jul 17, 2023
1 parent 4ed2332 commit 8ebd2e7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pbm/backup/physical.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ func NewBackupCursor(n *pbm.Node, l *plog.Event, opts bson.D) *BackupCursor {
}
}

func (bc *BackupCursor) create(ctx context.Context, retry int) (cur *mongo.Cursor, err error) {
var triesLimitExceededErr = errors.New("tries limit exceeded")

func (bc *BackupCursor) create(ctx context.Context, retry int) (*mongo.Cursor, error) {
for i := 0; i < retry; i++ {
cur, err = bc.n.Session().Database("admin").Aggregate(ctx, mongo.Pipeline{
cur, err := bc.n.Session().Database("admin").Aggregate(ctx, mongo.Pipeline{
{{"$backupCursor", bc.opts}},
})
if err != nil {
Expand All @@ -74,14 +76,14 @@ func (bc *BackupCursor) create(ctx context.Context, retry int) (cur *mongo.Curso
time.Sleep(time.Second * time.Duration(i+1))
continue
}
} else if err != nil {

return nil, err
}

return cur, nil
}

return cur, err
return nil, triesLimitExceededErr
}

func (bc *BackupCursor) Data(ctx context.Context) (bcp *BackupCursorData, err error) {
Expand Down

0 comments on commit 8ebd2e7

Please sign in to comment.