Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: enhance the table regions HTTP API #12357

Merged
merged 9 commits into from
Sep 26, 2019
Prev Previous commit
Next Next commit
address comment
  • Loading branch information
tiancaiamao committed Sep 25, 2019
commit 67deccb045a44737863d86ce68fa0df6eeacbb0b
15 changes: 7 additions & 8 deletions store/mockstore/mocktikv/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,21 +284,20 @@ func (c *Cluster) ScanRegions(startKey, endKey []byte, limit int) ([]*metapb.Reg
return bytes.Compare(regions[i].Meta.GetStartKey(), regions[j].Meta.GetStartKey()) < 0
})

keyLocation := sort.Search(len(regions), func(i int) bool {
startPos := sort.Search(len(regions), func(i int) bool {
if len(regions[i].Meta.GetEndKey()) == 0 {
return true
}
return bytes.Compare(regions[i].Meta.GetEndKey(), startKey) > 0
})
regions = regions[keyLocation:]
regions = regions[startPos:]
if len(endKey) > 0 {
var pos int
for pos = 1; pos < len(regions); pos++ {
if bytes.Compare(regions[pos].Meta.GetStartKey(), endKey) >= 0 {
break
}
endPos := sort.Search(len(regions), func(i int) bool {
return bytes.Compare(regions[i].Meta.GetStartKey(), endKey) >= 0
})
if endPos > 0 {
regions = regions[:endPos]
}
regions = regions[:pos]
}
if limit > 0 && len(regions) > limit {
regions = regions[:limit]
Expand Down