Add a new function LocateKeyRange (#1189)

Signed-off-by: SeaRise <hhssearise@foxmail.com>
This commit is contained in:
SeaRise 2024-02-29 12:58:05 +08:00 committed by GitHub
parent ea5a5c4ba6
commit 09ecb550d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 0 deletions

View File

@ -1175,6 +1175,24 @@ func (b *Bucket) Contains(key []byte) bool {
return contains(b.StartKey, b.EndKey, key)
}
// LocateKeyRange lists region and range that key in [start_key,end_key].
func (c *RegionCache) LocateKeyRange(bo *retry.Backoffer, startKey, endKey []byte) ([]*KeyLocation, error) {
regions, err := c.LoadRegionsInKeyRange(bo, startKey, endKey)
if err != nil {
return nil, err
}
res := make([]*KeyLocation, 0, len(regions))
for _, r := range regions {
res = append(res, &KeyLocation{
Region: r.VerID(),
StartKey: r.StartKey(),
EndKey: r.EndKey(),
Buckets: r.getStore().buckets,
})
}
return res, nil
}
// LocateKey searches for the region and range that the key is located.
func (c *RegionCache) LocateKey(bo *retry.Backoffer, key []byte) (*KeyLocation, error) {
r, err := c.findRegionByKey(bo, key, false)