MCPcopy
hub / github.com/dgraph-io/dgraph / SortOverNetwork

Function SortOverNetwork

worker/sort.go:48–86  ·  view source on GitHub ↗

SortOverNetwork sends sort query over the network.

(ctx context.Context, q *pb.SortMessage)

Source from the content-addressed store, hash-verified

46
47// SortOverNetwork sends sort query over the network.
48func SortOverNetwork(ctx context.Context, q *pb.SortMessage) (*pb.SortResult, error) {
49 gid, err := groups().BelongsToReadOnly(q.Order[0].Attr, q.ReadTs)
50 if err != nil {
51 return &emptySortResult, err
52 } else if gid == 0 {
53 return &emptySortResult,
54 errors.Errorf("Cannot sort by unknown attribute %s", x.ParseAttr(q.Order[0].Attr))
55 }
56
57 if span := trace.SpanFromContext(ctx); span != nil {
58 span.SetAttributes(
59 attribute.String("attribute", q.Order[0].Attr),
60 attribute.Int("groupId", int(gid)),
61 )
62 }
63
64 if groups().ServesGroup(gid) {
65 // No need for a network call, as this should be run from within this instance.
66 return processSort(ctx, q)
67 }
68
69 // Add span for cross-alpha network call
70 ctx, networkSpan := otel.Tracer("").Start(ctx, "SortOverNetwork.RemoteCall")
71 networkSpan.SetAttributes(
72 attribute.String("target_group", fmt.Sprintf("%d", gid)),
73 attribute.String("attr", x.SafeUTF8(q.Order[0].Attr)),
74 attribute.Bool("is_remote", true),
75 )
76
77 result, err := processWithBackupRequest(
78 ctx, gid, func(ctx context.Context, c pb.WorkerClient) (interface{}, error) {
79 return c.Sort(ctx, q)
80 })
81 networkSpan.End()
82 if err != nil {
83 return &emptySortResult, err
84 }
85 return result.(*pb.SortResult), nil
86}
87
88// Sort is used to sort given UID matrix.
89func (w *grpcWorker) Sort(ctx context.Context, s *pb.SortMessage) (*pb.SortResult, error) {

Callers 1

Calls 11

ParseAttrFunction · 0.92
SafeUTF8Function · 0.92
groupsFunction · 0.85
processSortFunction · 0.85
processWithBackupRequestFunction · 0.85
BelongsToReadOnlyMethod · 0.80
ServesGroupMethod · 0.80
StartMethod · 0.65
SortMethod · 0.65
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected