Skip to content

Commit

Permalink
fix(Dgraph): Forward task status requests to correct Alpha (#7774)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajeetdsouza authored May 5, 2021
1 parent 6b188f2 commit 60bec16
Show file tree
Hide file tree
Showing 10 changed files with 854 additions and 435 deletions.
4 changes: 2 additions & 2 deletions graphql/admin/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ func resolveBackup(ctx context.Context, m schema.Mutation) (*resolve.Resolved, b
return resolve.EmptyResult(m, err), false
}

msg := fmt.Sprintf("Backup queued with ID %s", taskId)
msg := fmt.Sprintf("Backup queued with ID %#x", taskId)
data := response("Success", msg)
data["taskId"] = taskId
data["taskId"] = fmt.Sprintf("%#x", taskId)
return resolve.DataResult(
m,
map[string]interface{}{m.Name(): data},
Expand Down
4 changes: 2 additions & 2 deletions graphql/admin/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ func resolveExport(ctx context.Context, m schema.Mutation) (*resolve.Resolved, b
return resolve.EmptyResult(m, err), false
}

msg := fmt.Sprintf("Export queued with ID %s", taskId)
msg := fmt.Sprintf("Export queued with ID %#x", taskId)
data := response("Success", msg)
data["taskId"] = taskId
data["taskId"] = fmt.Sprintf("%#x", taskId)
return resolve.DataResult(
m,
map[string]interface{}{m.Name(): data},
Expand Down
14 changes: 13 additions & 1 deletion graphql/admin/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,42 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"
"time"

"github.com/dgraph-io/dgraph/graphql/resolve"
"github.com/dgraph-io/dgraph/graphql/schema"
"github.com/dgraph-io/dgraph/protos/pb"
"github.com/dgraph-io/dgraph/worker"
"github.com/pkg/errors"
)

type taskInput struct {
Id string
}

func resolveTask(ctx context.Context, q schema.Query) *resolve.Resolved {
// Get Task ID.
input, err := getTaskInput(q)
if err != nil {
return resolve.EmptyResult(q, err)
}
if input.Id == "" {
return resolve.EmptyResult(q, fmt.Errorf("task ID is missing"))
}
taskId, err := strconv.ParseUint(input.Id, 0, 64)
if err != nil {
err = errors.Wrapf(err, "invalid task ID: %s", input.Id)
return resolve.EmptyResult(q, err)
}

meta, err := worker.Tasks.Get(input.Id)
// Get TaskMeta from network.
req := &pb.TaskStatusRequest{TaskId: taskId}
resp, err := worker.TaskStatusOverNetwork(context.Background(), req)
if err != nil {
return resolve.EmptyResult(q, err)
}
meta := worker.TaskMeta(resp.GetTaskMeta())
return resolve.DataResult(
q,
map[string]interface{}{q.Name(): map[string]interface{}{
Expand Down
9 changes: 9 additions & 0 deletions protos/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ service Worker {
rpc UpdateGraphQLSchema(UpdateGraphQLSchemaRequest)
returns (UpdateGraphQLSchemaResponse) {}
rpc DeleteNamespace(DeleteNsRequest) returns (Status) {}
rpc TaskStatus(TaskStatusRequest) returns (TaskStatusResponse) {}
}

message SubscriptionRequest {
Expand Down Expand Up @@ -756,4 +757,12 @@ message DeleteNsRequest {
uint64 namespace = 2;
}

message TaskStatusRequest {
uint64 task_id = 1;
}

message TaskStatusResponse {
uint64 task_meta = 1;
}

// vim: expandtab sw=2 ts=2
1,006 changes: 677 additions & 329 deletions protos/pb/pb.pb.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions testutil/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func WaitForTask(t *testing.T, taskId string, useHttps bool) {
require.NoError(t, err)

for {
time.Sleep(4 * time.Second)

var adminUrl string
var client http.Client
if useHttps {
Expand All @@ -95,8 +97,6 @@ func WaitForTask(t *testing.T, taskId string, useHttps bool) {
case "Failed", "Unknown":
t.Errorf("task failed with status: %s", status)
}

time.Sleep(4 * time.Second)
}
}

Expand Down
7 changes: 0 additions & 7 deletions worker/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ import (
"github.com/dgraph-io/dgraph/x"
)

const (
unknownStatus = "UNKNOWN"
inProgressStatus = "IN_PROGRESS"
okStatus = "OK"
errStatus = "ERR"
)

// predicateSet is a map whose keys are predicates. It is meant to be used as a set.
type predicateSet map[string]struct{}

Expand Down
2 changes: 1 addition & 1 deletion worker/backup_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func getFilteredManifests(h x.UriHandler, manifests []*Manifest,
var validManifests []*Manifest
for _, m := range manifests {
missingFiles := false
for g, _ := range m.Groups {
for g := range m.Groups {
path := filepath.Join(m.Path, backupName(m.Since, g))
if !h.FileExists(path) {
missingFiles = true
Expand Down
Loading

0 comments on commit 60bec16

Please sign in to comment.