Skip to content

Commit

Permalink
server: fix the dead lock in scatter region (#1706)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx authored and sre-bot committed Aug 26, 2019
1 parent 141496b commit 14b91e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 14 additions & 0 deletions server/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,20 @@ func (c *RaftCluster) GetOperatorController() *schedule.OperatorController {
return c.coordinator.opController
}

// GetHeartbeatStreams returns the heartbeat streams.
func (c *RaftCluster) GetHeartbeatStreams() *heartbeatStreams {
c.RLock()
defer c.RUnlock()
return c.coordinator.hbStreams
}

// GetCoordinator returns the coordinator.
func (c *RaftCluster) GetCoordinator() *coordinator {
c.RLock()
defer c.RUnlock()
return c.coordinator
}

// handleStoreHeartbeat updates the store status.
func (c *RaftCluster) handleStoreHeartbeat(stats *pdpb.StoreStats) error {
c.Lock()
Expand Down
8 changes: 2 additions & 6 deletions server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,7 @@ func (s *Server) RegionHeartbeat(stream pdpb.PD_RegionHeartbeatServer) error {
regionHeartbeatCounter.WithLabelValues(storeAddress, storeLabel, "report", "recv").Inc()
regionHeartbeatLatency.WithLabelValues(storeAddress, storeLabel).Observe(float64(time.Now().Unix()) - float64(request.GetInterval().GetEndTimestamp()))

cluster.RLock()
hbStreams := cluster.coordinator.hbStreams
cluster.RUnlock()
hbStreams := cluster.GetHeartbeatStreams()

if time.Since(lastBind) > s.cfg.HeartbeatStreamBindInterval.Duration {
regionHeartbeatCounter.WithLabelValues(storeAddress, storeLabel, "report", "bind").Inc()
Expand Down Expand Up @@ -633,9 +631,7 @@ func (s *Server) ScatterRegion(ctx context.Context, request *pdpb.ScatterRegionR
return nil, errors.Errorf("region %d is a hot region", region.GetID())
}

cluster.RLock()
defer cluster.RUnlock()
co := cluster.coordinator
co := cluster.GetCoordinator()
op, err := co.regionScatterer.Scatter(region)
if err != nil {
return nil, err
Expand Down

0 comments on commit 14b91e8

Please sign in to comment.