Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
Signed-off-by: HunDunDM <hundundm@gmail.com>
  • Loading branch information
HunDunDM authored and ti-chi-bot committed Nov 12, 2021
1 parent 3473efd commit 5f0d781
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion server/core/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func GenerateRegionGuideFunc(enableLog bool) RegionGuideFunc {
// Because keys and bytes are strongly related, only bytes are judged.
if region.GetRoundBytesWritten() != origin.GetRoundBytesWritten() ||
region.GetRoundBytesRead() != origin.GetRoundBytesRead() ||
region.flowRoundDivisor != origin.flowRoundDivisor {
region.flowRoundDivisor < origin.flowRoundDivisor {
saveCache, needSync = true, true
}

Expand Down
13 changes: 9 additions & 4 deletions server/core/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,19 @@ func (s *testRegionGuideSuite) TestNeedSync(c *C) {
needSync bool
}{
{
optionsA: []RegionCreateOption{WithLeader(nil)},
optionsB: []RegionCreateOption{WithLeader(nil)},
needSync: true,
},
{
optionsA: []RegionCreateOption{WithLeader(meta.Peers[1])},
optionsB: []RegionCreateOption{WithLeader(meta.Peers[1])},
needSync: true,
},
{
optionsA: []RegionCreateOption{WithPendingPeers(meta.Peers[1:2])},
optionsB: []RegionCreateOption{WithPendingPeers(meta.Peers[1:2])},
needSync: true,
},
{
optionsA: []RegionCreateOption{WithDownPeers([]*pdpb.PeerStats{{Peer: meta.Peers[1], DownSeconds: 600}})},
optionsB: []RegionCreateOption{WithDownPeers([]*pdpb.PeerStats{{Peer: meta.Peers[1], DownSeconds: 600}})},
needSync: true,
},
{
Expand All @@ -247,6 +247,11 @@ func (s *testRegionGuideSuite) TestNeedSync(c *C) {
{
optionsA: []RegionCreateOption{SetWrittenBytes(100000), WithFlowRoundByDigit(127)},
optionsB: []RegionCreateOption{SetWrittenBytes(0), WithFlowRoundByDigit(2)},
needSync: false,
},
{
optionsA: []RegionCreateOption{SetWrittenBytes(0), WithFlowRoundByDigit(2)},
optionsB: []RegionCreateOption{SetWrittenBytes(100000), WithFlowRoundByDigit(127)},
needSync: true,
},
}
Expand Down
18 changes: 9 additions & 9 deletions server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,13 @@ func (s *heartbeatServer) Recv() (*pdpb.RegionHeartbeatRequest, error) {
// RegionHeartbeat implements gRPC PDServer.
func (s *Server) RegionHeartbeat(stream pdpb.PD_RegionHeartbeatServer) error {
var (
server = &heartbeatServer{stream: stream}
regionFlowRoundByDigitOption = core.WithFlowRoundByDigit(s.persistOptions.GetPDServerConfig().FlowRoundByDigit)
forwardStream pdpb.PD_RegionHeartbeatClient
cancel context.CancelFunc
lastForwardedHost string
lastBind time.Time
errCh chan error
server = &heartbeatServer{stream: stream}
flowRoundOption = core.WithFlowRoundByDigit(s.persistOptions.GetPDServerConfig().FlowRoundByDigit)
forwardStream pdpb.PD_RegionHeartbeatClient
cancel context.CancelFunc
lastForwardedHost string
lastBind time.Time
errCh chan error
)
defer func() {
// cancel the forward stream
Expand Down Expand Up @@ -585,11 +585,11 @@ func (s *Server) RegionHeartbeat(stream pdpb.PD_RegionHeartbeatServer) error {
regionHeartbeatCounter.WithLabelValues(storeAddress, storeLabel, "report", "bind").Inc()
s.hbStreams.BindStream(storeID, server)
// refresh FlowRoundByDigit
regionFlowRoundByDigitOption = core.WithFlowRoundByDigit(s.persistOptions.GetPDServerConfig().FlowRoundByDigit)
flowRoundOption = core.WithFlowRoundByDigit(s.persistOptions.GetPDServerConfig().FlowRoundByDigit)
lastBind = time.Now()
}

region := core.RegionFromHeartbeat(request, regionFlowRoundByDigitOption)
region := core.RegionFromHeartbeat(request, flowRoundOption)
if region.GetLeader() == nil {
log.Error("invalid request, the leader is nil", zap.Reflect("request", request), errs.ZapError(errs.ErrLeaderNil))
regionHeartbeatCounter.WithLabelValues(storeAddress, storeLabel, "report", "invalid-leader").Inc()
Expand Down

0 comments on commit 5f0d781

Please sign in to comment.