Skip to content

Commit

Permalink
Merge pull request #72 from pingcap/qiuyesuifeng/first-region
Browse files Browse the repository at this point in the history
server: add get first region meta support by using empty search key.
  • Loading branch information
qiuyesuifeng committed Apr 8, 2016
2 parents 9810e4b + ecdb25a commit a19e5a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 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
9 changes: 9 additions & 0 deletions server/cluster_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,8 @@ func (s *testClusterWorkerSuite) TestSplit(c *C) {
{"e", "d", "", "f"},
}

firstRegionStartKey := tbl[0].startKey
firstRegionEndKey := tbl[0].splitKey
for _, t := range tbl {
regionKey := []byte(t.searchKey)
region, err := cluster.GetRegion(regionKey)
Expand Down Expand Up @@ -777,5 +779,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 a19e5a5

Please sign in to comment.