diff --git a/server/cluster_worker_test.go b/server/cluster_worker_test.go index f244a235df1..381fe9b009c 100644 --- a/server/cluster_worker_test.go +++ b/server/cluster_worker_test.go @@ -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) diff --git a/server/grpc_service.go b/server/grpc_service.go index d25999b113c..ac574d4f55b 100644 --- a/server/grpc_service.go +++ b/server/grpc_service.go @@ -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,