Skip to content

Commit 6be6f17

Browse files
committed
address comment
Signed-off-by: husharp <jinhao.hu@pingcap.com>
1 parent d161acb commit 6be6f17

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

pkg/core/region.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,28 @@ type RegionInfo struct {
7676
source RegionSource
7777
}
7878

79+
// RegionSource is the source of region.
80+
type RegionSource uint32
81+
82+
const (
83+
// FromStorage means this region's meta info might be stale.
84+
FromStorage RegionSource = iota
85+
// FromSync means this region's meta info might be stale.
86+
FromSync
87+
// FromHeartbeat means this region's meta info is relatively fresher.
88+
FromHeartbeat
89+
)
90+
91+
// SourceStale means this region's meta info might be stale.
92+
func (r *RegionInfo) SourceStale() bool {
93+
return r.source == FromStorage || r.source == FromSync
94+
}
95+
96+
// SourceFresh means this region's meta info is relatively fresher.
97+
func (r *RegionInfo) SourceFresh() bool {
98+
return r.source == FromHeartbeat
99+
}
100+
79101
// GetRegionSource returns the region source.
80102
func (r *RegionInfo) GetRegionSource() RegionSource {
81103
return r.source
@@ -685,7 +707,7 @@ func GenerateRegionGuideFunc(enableLog bool) RegionGuideFunc {
685707
}
686708
saveKV, saveCache, isNew = true, true, true
687709
} else {
688-
if origin.source == FromSync || origin.source == FromStorage {
710+
if origin.SourceStale() {
689711
isNew = true
690712
}
691713
r := region.GetRegionEpoch()
@@ -795,18 +817,6 @@ type RegionsInfo struct {
795817
pendingPeers map[uint64]*regionTree // storeID -> sub regionTree
796818
}
797819

798-
// RegionSource is the source of region.
799-
type RegionSource uint32
800-
801-
const (
802-
// FromStorage means region is stale.
803-
FromStorage RegionSource = iota
804-
// FromSync means region is stale.
805-
FromSync
806-
// FromHeartbeat means region is fresh.
807-
FromHeartbeat
808-
)
809-
810820
// NewRegionsInfo creates RegionsInfo with tree, regions, leaders and followers
811821
func NewRegionsInfo() *RegionsInfo {
812822
return &RegionsInfo{
@@ -854,7 +864,7 @@ func (r *RegionsInfo) CheckAndPutRegion(region *RegionInfo) []*RegionInfo {
854864
origin, overlaps, rangeChanged := r.setRegionLocked(region, true, ols...)
855865
r.t.Unlock()
856866
r.UpdateSubTree(region, origin, overlaps, rangeChanged)
857-
// FromStorage means region is stale.
867+
// FromStorage means this region's meta info might be stale.
858868
r.AtomicAddStaleRegionCnt()
859869
return overlaps
860870
}
@@ -902,7 +912,7 @@ func (r *RegionsInfo) AtomicCheckAndPutRegion(region *RegionInfo) ([]*RegionInfo
902912
return nil, err
903913
}
904914
// If origin is stale, need to sub the stale region count.
905-
if origin != nil && origin.source != FromHeartbeat && region.source == FromHeartbeat {
915+
if origin != nil && origin.SourceStale() && region.SourceFresh() {
906916
r.tree.AtomicSubStaleRegionCnt()
907917
}
908918
origin, overlaps, rangeChanged := r.setRegionLocked(region, true, ols...)

pkg/core/region_tree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type regionTree struct {
6262
totalSize int64
6363
totalWriteBytesRate float64
6464
totalWriteKeysRate float64
65-
65+
// count the stale meta regions
6666
staleRegionCnt int64
6767
}
6868

pkg/syncer/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ func (s *RegionSyncer) StartSyncWithLeader(addr string) {
194194
log.Debug("region is stale", zap.Stringer("origin", origin.GetMeta()), errs.ZapError(err))
195195
continue
196196
}
197-
// FromSync means region is stale.
198-
if origin == nil || (origin != nil && origin.GetRegionSource() == core.FromHeartbeat) {
197+
// FromSync means this region's meta info might be stale.
198+
if origin == nil || (origin != nil && origin.SourceFresh()) {
199199
bc.RegionsInfo.AtomicAddStaleRegionCnt()
200200
}
201201
_, saveKV, _, _ := regionGuide(region, origin)

0 commit comments

Comments
 (0)