Skip to content

Commit

Permalink
Fix(Dgraph): Add a lock to backups to process one request at a time. (#…
Browse files Browse the repository at this point in the history
…6316)

It's possible that two requests reach the server around the same time
and send a requests to the alphas with the same backupNum. This could
lead to issues further down the line.

Related to DGRAPH-2295
  • Loading branch information
martinmr authored Aug 31, 2020
1 parent 501f338 commit 5b79260
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions worker/backup_ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"context"
"net/url"
"sort"
"sync"
"time"

"github.com/dgraph-io/dgraph/posting"
Expand Down Expand Up @@ -80,6 +81,11 @@ func BackupGroup(ctx context.Context, in *pb.BackupRequest) (*pb.Status, error)
return res, nil
}

// backupLock is used to synchronize backups to avoid more than one backup request
// to be processed at the same time. Multiple requests could lead to multiple
// backups with the same backupNum in their manifest.
var backupLock sync.Mutex

func ProcessBackupRequest(ctx context.Context, req *pb.BackupRequest, forceFull bool) error {
if !EnterpriseEnabled() {
return errors.New("you must enable enterprise features first. " +
Expand All @@ -95,6 +101,10 @@ func ProcessBackupRequest(ctx context.Context, req *pb.BackupRequest, forceFull
return err
}

// Grab the lock here to avoid more than one request to be processed at the same time.
backupLock.Lock()
defer backupLock.Unlock()

ts, err := Timestamps(ctx, &pb.Num{ReadOnly: true})
if err != nil {
glog.Errorf("Unable to retrieve readonly timestamp for backup: %s", err)
Expand Down

0 comments on commit 5b79260

Please sign in to comment.