diff --git a/store/tikv/mpp.go b/store/tikv/mpp.go index 0145ad7c3ab3a..69d722be1c9b8 100644 --- a/store/tikv/mpp.go +++ b/store/tikv/mpp.go @@ -43,14 +43,10 @@ func (c *batchCopTask) GetAddress() string { func (c *MPPClient) selectAllTiFlashStore() []kv.MPPTaskMeta { resultTasks := make([]kv.MPPTaskMeta, 0) - c.store.regionCache.storeMu.RLock() - for _, st := range c.store.regionCache.storeMu.stores { - if st.storeType == kv.TiFlash { - task := &batchCopTask{storeAddr: st.addr, cmdType: tikvrpc.CmdMPPTask} - resultTasks = append(resultTasks, task) - } + for _, addr := range c.store.regionCache.GetTiFlashStoreAddrs() { + task := &batchCopTask{storeAddr: addr, cmdType: tikvrpc.CmdMPPTask} + resultTasks = append(resultTasks, task) } - c.store.regionCache.storeMu.RUnlock() return resultTasks } diff --git a/store/tikv/region_cache.go b/store/tikv/region_cache.go index 2967d2bf32850..21ff61b57c479 100644 --- a/store/tikv/region_cache.go +++ b/store/tikv/region_cache.go @@ -1244,6 +1244,19 @@ func (c *RegionCache) PDClient() pd.Client { return c.pdClient } +// GetTiFlashStoreAddrs returns addresses of all tiflash nodes. +func (c *RegionCache) GetTiFlashStoreAddrs() []string { + c.storeMu.RLock() + defer c.storeMu.RUnlock() + var addrs []string + for _, s := range c.storeMu.stores { + if s.storeType == kv.TiFlash { + addrs = append(addrs, s.addr) + } + } + return addrs +} + // btreeItem is BTree's Item that uses []byte to compare. type btreeItem struct { key []byte