Skip to content

Commit

Permalink
fix: Calling Discard only adds to txn_discards metric, not txn_aborts. (
Browse files Browse the repository at this point in the history
#7365)

This PR is a follow-up to #7339 to update the way
dgraph_txn_discards_total and dgraph_txn_aborts_total are
tracked. When the client calls Discard, only the
dgraph_txn_discards_total metric is incremented, not
dgraph_txn_aborts_total. This makes it easy to see:

1. If the client is calling Discard
2. If the server is aborting transactions (e.g., because of
   transaction conflicts)

Additional changes:

* Update metrics description text
  • Loading branch information
danielmai authored Jan 25, 2021
1 parent 34a96aa commit 1bfb25a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions worker/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,12 @@ func typeSanityCheck(t *pb.TypeUpdate) error {
func CommitOverNetwork(ctx context.Context, tc *api.TxnContext) (uint64, error) {
ctx, span := otrace.StartSpan(ctx, "worker.CommitOverNetwork")
defer span.End()

clientDiscard := false
if tc.Aborted {
// The client called Discard
ostats.Record(ctx, x.TxnDiscards.M(1))
clientDiscard = true
}

pl := groups().Leader(0)
Expand All @@ -789,8 +792,10 @@ func CommitOverNetwork(ctx context.Context, tc *api.TxnContext) (uint64, error)
span.Annotate(attributes, "")

if tctx.Aborted || tctx.CommitTs == 0 {
// The server aborted the txn (not the client)
ostats.Record(ctx, x.TxnAborts.M(1))
if !clientDiscard {
// The server aborted the txn (not the client)
ostats.Record(ctx, x.TxnAborts.M(1))
}
return 0, dgo.ErrAborted
}
ostats.Record(ctx, x.TxnCommits.M(1))
Expand Down
8 changes: 4 additions & 4 deletions x/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ var (
// TxnCommits records count of committed transactions.
TxnCommits = stats.Int64("txn_commits_total",
"Number of transaction commits", stats.UnitDimensionless)
// TxnDiscards records count of discarded transactions.
// TxnDiscards records count of discarded transactions by the client.
TxnDiscards = stats.Int64("txn_discards_total",
"Number of transaction discards", stats.UnitDimensionless)
// TxnAborts records count of aborted transactions.
"Number of transaction discards by the client", stats.UnitDimensionless)
// TxnAborts records count of aborted transactions by the server.
TxnAborts = stats.Int64("txn_aborts_total",
"Number of transaction aborts", stats.UnitDimensionless)
"Number of transaction aborts by the server", stats.UnitDimensionless)
// PBlockHitRatio records the hit ratio of posting store block cache.
PBlockHitRatio = stats.Float64("hit_ratio_postings_block",
"Hit ratio of p store block cache", stats.UnitDimensionless)
Expand Down

0 comments on commit 1bfb25a

Please sign in to comment.