diff --git a/ddl/ddl_tiflash_test.go b/ddl/ddl_tiflash_test.go index 2fb42d76dd507..b86c420d605fb 100644 --- a/ddl/ddl_tiflash_test.go +++ b/ddl/ddl_tiflash_test.go @@ -998,18 +998,19 @@ func TestTiFlashBatchUnsupported(t *testing.T) { func TestTiFlashGroupIndexWhenStartup(t *testing.T) { s, teardown := createTiFlashContext(t) + tiflash := s.tiflash defer teardown() _ = testkit.NewTestKit(t, s.store) timeout := time.Now().Add(10 * time.Second) errMsg := "time out" for time.Now().Before(timeout) { time.Sleep(100 * time.Millisecond) - if s.tiflash.GroupIndex != 0 { + if tiflash.GetRuleGroupIndex() != 0 { errMsg = "invalid group index" break } } - require.Equal(t, placement.RuleIndexTiFlash, s.tiflash.GroupIndex, errMsg) - require.Greater(t, s.tiflash.GroupIndex, placement.RuleIndexTable) - require.Greater(t, s.tiflash.GroupIndex, placement.RuleIndexPartition) + require.Equal(t, placement.RuleIndexTiFlash, tiflash.GetRuleGroupIndex(), errMsg) + require.Greater(t, tiflash.GetRuleGroupIndex(), placement.RuleIndexTable) + require.Greater(t, tiflash.GetRuleGroupIndex(), placement.RuleIndexPartition) } diff --git a/domain/infosync/tiflash_manager.go b/domain/infosync/tiflash_manager.go index 7040eefee837b..eb929a776ae58 100644 --- a/domain/infosync/tiflash_manager.go +++ b/domain/infosync/tiflash_manager.go @@ -305,7 +305,7 @@ func (m *mockTiFlashTableInfo) String() string { // MockTiFlash mocks a TiFlash, with necessary Pd support. type MockTiFlash struct { sync.Mutex - GroupIndex int + groupIndex int StatusAddr string StatusServer *httptest.Server SyncStatus map[int]mockTiFlashTableInfo @@ -373,7 +373,7 @@ func NewMockTiFlash() *MockTiFlash { func (tiflash *MockTiFlash) HandleSetPlacementRule(rule placement.TiFlashRule) error { tiflash.Lock() defer tiflash.Unlock() - tiflash.GroupIndex = placement.RuleIndexTiFlash + tiflash.groupIndex = placement.RuleIndexTiFlash if !tiflash.PdEnabled { logutil.BgLogger().Info("pd server is manually disabled, just quit") return nil @@ -492,6 +492,20 @@ func (tiflash *MockTiFlash) HandleGetStoresStat() *helper.StoresStat { } } +// SetRuleGroupIndex sets the group index of tiflash +func (tiflash *MockTiFlash) SetRuleGroupIndex(groupIndex int) { + tiflash.Lock() + defer tiflash.Unlock() + tiflash.groupIndex = groupIndex +} + +// GetRuleGroupIndex gets the group index of tiflash +func (tiflash *MockTiFlash) GetRuleGroupIndex() int { + tiflash.Lock() + defer tiflash.Unlock() + return tiflash.groupIndex +} + // Compare supposed rule, and we actually get from TableInfo func isRuleMatch(rule placement.TiFlashRule, startKey string, endKey string, count int, labels []string) bool { // Compute startKey @@ -598,7 +612,7 @@ func (m *mockTiFlashPlacementManager) SetTiFlashGroupConfig(_ context.Context) e if m.tiflash == nil { return nil } - m.tiflash.GroupIndex = placement.RuleIndexTiFlash + m.tiflash.SetRuleGroupIndex(placement.RuleIndexTiFlash) return nil }