diff --git a/graphql/admin/restore.go b/graphql/admin/restore.go index 90df7973d96..5ecb185fdcb 100644 --- a/graphql/admin/restore.go +++ b/graphql/admin/restore.go @@ -19,6 +19,9 @@ package admin import ( "context" "encoding/json" + "sync" + + "github.com/dgraph-io/dgraph/edgraph" "github.com/dgraph-io/dgraph/graphql/resolve" "github.com/dgraph-io/dgraph/graphql/schema" @@ -66,7 +69,9 @@ func resolveRestore(ctx context.Context, m schema.Mutation) (*resolve.Resolved, VaultField: input.VaultField, VaultFormat: input.VaultFormat, } - restoreId, err := worker.ProcessRestoreRequest(context.Background(), &req) + + wg := &sync.WaitGroup{} + restoreId, err := worker.ProcessRestoreRequest(context.Background(), &req, wg) if err != nil { worker.DeleteRestoreId(restoreId) return &resolve.Resolved{ @@ -78,6 +83,11 @@ func resolveRestore(ctx context.Context, m schema.Mutation) (*resolve.Resolved, }, false } + go func() { + wg.Wait() + edgraph.ResetAcl(nil) + }() + return &resolve.Resolved{ Data: map[string]interface{}{m.Name(): map[string]interface{}{ "code": "Success", diff --git a/worker/online_restore.go b/worker/online_restore.go index 7bf1ef9c909..f329ae31d92 100644 --- a/worker/online_restore.go +++ b/worker/online_restore.go @@ -20,13 +20,15 @@ package worker import ( "context" + "sync" "github.com/dgraph-io/dgraph/protos/pb" "github.com/dgraph-io/dgraph/x" "github.com/golang/glog" ) -func ProcessRestoreRequest(ctx context.Context, req *pb.RestoreRequest) (int, error) { +func ProcessRestoreRequest(ctx context.Context, req *pb.RestoreRequest, + wg *sync.WaitGroup) (int, error) { glog.Warningf("Restore failed: %v", x.ErrNotSupported) return 0, x.ErrNotSupported } diff --git a/worker/online_restore_ee.go b/worker/online_restore_ee.go index 77f4c6985d6..ca8a2410db2 100644 --- a/worker/online_restore_ee.go +++ b/worker/online_restore_ee.go @@ -18,15 +18,17 @@ import ( "io" "net/url" "strings" + "sync" "time" + "github.com/golang/glog" + "github.com/dgraph-io/dgraph/conn" "github.com/dgraph-io/dgraph/ee/enc" "github.com/dgraph-io/dgraph/posting" "github.com/dgraph-io/dgraph/protos/pb" "github.com/dgraph-io/dgraph/schema" - "github.com/golang/glog" "github.com/golang/protobuf/proto" "github.com/pkg/errors" "github.com/spf13/pflag" @@ -38,7 +40,8 @@ const ( ) // ProcessRestoreRequest verifies the backup data and sends a restore proposal to each group. -func ProcessRestoreRequest(ctx context.Context, req *pb.RestoreRequest) (int, error) { +func ProcessRestoreRequest(ctx context.Context, req *pb.RestoreRequest, + wg *sync.WaitGroup) (int, error) { if req == nil { return 0, errors.Errorf("restore request cannot be nil") } @@ -102,7 +105,7 @@ func ProcessRestoreRequest(ctx context.Context, req *pb.RestoreRequest) (int, er for _, gid := range currentGroups { reqCopy := proto.Clone(req).(*pb.RestoreRequest) reqCopy.GroupId = gid - + wg.Add(1) go func() { errCh <- tryRestoreProposal(ctx, reqCopy) }() @@ -114,6 +117,7 @@ func ProcessRestoreRequest(ctx context.Context, req *pb.RestoreRequest) (int, er if err := <-errCh; err != nil { errs = append(errs, err) } + wg.Done() } if err := rt.Done(restoreId, errs); err != nil { glog.Warningf("Could not mark restore operation with ID %d as done. Error: %s",