From d53805b82369e4044934aa77327566ae7d7807c6 Mon Sep 17 00:00:00 2001 From: Erik Grinaker Date: Thu, 22 Feb 2024 11:38:28 +0000 Subject: [PATCH] kvcoord: evict range cache on unsplittable batches Epic: none Release note: None --- pkg/kv/kvclient/kvcoord/dist_sender.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/kv/kvclient/kvcoord/dist_sender.go b/pkg/kv/kvclient/kvcoord/dist_sender.go index 2747e227e77e..f3f163de2914 100644 --- a/pkg/kv/kvclient/kvcoord/dist_sender.go +++ b/pkg/kv/kvclient/kvcoord/dist_sender.go @@ -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(), @@ -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