Skip to content

Commit

Permalink
fix(restore): reset acl accounts once restore is done if necessary (#…
Browse files Browse the repository at this point in the history
…7202)

* reset acl accounts once restore is done if necessary

* handling restores with wait group

* making wg to work with each proposal
  • Loading branch information
aman-bansal authored Jan 5, 2021
1 parent 1088d30 commit 5a1d0b4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
12 changes: 11 additions & 1 deletion graphql/admin/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -66,7 +69,9 @@ func resolveRestore(ctx context.Context, m schema.Mutation) (*resolve.Resolved,
VaultField: input.VaultField,
VaultFormat: input.VaultFormat,
}
err = worker.ProcessRestoreRequest(context.Background(), &req)

wg := &sync.WaitGroup{}
err = worker.ProcessRestoreRequest(context.Background(), &req, wg)
if err != nil {
return &resolve.Resolved{
Data: map[string]interface{}{m.Name(): map[string]interface{}{
Expand All @@ -77,6 +82,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",
Expand Down
5 changes: 3 additions & 2 deletions worker/online_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ 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) error {
func ProcessRestoreRequest(ctx context.Context, req *pb.RestoreRequest, wg *sync.WaitGroup) error {
glog.Warningf("Restore failed: %v", x.ErrNotSupported)
return x.ErrNotSupported
}
Expand All @@ -39,4 +40,4 @@ func (w *grpcWorker) Restore(ctx context.Context, req *pb.RestoreRequest) (*pb.S

func handleRestoreProposal(ctx context.Context, req *pb.RestoreRequest) error {
return nil
}
}
11 changes: 7 additions & 4 deletions worker/online_restore_ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -38,7 +40,7 @@ const (
)

// ProcessRestoreRequest verifies the backup data and sends a restore proposal to each group.
func ProcessRestoreRequest(ctx context.Context, req *pb.RestoreRequest) error {
func ProcessRestoreRequest(ctx context.Context, req *pb.RestoreRequest, wg *sync.WaitGroup) error {
if req == nil {
return errors.Errorf("restore request cannot be nil")
}
Expand Down Expand Up @@ -95,7 +97,7 @@ func ProcessRestoreRequest(ctx context.Context, req *pb.RestoreRequest) error {
for _, gid := range currentGroups {
reqCopy := proto.Clone(req).(*pb.RestoreRequest)
reqCopy.GroupId = gid

wg.Add(1)
go func() {
errCh <- tryRestoreProposal(ctx, reqCopy)
}()
Expand All @@ -106,6 +108,7 @@ func ProcessRestoreRequest(ctx context.Context, req *pb.RestoreRequest) error {
if err := <-errCh; err != nil {
glog.Errorf("Error while restoring %v", err)
}
wg.Done()
}
}()

Expand Down Expand Up @@ -363,4 +366,4 @@ func writeBackup(ctx context.Context, req *pb.RestoreRequest) error {
return errors.Wrapf(res.Err, "cannot write backup")
}
return nil
}
}

0 comments on commit 5a1d0b4

Please sign in to comment.