From 5f0d781d1c33a19edbd3654a52dd83fe83e24c16 Mon Sep 17 00:00:00 2001 From: HunDunDM Date: Mon, 8 Nov 2021 15:25:20 +0800 Subject: [PATCH] address comment Signed-off-by: HunDunDM --- server/core/region.go | 2 +- server/core/region_test.go | 13 +++++++++---- server/grpc_service.go | 18 +++++++++--------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/server/core/region.go b/server/core/region.go index 930b4f4a520..a22b41adbc3 100644 --- a/server/core/region.go +++ b/server/core/region.go @@ -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 } diff --git a/server/core/region_test.go b/server/core/region_test.go index 6205be4f4bb..ce6c3138e11 100644 --- a/server/core/region_test.go +++ b/server/core/region_test.go @@ -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, }, { @@ -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, }, } diff --git a/server/grpc_service.go b/server/grpc_service.go index 6d77c30a78d..9eb9f59489a 100644 --- a/server/grpc_service.go +++ b/server/grpc_service.go @@ -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 @@ -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()