Skip to content

Commit e707ed2

Browse files
authored
Merge pull request #134256 from cockroachdb/blathers/backport-release-24.1-131545
release-24.1: kvpb,kvserver: add range id, span to BatchTimestampBeforeGCError
2 parents 3bf24a3 + 47deb11 commit e707ed2

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
@@ -37,16 +37,16 @@ func TestAsTerminalError(t *testing.T) {
3737

3838
// Regardless of the state of the node drain, or the type of error,
3939
// context error takes precedence.
40-
require.Regexp(t, context.Canceled,
41-
changefeedbase.AsTerminalError(canceledCtx, nodeIsDraining, errors.New("ignored")))
42-
require.Regexp(t, context.Canceled,
43-
changefeedbase.AsTerminalError(canceledCtx, nodeIsNotDraining, errors.New("ignored")))
40+
require.Regexp(t, context.Canceled.Error(),
41+
changefeedbase.AsTerminalError(canceledCtx, nodeIsDraining, errors.New("ignored")).Error())
42+
require.Regexp(t, context.Canceled.Error(),
43+
changefeedbase.AsTerminalError(canceledCtx, nodeIsNotDraining, errors.New("ignored")).Error())
4444
})
4545

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

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

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

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

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)