Skip to content

Commit

Permalink
schedule: when Region is removed from RegionsInfo, also remove fit ca…
Browse files Browse the repository at this point in the history
…che (#5865)

ref #5860, ref #5864

Signed-off-by: HunDunDM <hundundm@gmail.com>
  • Loading branch information
HunDunDM authored Jan 19, 2023
1 parent c5bf5be commit 6e35a4d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ func (c *RaftCluster) processRegionHeartbeat(region *core.RegionInfo) error {
c.regionStats.ClearDefunctRegion(item.GetID())
}
c.labelLevelStats.ClearDefunctRegion(item.GetID())
c.ruleManager.InvalidCache(item.GetID())
}
regionUpdateCacheEventCounter.Inc()
}
Expand Down
7 changes: 7 additions & 0 deletions server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,11 @@ func TestRegionHeartbeat(t *testing.T) {
re.NoError(err)

// Check overlap
rm := cluster.GetRuleManager()
rm.SetPlaceholderRegionFitCache(regions[n-1])
rm.SetPlaceholderRegionFitCache(regions[n-2])
re.True(rm.CheckIsCachedDirectly(regions[n-1].GetID()))
re.True(rm.CheckIsCachedDirectly(regions[n-2].GetID()))
overlapRegion = regions[n-1].Clone(
core.WithStartKey(regions[n-2].GetStartKey()),
core.WithNewRegionID(regions[n-1].GetID()+1),
Expand All @@ -911,9 +916,11 @@ func TestRegionHeartbeat(t *testing.T) {
ok, err = storage.LoadRegion(regions[n-1].GetID(), region)
re.False(ok)
re.NoError(err)
re.False(rm.CheckIsCachedDirectly(regions[n-1].GetID()))
ok, err = storage.LoadRegion(regions[n-2].GetID(), region)
re.False(ok)
re.NoError(err)
re.False(rm.CheckIsCachedDirectly(regions[n-2].GetID()))
ok, err = storage.LoadRegion(overlapRegion.GetID(), region)
re.True(ok)
re.NoError(err)
Expand Down
18 changes: 18 additions & 0 deletions server/schedule/placement/rule_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,24 @@ func (m *RuleManager) InvalidCache(regionID uint64) {
m.cache.Invalid(regionID)
}

// SetPlaceholderRegionFitCache sets a placeholder region fit cache information
// Only used for testing
func (m *RuleManager) SetPlaceholderRegionFitCache(region *core.RegionInfo) {
placeholderCache := &RegionRuleFitCache{region: toRegionCache(region)}
m.cache.mu.Lock()
defer m.cache.mu.Unlock()
m.cache.caches[region.GetID()] = placeholderCache
}

// CheckIsCachedDirectly returns whether the region's fit is cached
// Only used for testing
func (m *RuleManager) CheckIsCachedDirectly(regionID uint64) bool {
m.cache.mu.RLock()
defer m.cache.mu.RUnlock()
_, ok := m.cache.caches[regionID]
return ok
}

func (m *RuleManager) beginPatch() *ruleConfigPatch {
return m.ruleConfig.beginPatch()
}
Expand Down

0 comments on commit 6e35a4d

Please sign in to comment.