Skip to content

Commit

Permalink
proto: compatible with proto3. (#919)
Browse files Browse the repository at this point in the history
  • Loading branch information
disksing authored Jan 15, 2018
1 parent 1a878c9 commit 9522bba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions server/cluster_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,27 @@ func (s *testClusterWorkerSuite) checkSearchRegions(cluster *RaftCluster, keys .
}
}

func (s *testClusterWorkerSuite) TestEmptyRegionKey(c *C) {
cluster := s.svr.GetRaftCluster()
c.Assert(cluster, NotNil)
r1, _ := cluster.GetRegionByKey([]byte("a"))
// Bootstrap region is ["", "").
c.Assert(r1.StartKey, HasLen, 0)
c.Assert(r1.EndKey, HasLen, 0)
// For the region key, nil is the same as "".
r1.StartKey, r1.EndKey = nil, nil
req := &pdpb.AskSplitRequest{
Header: newRequestHeader(s.clusterID),
Region: r1,
}
_, err := s.grpcPDClient.AskSplit(context.Background(), req)
c.Assert(err, IsNil)
// Without region will get an error.
req.Region = nil
_, err = s.grpcPDClient.AskSplit(context.Background(), req)
c.Assert(err, NotNil)
}

func (s *testClusterWorkerSuite) TestHeartbeatSplit(c *C) {
cluster := s.svr.GetRaftCluster()
c.Assert(cluster, NotNil)
Expand Down
4 changes: 2 additions & 2 deletions server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ func (s *Server) AskSplit(ctx context.Context, request *pdpb.AskSplitRequest) (*
if cluster == nil {
return &pdpb.AskSplitResponse{Header: s.notBootstrappedHeader()}, nil
}
if request.GetRegion().GetStartKey() == nil {
return nil, errors.New("missing region start key for split")
if request.GetRegion() == nil {
return nil, errors.New("missing region for split")
}
req := &pdpb.AskSplitRequest{
Region: request.Region,
Expand Down

0 comments on commit 9522bba

Please sign in to comment.