Skip to content

Commit

Permalink
Merge #34379
Browse files Browse the repository at this point in the history
34379: release-2.1: roachpb: make Transaction implement SafeMessager r=andreimatei a=andreimatei

Backport 1/1 commits from #34378.

/cc @cockroachdb/release

---

So it is included in Sentry reports.
Also improve a Fatal message that's been seen to fire for unknown
reasons (haven't yet looked if I can figure out why it fires).

Touches #34341

Release note: None


Co-authored-by: Andrei Matei <[email protected]>
  • Loading branch information
craig[bot] and andreimatei committed Jan 30, 2019
2 parents 60cb315 + 9e2acdb commit d364a23
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/kv/txn_interceptor_heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ func (h *txnHeartbeat) heartbeat(ctx context.Context) bool {
// status. That response is supposed to have closed the txnHeartbeat.
if h.mu.txn.Status != roachpb.PENDING {
if h.mu.txnEnd != nil {
log.Fatalf(ctx, "txn status: %s, but heartbeat loop hasn't been signaled to stop", h.mu.txn.Status)
log.Fatalf(ctx,
"txn committed or aborted but heartbeat loop hasn't been signaled to stop. txn: %s",
h.mu.txn)
}
return false
}
Expand Down
25 changes: 25 additions & 0 deletions pkg/roachpb/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,8 @@ func (v Value) PrettyPrint() string {
return buf.String()
}

var _ log.SafeMessager = Transaction{}

const (
// MinTxnPriority is the minimum allowed txn priority.
MinTxnPriority = 0
Expand Down Expand Up @@ -1010,6 +1012,8 @@ func (t *Transaction) IsSerializable() bool {
}

// String formats transaction into human readable string.
//
// NOTE: When updating String(), you probably want to also update SafeMessage().
func (t Transaction) String() string {
var buf bytes.Buffer
// Compute priority as a floating point number from 0-100 for readability.
Expand All @@ -1027,6 +1031,27 @@ func (t Transaction) String() string {
return buf.String()
}

// SafeMessage implements the SafeMessager interface.
//
// This method should be kept largely synchronized with String(), except that it
// can't include sensitive info (e.g. the transaction key).
func (t Transaction) SafeMessage() string {
var buf bytes.Buffer
// Compute priority as a floating point number from 0-100 for readability.
floatPri := 100 * float64(t.Priority) / float64(math.MaxInt32)
if len(t.Name) > 0 {
fmt.Fprintf(&buf, "%q ", t.Name)
}
fmt.Fprintf(&buf, "id=%s rw=%t pri=%.8f stat=%s epo=%d "+
"ts=%s orig=%s max=%s wto=%t seq=%d",
t.Short(), t.Writing, floatPri, t.Status, t.Epoch, t.Timestamp,
t.OrigTimestamp, t.MaxTimestamp, t.WriteTooOld, t.Sequence)
if ni := len(t.Intents); t.Status != PENDING && ni > 0 {
fmt.Fprintf(&buf, " int=%d", ni)
}
return buf.String()
}

// ResetObservedTimestamps clears out all timestamps recorded from individual
// nodes.
func (t *Transaction) ResetObservedTimestamps() {
Expand Down

0 comments on commit d364a23

Please sign in to comment.