Skip to content

Commit

Permalink
Add a new function LocateKeyRange (#1189)
Browse files Browse the repository at this point in the history
Signed-off-by: SeaRise <[email protected]>
  • Loading branch information
SeaRise authored Feb 29, 2024
1 parent ea5a5c4 commit 09ecb55
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/locate/region_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 09ecb55

Please sign in to comment.