Skip to content

Commit 47deb11

Browse files
committed
kvpb,kvserver: add range id, span to BatchTimestampBeforeGCError
Currently, debugging a `BatchTimestampBeforeGCError` is difficult, as there information is lacking as to replica / range tried to touch underneath the GC threshold. Add the range ID and span to the error message. Fixes #131256. Release note: None.
1 parent 0ed6076 commit 47deb11

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

pkg/kv/kvpb/errors.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,11 @@ func (e *BatchTimestampBeforeGCError) Error() string {
13541354
}
13551355

13561356
func (e *BatchTimestampBeforeGCError) SafeFormatError(p errors.Printer) (next error) {
1357-
p.Printf("batch timestamp %v must be after replica GC threshold %v", e.Timestamp, e.Threshold)
1357+
p.Printf(
1358+
"batch timestamp %v must be after replica GC threshold %v (r%d: %s)",
1359+
e.Timestamp, e.Threshold, e.RangeID,
1360+
roachpb.RSpan{Key: []byte(e.StartKey), EndKey: []byte(e.EndKey)},
1361+
)
13581362
return nil
13591363
}
13601364

pkg/kv/kvpb/errors.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,11 @@ message BatchTimestampBeforeGCError {
579579
// that has been marked as excluded from a backup via
580580
// `ALTER TABLE ... SET (exclude_data_from_backup = true)`.
581581
optional bool data_excluded_from_backup = 3 [(gogoproto.nullable) = false];
582+
optional int64 range_id = 4 [(gogoproto.nullable) = false,
583+
(gogoproto.customname) = "RangeID",
584+
(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.RangeID"];
585+
optional bytes start_key = 5 [(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.Key"];
586+
optional bytes end_key = 6 [(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.Key"];
582587
}
583588

584589
// A MVCCHistoryMutationError indicates that MVCC history was unexpectedly

pkg/kv/kvpb/errors_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func TestErrorRedaction(t *testing.T) {
282282
},
283283
{
284284
err: &BatchTimestampBeforeGCError{},
285-
expect: "batch timestamp 0,0 must be after replica GC threshold 0,0",
285+
expect: "batch timestamp 0,0 must be after replica GC threshold 0,0 (r0: ‹/Min›)",
286286
},
287287
{
288288
err: &TxnAlreadyEncounteredErrorError{},

pkg/kv/kvserver/kvserverbase/forced_error.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ func CheckForcedErr(
256256
ForcedError: kvpb.NewError(&kvpb.BatchTimestampBeforeGCError{
257257
Timestamp: wts,
258258
Threshold: *replicaState.GCThreshold,
259+
RangeID: replicaState.Desc.RangeID,
260+
StartKey: replicaState.Desc.StartKey.AsRawKey(),
261+
EndKey: replicaState.Desc.EndKey.AsRawKey(),
259262
}),
260263
}
261264
}

pkg/kv/kvserver/replica.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,10 +1993,14 @@ func (r *Replica) checkTSAboveGCThresholdRLocked(
19931993
if threshold.Less(ts) {
19941994
return nil
19951995
}
1996+
desc := r.descRLocked()
19961997
return &kvpb.BatchTimestampBeforeGCError{
19971998
Timestamp: ts,
19981999
Threshold: threshold,
19992000
DataExcludedFromBackup: r.excludeReplicaFromBackupRLocked(ctx, rspan),
2001+
RangeID: desc.RangeID,
2002+
StartKey: desc.StartKey.AsRawKey(),
2003+
EndKey: desc.EndKey.AsRawKey(),
20002004
}
20012005
}
20022006

0 commit comments

Comments
 (0)