cockroachdb / cockroachdb/cockroach
kvcoord: DistSender does not respect MaxSpanRequestKeys for read-write batches
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
**Describe the problem**
DistSender splits batches at two levels:
1. Batches are split according to the rules in `(BatchRequest).Split` to separate isWrite requests from read-only requests.
2. Batches are split at range boundaries.
If the batch is split according to (1), MaxSpanRequestKeys consumed by one batch do not apply to subsequent batches. In almost all cases, this is no matter since most isWrite requests don't consume MaxSpanRequestKeys anyway. But, there are a few problematic cases such as:
```golang
err := db.Txn(recCtx, func(ctx context.Context, txn *kv.Txn) error {
b := txn.NewBatch()
b.Header.MaxSpanRequestKeys = 1
b.Scan(startKey, endKey)
b.ScanForUpdate(startKey, endKey, kvpb.GuaranteedDurability)
if err := txn.Run(ctx, b); err != nil {
return err
}
})
```
These two scans are separated into different batches because the GuaranteedDurability lock is considered a write and thus split off into its own batch. It seems likely that a mixed Scan + DeleteRange is also affected by this.
I don't think SQL will ever produce such batches currently.
Jira issue: CRDB-54399
Contributor guide
Assessment
This issue has not been assessed yet.