Skip to content

Commit

Permalink
server: add get first region meta support by using empty search key.
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuyesuifeng committed Apr 7, 2016
1 parent e993dd4 commit daa7ddf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 0 additions & 4 deletions server/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,6 @@ func (c *raftCluster) GetStore(storeID uint64) (*metapb.Store, error) {
}

func (c *raftCluster) GetRegion(regionKey []byte) (*metapb.Region, error) {
if len(regionKey) == 0 {
return nil, errors.New("invalid empty region key")
}

// We must use the next region key for search,
// e,g, we have two regions 1, 2, and key ranges are ["", "abc"), ["abc", +infinite),
// if we use "abc" to search the region, the first key >= "abc" may be
Expand Down
16 changes: 15 additions & 1 deletion server/cluster_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,14 @@ func (s *testClusterWorkerSuite) TestSplit(c *C) {
{"e", "d", "", "f"},
}

for _, t := range tbl {
var firstRegionStartKey, firstRegionEndKey string
for i, t := range tbl {
// Get first region start and end key.
if i == 0 {
firstRegionStartKey = t.startKey
firstRegionEndKey = t.splitKey
}

regionKey := []byte(t.searchKey)
region, err := cluster.GetRegion(regionKey)
c.Assert(err, IsNil)
Expand Down Expand Up @@ -777,5 +784,12 @@ func (s *testClusterWorkerSuite) TestSplit(c *C) {
c.Assert(err, IsNil)
c.Assert(right.GetStartKey(), BytesEquals, []byte(t.splitKey))
c.Assert(right.GetEndKey(), BytesEquals, []byte(t.endKey))

// Test get first region.
regionKey = []byte{}
region, err = cluster.GetRegion(regionKey)
c.Assert(err, IsNil)
c.Assert(region.GetStartKey(), BytesEquals, []byte(firstRegionStartKey))
c.Assert(region.GetEndKey(), BytesEquals, []byte(firstRegionEndKey))
}
}

0 comments on commit daa7ddf

Please sign in to comment.