From 5b7926018adc5ed2173d0df5b1ac5796517566ed Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Mon, 31 Aug 2020 13:04:23 -0700 Subject: [PATCH] Fix(Dgraph): Add a lock to backups to process one request at a time. (#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 --- worker/backup_ee.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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)