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 committed Jan 12, 2021
1 parent 764ac49 commit ab54155
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 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,
}
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{
Expand All @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion worker/online_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 7 additions & 3 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,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")
}
Expand Down Expand Up @@ -74,7 +77,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)
}()
Expand All @@ -90,6 +93,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",
Expand Down

0 comments on commit ab54155

Please sign in to comment.