Skip to content

Commit

Permalink
kvcoord: evict range cache on unsplittable batches
Browse files Browse the repository at this point in the history
Epic: none
Release note: None
  • Loading branch information
erikgrinaker committed Feb 22, 2024
1 parent 15b75eb commit d53805b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/kv/kvclient/kvcoord/dist_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -1495,12 +1495,15 @@ func (ds *DistSender) divideAndSendBatchToRanges(
return resp.reply, resp.pErr
}

// The batch spans ranges (according to our cached range descriptors).
// Verify that this is ok.
// TODO(tschottdorf): we should have a mechanism for discovering range
// merges (descriptor staleness will mostly go unnoticed), or we'll be
// turning single-range queries into multi-range queries for no good
// reason.
// The batch spans ranges (according to our cached range descriptors). Either
// the client has an outdated view of the range descriptor and didn't see a
// split, or we have an outdated view of the range descriptor and didn't see a
// merge. Evict the descriptor in case it's the latter. This case should be
// fairly rare.
//
// TODO(tschottdorf): we should have a mechanism for discovering range merges
// (descriptor staleness will mostly go unnoticed), or we'll be evicting the
// cache for no good reason.
if ba.IsUnsplittable() {
mismatch := kvpb.NewRangeKeyMismatchErrorWithCTPolicy(ctx,
rs.Key.AsRawKey(),
Expand All @@ -1509,6 +1512,9 @@ func (ds *DistSender) divideAndSendBatchToRanges(
nil, /* lease */
ri.ClosedTimestampPolicy(),
)
// Evict the cached descriptor after constructing the error.
tok := ri.Token()
tok.Evict(ctx)
return nil, kvpb.NewError(mismatch)
}
// If there's no transaction and ba spans ranges, possibly re-run as part of
Expand Down

0 comments on commit d53805b

Please sign in to comment.