diff --git a/worker/backup_ee.go b/worker/backup_ee.go index e6328faf4af..1e8801d62af 100644 --- a/worker/backup_ee.go +++ b/worker/backup_ee.go @@ -16,6 +16,7 @@ import ( "context" "net/url" "sort" + "sync" "time" "github.com/dgraph-io/dgraph/posting" @@ -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. " + @@ -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)