SortOverNetwork sends sort query over the network.
(ctx context.Context, q *pb.SortMessage)
| 46 | |
| 47 | // SortOverNetwork sends sort query over the network. |
| 48 | func 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. |
| 89 | func (w *grpcWorker) Sort(ctx context.Context, s *pb.SortMessage) (*pb.SortResult, error) { |
no test coverage detected