MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / TaskStatusOverNetwork

Function TaskStatusOverNetwork

worker/queue.go:30–66  ·  view source on GitHub ↗

TaskStatusOverNetwork fetches the status of a task over the network. Alphas only know about the tasks created by them, but this function would fetch the task from the correct Alpha.

(ctx context.Context, req *pb.TaskStatusRequest,
)

Source from the content-addressed store, hash-verified

28// TaskStatusOverNetwork fetches the status of a task over the network. Alphas only know about the
29// tasks created by them, but this function would fetch the task from the correct Alpha.
30func TaskStatusOverNetwork(ctx context.Context, req *pb.TaskStatusRequest,
31) (*pb.TaskStatusResponse, error) {
32 // Extract Raft ID from Task ID.
33 taskId := req.GetTaskId()
34 if taskId == 0 {
35 return nil, fmt.Errorf("invalid task ID: %#x", taskId)
36 }
37 raftId := taskId >> 32
38
39 // Skip the network call if the required Alpha is me.
40 myRaftId := State.WALstore.Uint(raftwal.RaftId)
41 if raftId == myRaftId {
42 worker := (*grpcWorker)(nil)
43 return worker.TaskStatus(ctx, req)
44 }
45
46 // Find the Alpha with the required Raft ID.
47 var addr string
48 for _, group := range groups().state.GetGroups() {
49 for _, member := range group.GetMembers() {
50 if member.GetId() == raftId {
51 addr = member.GetAddr()
52 }
53 }
54 }
55 if addr == "" {
56 return nil, fmt.Errorf("the Alpha that served that task is not available")
57 }
58
59 // Send the request to the Alpha.
60 pool, err := conn.GetPools().Get(addr)
61 if err != nil {
62 return nil, errors.Wrapf(err, "unable to reach the Alpha that served that task")
63 }
64 client := pb.NewWorkerClient(pool.Get())
65 return client.TaskStatus(ctx, req)
66}
67
68// TaskStatus retrieves metadata for a given task ID.
69func (*grpcWorker) TaskStatus(ctx context.Context, req *pb.TaskStatusRequest,

Callers 1

resolveTaskFunction · 0.92

Calls 12

TaskStatusMethod · 0.95
GetPoolsFunction · 0.92
NewWorkerClientFunction · 0.92
groupsFunction · 0.85
GetTaskIdMethod · 0.80
GetGroupsMethod · 0.80
GetMembersMethod · 0.80
GetMethod · 0.65
ErrorfMethod · 0.45
UintMethod · 0.45
GetIdMethod · 0.45
GetAddrMethod · 0.45

Tested by

no test coverage detected