Skip to content

Commit bfa11da

Browse files
fixed comments
1 parent 8527b4a commit bfa11da

9 files changed

Lines changed: 142 additions & 269 deletions

File tree

edgraph/server.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -542,15 +542,11 @@ func (s *Server) Alter(ctx context.Context, op *api.Operation) (*api.Payload, er
542542
}
543543

544544
func annotateNamespace(span trace.Span, ns uint64) {
545-
if span.IsRecording() {
546-
span.SetAttributes(attribute.String("ns", fmt.Sprintf("%d", ns)))
547-
}
545+
span.SetAttributes(attribute.String("ns", fmt.Sprintf("%d", ns)))
548546
}
549547

550548
func annotateStartTs(span trace.Span, ts uint64) {
551-
if span.IsRecording() {
552-
span.SetAttributes(attribute.String("startTs", fmt.Sprintf("%d", ts)))
553-
}
549+
span.SetAttributes(attribute.String("startTs", fmt.Sprintf("%d", ts)))
554550
}
555551

556552
func (s *Server) doMutate(ctx context.Context, qc *queryContext, resp *api.Response) error {
@@ -1513,10 +1509,8 @@ func processQuery(ctx context.Context, qc *queryContext) (*api.Response, error)
15131509
if err != nil && (qc.gqlField == nil || !x.IsGqlErrorList(err)) {
15141510
return resp, err
15151511
}
1516-
if qc.span.IsRecording() {
1517-
qc.span.AddEvent("Response",
1518-
trace.WithAttributes(attribute.String("response", string(resp.Json))))
1519-
}
1512+
qc.span.AddEvent("Response",
1513+
trace.WithAttributes(attribute.String("response", string(resp.Json))))
15201514

15211515
// varToUID contains a map of variable name to the uids corresponding to it.
15221516
// It is used later for constructing set and delete mutations by replacing

query/mutation.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ func ApplyMutations(ctx context.Context, m *pb.Mutations) (*api.TxnContext, erro
4141
tctx, err := worker.MutateOverNetwork(ctx, m)
4242
if err != nil {
4343
span := trace.SpanFromContext(ctx)
44-
if span.IsRecording() {
45-
span.AddEvent("MutateOverNetwork Error", trace.WithAttributes(
46-
attribute.String("error", err.Error()),
47-
attribute.String("mutation", m.String())))
48-
}
44+
span.AddEvent("MutateOverNetwork Error", trace.WithAttributes(
45+
attribute.String("error", err.Error()),
46+
attribute.String("mutation", m.String())))
4947
}
5048
return tctx, err
5149
}

query/query.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,9 +1961,7 @@ func expandSubgraph(ctx context.Context, sg *SubGraph) ([]*SubGraph, error) {
19611961
switch child.Params.Expand {
19621962
// It could be expand(_all_) or expand(val(x)).
19631963
case "_all_":
1964-
if span.IsRecording() {
1965-
span.AddEvent("expand(_all_)")
1966-
}
1964+
span.AddEvent("expand(_all_)")
19671965
if len(typeNames) == 0 {
19681966
break
19691967
}
@@ -1987,9 +1985,7 @@ func expandSubgraph(ctx context.Context, sg *SubGraph) ([]*SubGraph, error) {
19871985

19881986
default:
19891987
if len(child.ExpandPreds) > 0 {
1990-
if span.IsRecording() {
1991-
span.AddEvent("expand default")
1992-
}
1988+
span.AddEvent("expand default")
19931989
// We already have the predicates populated from the var.
19941990
temp := getPredsFromVals(child.ExpandPreds)
19951991
for _, pred := range temp {
@@ -2375,12 +2371,8 @@ func ProcessGraph(ctx context.Context, sg, parent *SubGraph, rch chan error) {
23752371

23762372
if (sg.DestUIDs == nil || len(sg.DestUIDs.Uids) == 0) && childErr == nil {
23772373
// Looks like we're done here. Be careful with nil srcUIDs!
2378-
if span != nil {
2379-
if span.IsRecording() {
2380-
span.AddEvent("Zero uids", trace.WithAttributes(
2381-
attribute.String("attr", sg.Attr)))
2382-
}
2383-
}
2374+
span.AddEvent("Zero uids", trace.WithAttributes(
2375+
attribute.String("attr", sg.Attr)))
23842376
out := sg.Children[:0]
23852377
for _, child := range sg.Children {
23862378
if child.IsInternal() && child.Attr == "expand" {
@@ -2792,9 +2784,7 @@ func (req *Request) ProcessQuery(ctx context.Context) (err error) {
27922784
sg.ReadTs = req.ReadTs
27932785
sg.Cache = req.Cache
27942786
})
2795-
if span.IsRecording() {
2796-
span.AddEvent("Query parsed")
2797-
}
2787+
span.AddEvent("Query parsed")
27982788
req.Subgraphs = append(req.Subgraphs, sg)
27992789
}
28002790
req.Latency.Parsing += time.Since(loopStart)

worker/draft.go

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,7 @@ func (n *node) applyMutations(ctx context.Context, proposal *pb.Proposal) (rerr
434434
// by detectPendingTxns below.
435435
startTs := posting.Oracle().MaxAssigned()
436436

437-
if span.IsRecording() {
438-
span.AddEvent("Applying schema and types")
439-
}
437+
span.AddEvent("Applying schema and types")
440438
for _, supdate := range proposal.Mutations.Schema {
441439
// We should not need to check for predicate move here.
442440
if err := detectPendingTxns(supdate.Predicate); err != nil {
@@ -476,14 +474,10 @@ func (n *node) applyMutations(ctx context.Context, proposal *pb.Proposal) (rerr
476474
// We should only drop the predicate if there is no pending
477475
// transaction.
478476
if err := detectPendingTxns(edge.Attr); err != nil {
479-
if span.IsRecording() {
480-
span.AddEvent("Found pending transactions. Retry later.")
481-
}
477+
span.AddEvent("Found pending transactions. Retry later.")
482478
return err
483479
}
484-
if span.IsRecording() {
485-
span.AddEvent("Deleting predicate")
486-
}
480+
span.AddEvent("Deleting predicate")
487481
return posting.DeletePredicate(ctx, edge.Attr, proposal.StartTs)
488482
}
489483
// Don't derive schema when doing deletion.
@@ -536,11 +530,9 @@ func (n *node) applyMutations(ctx context.Context, proposal *pb.Proposal) (rerr
536530

537531
txn := posting.Oracle().RegisterStartTs(m.StartTs)
538532
if txn.ShouldAbort() {
539-
if span.IsRecording() {
540-
span.AddEvent("Txn should abort.", trace.WithAttributes(
541-
attribute.Int64("start_ts", int64(m.StartTs)),
542-
))
543-
}
533+
span.AddEvent("Txn should abort.", trace.WithAttributes(
534+
attribute.Int64("start_ts", int64(m.StartTs)),
535+
))
544536
return x.ErrConflict
545537
}
546538
// Discard the posting lists from cache to release memory at the end.
@@ -633,12 +625,10 @@ func (n *node) applyCommitted(proposal *pb.Proposal, key uint64) error {
633625

634626
ctx := n.Ctx(key)
635627
span := trace.SpanFromContext(ctx)
636-
if span.IsRecording() {
637-
span.AddEvent("Node.applyCommited", trace.WithAttributes(
638-
attribute.Int64("node id", int64(n.Id)),
639-
attribute.Int64("Group Id", int64(n.gid)),
640-
attribute.Int64("proposal key", int64(key))))
641-
}
628+
span.AddEvent("Node.applyCommited", trace.WithAttributes(
629+
attribute.Int64("node id", int64(n.Id)),
630+
attribute.Int64("Group Id", int64(n.gid)),
631+
attribute.Int64("proposal key", int64(key))))
642632

643633
if proposal.Mutations != nil {
644634
// syncmarks for this shouldn't be marked done until it's committed.
@@ -857,17 +847,16 @@ func (n *node) processApplyCh() {
857847
p := &P{err: perr, size: psz, seen: time.Now()}
858848
previous[key] = p
859849
}
850+
span := trace.SpanFromContext(n.ctx)
860851
if perr != nil {
861852
glog.Errorf("Applying proposal. Error: %v. Proposal: %q.", perr, proposal)
853+
span.AddEvent(fmt.Sprintf("Applying proposal failed. Error: %v Proposal: %q", perr, proposal))
862854
}
863-
span := trace.SpanFromContext(n.ctx)
864-
if span.IsRecording() {
865-
span.AddEvent("Applied proposal with key: %d, index: %d. Err: %v",
866-
trace.WithAttributes(
867-
attribute.Int64("key", int64(key)),
868-
attribute.Int64("index", int64(proposal.Index)),
869-
attribute.String("error", perr.Error())))
870-
}
855+
span.AddEvent("Applied proposal with key: %d, index: %d. Err: %v",
856+
trace.WithAttributes(
857+
attribute.Int64("key", int64(key)),
858+
attribute.Int64("index", int64(proposal.Index)),
859+
))
871860

872861
var tags []tag.Mutator
873862
switch {
@@ -1428,13 +1417,10 @@ func (n *node) Run() {
14281417
// Store the hardstate and entries. Note that these are not CommittedEntries.
14291418
n.SaveToStorage(&rd.HardState, rd.Entries, &rd.Snapshot)
14301419
timer.Record("disk")
1431-
if span != nil {
1432-
span.AddEvent("Saved %d entries. Snapshot, HardState empty? (%v, %v)",
1433-
trace.WithAttributes(
1434-
attribute.Int("entries", len(rd.Entries)),
1435-
attribute.Bool("snapshotEmpty", raft.IsEmptySnap(rd.Snapshot)),
1436-
attribute.Bool("hardStateEmpty", raft.IsEmptyHardState(rd.HardState))))
1437-
}
1420+
span.AddEvent(fmt.Sprintf("Saved %d entries. Snapshot, HardState empty? (%v, %v)",
1421+
len(rd.Entries),
1422+
raft.IsEmptySnap(rd.Snapshot),
1423+
raft.IsEmptyHardState(rd.HardState)))
14381424

14391425
for x.WorkerConfig.HardSync && rd.MustSync {
14401426
if err := n.Store.Sync(); err != nil {

worker/mutation.go

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,9 @@ func runMutation(ctx context.Context, edge *pb.DirectedEdge, txn *posting.Txn) e
107107
plist, err := getFn(key)
108108
if dur := time.Since(t); dur > time.Millisecond {
109109
span := trace.SpanFromContext(ctx)
110-
if span.IsRecording() {
111-
span.AddEvent("Slow GetLru", trace.WithAttributes(
112-
attribute.Bool("slow-get", true),
113-
attribute.String("duration", dur.String())))
114-
}
110+
span.AddEvent("Slow GetLru", trace.WithAttributes(
111+
attribute.Bool("slow-get", true),
112+
attribute.String("duration", dur.String())))
115113
}
116114
if err != nil {
117115
return err
@@ -764,12 +762,10 @@ func MutateOverNetwork(ctx context.Context, m *pb.Mutations) (*api.TxnContext, e
764762
resCh := make(chan res, len(mutationMap))
765763
for gid, mu := range mutationMap {
766764
if gid == 0 {
767-
if span.IsRecording() {
768-
span.AddEvent("State information", trace.WithAttributes(
769-
attribute.String("state", groups().state.String())))
770-
span.AddEvent("Group id zero for mutation", trace.WithAttributes(
771-
attribute.String("mutation", mu.String())))
772-
}
765+
span.AddEvent("State information", trace.WithAttributes(
766+
attribute.String("state", groups().state.String())))
767+
span.AddEvent("Group id zero for mutation", trace.WithAttributes(
768+
attribute.String("mutation", mu.String())))
773769
return tctx, errNonExistentTablet
774770
}
775771
mu.StartTs = m.StartTs
@@ -906,17 +902,13 @@ func CommitOverNetwork(ctx context.Context, tc *api.TxnContext) (uint64, error)
906902
tctx, err := zc.CommitOrAbort(ctx, tc)
907903

908904
if err != nil {
909-
if span.IsRecording() {
910-
span.AddEvent("Error in CommitOrAbort", trace.WithAttributes(
911-
attribute.String("error", err.Error())))
912-
}
905+
span.AddEvent("Error in CommitOrAbort", trace.WithAttributes(
906+
attribute.String("error", err.Error())))
913907
return 0, err
914908
}
915-
if span.IsRecording() {
916-
span.AddEvent("Commit status", trace.WithAttributes(
917-
attribute.Int64("commitTs", int64(tctx.CommitTs)),
918-
attribute.Bool("committed", tctx.CommitTs > 0)))
919-
}
909+
span.AddEvent("Commit status", trace.WithAttributes(
910+
attribute.Int64("commitTs", int64(tctx.CommitTs)),
911+
attribute.Bool("committed", tctx.CommitTs > 0)))
920912

921913
if tctx.Aborted || tctx.CommitTs == 0 {
922914
if !clientDiscard {

worker/predicate_move.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,8 @@ func movePredicateHelper(ctx context.Context, in *pb.MovePredicatePayload) error
342342
}
343343
return out.Send(kvs)
344344
}
345-
if span.IsRecording() {
346-
span.AddEvent("Starting stream list orchestrate", trace.WithAttributes(
347-
attribute.String("predicate", in.Predicate)))
348-
}
345+
span.AddEvent("Starting stream list orchestrate", trace.WithAttributes(
346+
attribute.String("predicate", in.Predicate)))
349347
if err := stream.Orchestrate(out.Context()); err != nil {
350348
return err
351349
}
@@ -360,10 +358,8 @@ func movePredicateHelper(ctx context.Context, in *pb.MovePredicatePayload) error
360358
}
361359

362360
msg := fmt.Sprintf("Receiver %s says it got %d keys.\n", pl.Addr, recvCount)
363-
if span.IsRecording() {
364-
span.AddEvent("Moving predicate", trace.WithAttributes(
365-
attribute.String("predicate", in.Predicate)))
366-
}
361+
span.AddEvent("Moving predicate", trace.WithAttributes(
362+
attribute.String("predicate", in.Predicate)))
367363
glog.Infof(msg)
368364
return nil
369365
}

worker/proposal.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,9 @@ func (n *node) proposeAndWait(ctx context.Context, proposal *pb.Proposal) (perr
229229
x.AssertTruef(n.Proposals.Store(key, pctx), "Found existing proposal with key: [%x]", key)
230230
defer n.Proposals.Delete(key) // Ensure that it gets deleted on return.
231231

232-
if span.IsRecording() {
233-
span.AddEvent("Proposing", trace.WithAttributes(
234-
attribute.Int64("key", int64(key)),
235-
attribute.String("timeout", timeout.String())))
236-
}
232+
span.AddEvent("Proposing", trace.WithAttributes(
233+
attribute.Int64("key", int64(key)),
234+
attribute.String("timeout", timeout.String())))
237235

238236
if err = n.Raft().Propose(cctx, data); err != nil {
239237
return errors.Wrapf(err, "While proposing")
@@ -254,10 +252,8 @@ func (n *node) proposeAndWait(ctx context.Context, proposal *pb.Proposal) (perr
254252
if atomic.LoadUint32(&pctx.Found) > 0 {
255253
// We found the proposal in CommittedEntries. No need to retry.
256254
} else {
257-
if span.IsRecording() {
258-
span.AddEvent("Timeout reached", trace.WithAttributes(
259-
attribute.String("timeout", timeout.String())))
260-
}
255+
span.AddEvent("Timeout reached", trace.WithAttributes(
256+
attribute.String("timeout", timeout.String())))
261257
cancel()
262258
}
263259
case <-cctx.Done():
@@ -295,10 +291,8 @@ func (n *node) proposeAndWait(ctx context.Context, proposal *pb.Proposal) (perr
295291
// below. We should always propose it irrespective of how many pending proposals there
296292
// might be.
297293
default:
298-
if span.IsRecording() {
299-
span.AddEvent("Incrementing limiter", trace.WithAttributes(
300-
attribute.Int64("retry", int64(i))))
301-
}
294+
span.AddEvent("Incrementing limiter", trace.WithAttributes(
295+
attribute.Int64("retry", int64(i))))
302296
if err := limiter.incr(ctx, i); err != nil {
303297
return err
304298
}

0 commit comments

Comments
 (0)