Skip to content

Commit

Permalink
fix(Dgraph): make backups cancel other tasks (#6152)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
martinmr authored Aug 19, 2020
1 parent 67a221a commit ea15b66
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions worker/backup_ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 14 additions & 0 deletions worker/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ func (id op) String() string {
return "opIndexing"
case opRestore:
return "opRestore"
case opBackup:
return "opBackup"
default:
return "opUnknown"
}
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ea15b66

Please sign in to comment.