Skip to content

Commit 7433331

Browse files
craig[bot]nicktrav
andcommitted
Merge #131545
131545: kvp,kvserver: add range id, span to BatchTimestampBeforeGCError r=nicktrav a=nicktrav 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. Co-authored-by: Nick Travers <[email protected]>
2 parents 8d4573a + 96b93e8 commit 7433331

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

pkg/ccl/changefeedccl/changefeedbase/errors_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ func TestAsTerminalError(t *testing.T) {
4040

4141
// Regardless of the state of the node drain, or the type of error,
4242
// context error takes precedence.
43-
require.Regexp(t, context.Canceled,
44-
changefeedbase.AsTerminalError(canceledCtx, nodeIsDraining, errors.New("ignored")))
45-
require.Regexp(t, context.Canceled,
46-
changefeedbase.AsTerminalError(canceledCtx, nodeIsNotDraining, errors.New("ignored")))
43+
require.Regexp(t, context.Canceled.Error(),
44+
changefeedbase.AsTerminalError(canceledCtx, nodeIsDraining, errors.New("ignored")).Error())
45+
require.Regexp(t, context.Canceled.Error(),
46+
changefeedbase.AsTerminalError(canceledCtx, nodeIsNotDraining, errors.New("ignored")).Error())
4747
})
4848

4949
t.Run("node drain marked as job retry", func(t *testing.T) {
5050
cause := errors.New("some error happened")
5151
termErr := changefeedbase.AsTerminalError(context.Background(), nodeIsDraining, cause)
52-
require.Regexp(t, cause.Error(), termErr)
52+
require.Contains(t, cause.Error(), termErr.Error())
5353
require.True(t, jobs.IsRetryJobError(termErr))
5454
})
5555

@@ -58,19 +58,19 @@ func TestAsTerminalError(t *testing.T) {
5858
cause := changefeedbase.WithTerminalError(
5959
changefeedbase.MarkRetryableError(errors.New("confusing error")))
6060
termErr := changefeedbase.AsTerminalError(context.Background(), nodeIsNotDraining, cause)
61-
require.Regexp(t, cause.Error(), termErr)
61+
require.Contains(t, cause.Error(), termErr.Error())
6262
})
6363

6464
t.Run("assertion failures are terminal", func(t *testing.T) {
6565
// Assertion failures are terminal, even if marked as retry-able.
6666
cause := changefeedbase.MarkRetryableError(errors.AssertionFailedf("though shall not pass"))
6767
termErr := changefeedbase.AsTerminalError(context.Background(), nodeIsNotDraining, cause)
68-
require.Regexp(t, cause.Error(), termErr)
68+
require.Contains(t, cause.Error(), termErr.Error())
6969
})
7070

7171
t.Run("gc error is terminal", func(t *testing.T) {
7272
cause := changefeedbase.MarkRetryableError(&kvpb.BatchTimestampBeforeGCError{})
7373
termErr := changefeedbase.AsTerminalError(context.Background(), nodeIsNotDraining, cause)
74-
require.Regexp(t, cause.Error(), termErr)
74+
require.Contains(t, cause.Error(), termErr.Error())
7575
})
7676
}

pkg/kv/kvpb/errors.go

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

13671367
func (e *BatchTimestampBeforeGCError) SafeFormatError(p errors.Printer) (next error) {
1368-
p.Printf("batch timestamp %v must be after replica GC threshold %v", e.Timestamp, e.Threshold)
1368+
p.Printf(
1369+
"batch timestamp %v must be after replica GC threshold %v (r%d: %s)",
1370+
e.Timestamp, e.Threshold, e.RangeID,
1371+
roachpb.RSpan{Key: []byte(e.StartKey), EndKey: []byte(e.EndKey)},
1372+
)
13691373
return nil
13701374
}
13711375

pkg/kv/kvpb/errors.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,11 @@ message BatchTimestampBeforeGCError {
598598
// that has been marked as excluded from a backup via
599599
// `ALTER TABLE ... SET (exclude_data_from_backup = true)`.
600600
optional bool data_excluded_from_backup = 3 [(gogoproto.nullable) = false];
601+
optional int64 range_id = 4 [(gogoproto.nullable) = false,
602+
(gogoproto.customname) = "RangeID",
603+
(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.RangeID"];
604+
optional bytes start_key = 5 [(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.Key"];
605+
optional bytes end_key = 6 [(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.Key"];
601606
}
602607

603608
// 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
@@ -287,7 +287,7 @@ func TestErrorRedaction(t *testing.T) {
287287
},
288288
{
289289
err: &BatchTimestampBeforeGCError{},
290-
expect: "batch timestamp 0,0 must be after replica GC threshold 0,0",
290+
expect: "batch timestamp 0,0 must be after replica GC threshold 0,0 (r0: ‹/Min›)",
291291
},
292292
{
293293
err: &TxnAlreadyEncounteredErrorError{},

pkg/kv/kvserver/kvserverbase/forced_error.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ func CheckForcedErr(
260260
ForcedError: kvpb.NewError(&kvpb.BatchTimestampBeforeGCError{
261261
Timestamp: wts,
262262
Threshold: *replicaState.GCThreshold,
263+
RangeID: replicaState.Desc.RangeID,
264+
StartKey: replicaState.Desc.StartKey.AsRawKey(),
265+
EndKey: replicaState.Desc.EndKey.AsRawKey(),
263266
}),
264267
}
265268
}

pkg/kv/kvserver/replica.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,10 +2011,14 @@ func (r *Replica) checkTSAboveGCThresholdRLocked(
20112011
if threshold.Less(ts) {
20122012
return nil
20132013
}
2014+
desc := r.descRLocked()
20142015
return &kvpb.BatchTimestampBeforeGCError{
20152016
Timestamp: ts,
20162017
Threshold: threshold,
20172018
DataExcludedFromBackup: r.excludeReplicaFromBackupRLocked(ctx, rspan),
2019+
RangeID: desc.RangeID,
2020+
StartKey: desc.StartKey.AsRawKey(),
2021+
EndKey: desc.EndKey.AsRawKey(),
20182022
}
20192023
}
20202024

0 commit comments

Comments
 (0)