Skip to content

Commit 5b79260

Browse files
authored
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
1 parent 501f338 commit 5b79260

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

worker/backup_ee.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"context"
1717
"net/url"
1818
"sort"
19+
"sync"
1920
"time"
2021

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

84+
// backupLock is used to synchronize backups to avoid more than one backup request
85+
// to be processed at the same time. Multiple requests could lead to multiple
86+
// backups with the same backupNum in their manifest.
87+
var backupLock sync.Mutex
88+
8389
func ProcessBackupRequest(ctx context.Context, req *pb.BackupRequest, forceFull bool) error {
8490
if !EnterpriseEnabled() {
8591
return errors.New("you must enable enterprise features first. " +
@@ -95,6 +101,10 @@ func ProcessBackupRequest(ctx context.Context, req *pb.BackupRequest, forceFull
95101
return err
96102
}
97103

104+
// Grab the lock here to avoid more than one request to be processed at the same time.
105+
backupLock.Lock()
106+
defer backupLock.Unlock()
107+
98108
ts, err := Timestamps(ctx, &pb.Num{ReadOnly: true})
99109
if err != nil {
100110
glog.Errorf("Unable to retrieve readonly timestamp for backup: %s", err)

0 commit comments

Comments
 (0)