Skip to content

Commit

Permalink
fix(restore): Handle MaxUid=0 appropriately (#7258)
Browse files Browse the repository at this point in the history
At the end of the restore operation we update the MaxUid in zero. This
MaxUid can be zero if the backup was created from an empty DB.

(cherry picked from commit b05fb93)
  • Loading branch information
Ibrahim Jarif committed Jan 8, 2021
1 parent fae97ec commit 5ab0489
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions ee/backup/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ package backup
import (
"context"
"fmt"
"google.golang.org/grpc/credentials"
"os"
"time"

"google.golang.org/grpc/credentials"

"github.com/dgraph-io/dgraph/ee/enc"
"github.com/dgraph-io/dgraph/protos/pb"
"github.com/dgraph-io/dgraph/worker"
Expand Down Expand Up @@ -236,19 +237,19 @@ func runRestoreCmd() error {
ctx, cancelTs := context.WithTimeout(context.Background(), time.Minute)
defer cancelTs()

_, err := zc.Timestamps(ctx, &pb.Num{Val: result.Version})
if err != nil {
if _, err := zc.Timestamps(ctx, &pb.Num{Val: result.Version}); err != nil {
fmt.Printf("Failed to assign timestamp %d in Zero: %v", result.Version, err)
return err
}

ctx, cancelUid := context.WithTimeout(context.Background(), time.Minute)
defer cancelUid()

_, err = zc.AssignUids(ctx, &pb.Num{Val: result.MaxLeaseUid})
if err != nil {
fmt.Printf("Failed to assign maxLeaseId %d in Zero: %v\n", result.MaxLeaseUid, err)
return err
// MaxLeaseUid can be zero if the backup was taken on an empty DB.
if result.MaxLeaseUid > 0 {
ctx, cancelUid := context.WithTimeout(context.Background(), time.Minute)
defer cancelUid()
if _, err = zc.AssignUids(ctx, &pb.Num{Val: result.MaxLeaseUid}); err != nil {
fmt.Printf("Failed to assign maxLeaseId %d in Zero: %v\n", result.MaxLeaseUid, err)
return err
}
}
}

Expand Down

0 comments on commit 5ab0489

Please sign in to comment.