Skip to content

Commit be9501f

Browse files
committed
roachpb: print observed timestamps in txn
Split out from #143270. Epic: none Release note: None
1 parent d6f6132 commit be9501f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pkg/kv/kvpb/errors_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ func TestErrorRedaction(t *testing.T) {
171171
hlc.ClockTimestamp{WallTime: 1, Logical: 2},
172172
))
173173
txn := roachpb.MakeTransaction("foo", roachpb.Key("bar"), isolation.Serializable, 1, hlc.Timestamp{WallTime: 1}, 1, 99, 0, false /* omitInRangefeeds */)
174+
txn.UpdateObservedTimestamp(1, hlc.ClockTimestamp{WallTime: 111, Logical: 1})
175+
txn.UpdateObservedTimestamp(2, hlc.ClockTimestamp{WallTime: 222, Logical: 2})
174176
txn.ID = uuid.Nil
175177
txn.Priority = 1234
176178
wrappedPErr.UnexposedTxn = &txn
@@ -180,7 +182,7 @@ func TestErrorRedaction(t *testing.T) {
180182
var s redact.StringBuilder
181183
s.Print(r)
182184
act := s.RedactableString().Redact()
183-
const exp = "ReadWithinUncertaintyIntervalError: read at time 0.000000001,0 encountered previous write with future timestamp 0.000000002,0 (local=0.000000001,2) within uncertainty interval `t <= (local=0.000000002,2, global=0.000000003,0)`; observed timestamps: [{12 0.000000004,0}]: \"foo\" meta={id=00000000 key=‹×› iso=Serializable pri=0.00005746 epo=0 ts=0.000000001,0 min=0.000000001,0 seq=0} lock=true stat=PENDING rts=0.000000001,0 wto=false gul=0.000000002,0"
185+
const exp = "ReadWithinUncertaintyIntervalError: read at time 0.000000001,0 encountered previous write with future timestamp 0.000000002,0 (local=0.000000001,2) within uncertainty interval `t <= (local=0.000000002,2, global=0.000000003,0)`; observed timestamps: [{12 0.000000004,0}]: \"foo\" meta={id=00000000 key=‹×› iso=Serializable pri=0.00005746 epo=0 ts=0.000000001,0 min=0.000000001,0 seq=0} lock=true stat=PENDING rts=0.000000001,0 wto=false gul=0.000000002,0 obs={[email protected],1 [email protected],2}"
184186
require.Equal(t, exp, string(act))
185187
})
186188

pkg/roachpb/data.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,29 @@ func (t Transaction) SafeFormat(w redact.SafePrinter, _ rune) {
15541554
}
15551555
w.Printf("meta={%s} lock=%t stat=%s rts=%s wto=%t gul=%s",
15561556
t.TxnMeta, t.IsLocking(), t.Status, t.ReadTimestamp, t.WriteTooOld, t.GlobalUncertaintyLimit)
1557+
1558+
// Print observed timestamps (limited to 5 for readability).
1559+
if obsCount := len(t.ObservedTimestamps); obsCount > 0 {
1560+
w.Printf(" obs={")
1561+
limit := obsCount
1562+
if limit > 5 {
1563+
limit = 5
1564+
}
1565+
1566+
for i := 0; i < limit; i++ {
1567+
if i > 0 {
1568+
w.Printf(" ")
1569+
}
1570+
obs := t.ObservedTimestamps[i]
1571+
w.Printf("n%d@%s", obs.NodeID, obs.Timestamp)
1572+
}
1573+
1574+
if obsCount > 5 {
1575+
w.Printf(", ...")
1576+
}
1577+
w.Printf("}")
1578+
}
1579+
15571580
if ni := len(t.LockSpans); t.Status != PENDING && ni > 0 {
15581581
w.Printf(" int=%d", ni)
15591582
}

0 commit comments

Comments
 (0)