From ea15b664aa8659c0722e31a499c598698377215f Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Wed, 19 Aug 2020 10:59:38 -0700 Subject: [PATCH] fix(Dgraph): make backups cancel other tasks (#6152) Backups should be added to the list of tasks (rollups, snapshots, etc) that are managed by Dgraph so that rollups and other tasks are paused during the backup. --- worker/backup_ee.go | 5 +++++ worker/draft.go | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/worker/backup_ee.go b/worker/backup_ee.go index b39e7979ae9..e6328faf4af 100644 --- a/worker/backup_ee.go +++ b/worker/backup_ee.go @@ -50,6 +50,11 @@ func backupCurrentGroup(ctx context.Context, req *pb.BackupRequest) (*pb.Status, return nil, err } + closer, err := g.Node.startTask(opBackup) + if err != nil { + return nil, errors.Wrapf(err, "cannot start backup operation") + } + defer closer.Done() bp := NewBackupProcessor(pstore, req) return bp.WriteBackup(ctx) } diff --git a/worker/draft.go b/worker/draft.go index 59d906be699..8156790414f 100644 --- a/worker/draft.go +++ b/worker/draft.go @@ -86,6 +86,8 @@ func (id op) String() string { return "opIndexing" case opRestore: return "opRestore" + case opBackup: + return "opBackup" default: return "opUnknown" } @@ -96,6 +98,7 @@ const ( opSnapshot opIndexing opRestore + opBackup ) // startTask is used to check whether an op is already running. If a rollup is running, @@ -141,6 +144,17 @@ func (n *node) startTask(id op) (*y.Closer, error) { delete(n.ops, otherId) otherCloser.SignalAndWait() } + case opBackup: + // Backup cancels all other operations, except for other backups since + // only one restore operation should be active any given moment. + for otherId, otherCloser := range n.ops { + if otherId == opBackup { + return nil, errors.Errorf("another backup operation is already running") + } + // Remove from map and signal the closer to cancel the operation. + delete(n.ops, otherId) + otherCloser.SignalAndWait() + } case opSnapshot, opIndexing: for otherId, otherCloser := range n.ops { if otherId == opRollup {