Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kv: avoid transaction too large error if already refreshed #31733

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pkg/kv/dist_sender_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2078,6 +2078,32 @@ func TestTxnCoordSenderRetries(t *testing.T) {
},
expFailure: "transaction is too large to complete; try splitting into pieces",
},
{
// If we've exhausted the limit for tracking refresh spans but we
// already refreshed, keep running the txn.
name: "forwarded timestamp with too many refreshes, read only",
afterTxnStart: func(ctx context.Context, db *client.DB) error {
return db.Put(ctx, "a", "value")
},
retryable: func(ctx context.Context, txn *client.Txn) error {
// Make the batch large enough such that when we accounted for
// all of its spans then we exceed the limit on refresh spans.
// This is not an issue because we refresh before tracking their
// spans.
keybase := strings.Repeat("a", 1024)
maxRefreshBytes := kv.MaxTxnRefreshSpansBytes.Get(&s.ClusterSettings().SV)
scanToExceed := int(maxRefreshBytes) / len(keybase)
b := txn.NewBatch()
// Hit the uncertainty error at the beginning of the batch.
b.Get("a")
for i := 0; i < scanToExceed; i++ {
key := roachpb.Key(fmt.Sprintf("%s%10d", keybase, i))
b.Scan(key, key.Next())
}
return txn.Run(ctx, b)
},
filter: newUncertaintyFilter(roachpb.Key([]byte("a"))),
},
{
// Even if accounting for the refresh spans would have exhausted the
// limit for tracking refresh spans and our transaction's timestamp
Expand Down
10 changes: 9 additions & 1 deletion pkg/kv/txn_interceptor_span_refresher.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,15 @@ func (sr *txnSpanRefresher) SendLocked(
// exhausted, return a non-retryable error indicating that the
// transaction is too large and should potentially be split.
// We do this to avoid endlessly retrying a txn likely refail.
if sr.refreshInvalid && (br.Txn.OrigTimestamp != br.Txn.Timestamp) {
//
// TODO(nvanbenschoten): this is duplicating some of the logic
// in IsSerializablePushAndRefreshNotPossible. We plan to remove
// this all shortly (#30074), but if that changes, we should clean
// this overlap up.
ts := br.Txn.OrigTimestamp
ts.Forward(br.Txn.RefreshedTimestamp)
pushed := ts != br.Txn.Timestamp
if pushed && sr.refreshInvalid {
return nil, roachpb.NewErrorWithTxn(
errors.New("transaction is too large to complete; try splitting into pieces"), br.Txn,
)
Expand Down