Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: fix data race in TestTiFlashGroupIndexWhenStartup #37371

Merged
merged 2 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ddl/ddl_tiflash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
18 changes: 15 additions & 3 deletions domain/infosync/tiflash_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -492,6 +492,18 @@ func (tiflash *MockTiFlash) HandleGetStoresStat() *helper.StoresStat {
}
}

func (tiflash *MockTiFlash) SetRuleGroupIndex(groupIndex int) {
tiflash.Lock()
defer tiflash.Unlock()
tiflash.groupIndex = groupIndex
}

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
Expand Down Expand Up @@ -598,7 +610,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
}

Expand Down