Fix data race in minicluster for nodes add&get (#24336)

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/24344/head
congqixia 2023-05-23 21:09:28 +08:00 committed by GitHub
parent 943b7fb0ef
commit 227a770a11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 3 deletions

View File

@ -14,6 +14,7 @@ on:
- 'pkg/**'
- 'cmd/**'
- 'build/**'
- 'tests/integration/**'
- '.github/workflows/code-checker.yaml'
- '.env'
- docker-compose.yml

View File

@ -13,6 +13,7 @@ on:
- 'pkg/**'
- 'cmd/**'
- 'build/**'
- 'tests/integration/**'
- '.github/workflows/mac.yaml'
- '.env'
- docker-compose.yml

View File

@ -10,7 +10,7 @@ on:
- 'pkg/**'
- 'cmd/**'
- 'build/**'
- 'tests/integration' # run integration test
- 'tests/integration/**' # run integration test
- '.github/workflows/main.yaml'
- '.env'
- docker-compose.yml
@ -26,7 +26,7 @@ on:
- 'pkg/**'
- 'cmd/**'
- 'build/**'
- 'tests/integration' # run integration test
- 'tests/integration/**' # run integration test
- '.github/workflows/main.yaml'
- '.env'
- docker-compose.yml

View File

@ -95,7 +95,7 @@ const (
type MiniCluster struct {
ctx context.Context
mu sync.Mutex
mu sync.RWMutex
params map[string]string
clusterConfig ClusterConfig
@ -1177,6 +1177,8 @@ func (cluster *MiniCluster) UpdateClusterSize(clusterConfig ClusterConfig) error
}
func (cluster *MiniCluster) GetProxy(ctx context.Context, addr string) (types.Proxy, error) {
cluster.mu.RLock()
defer cluster.mu.RUnlock()
if cluster.Proxy.GetAddress() == addr {
return cluster.Proxy, nil
}
@ -1184,6 +1186,8 @@ func (cluster *MiniCluster) GetProxy(ctx context.Context, addr string) (types.Pr
}
func (cluster *MiniCluster) GetQueryNode(ctx context.Context, addr string) (types.QueryNode, error) {
cluster.mu.RLock()
defer cluster.mu.RUnlock()
for _, queryNode := range cluster.QueryNodes {
if queryNode.GetAddress() == addr {
return queryNode, nil
@ -1193,6 +1197,8 @@ func (cluster *MiniCluster) GetQueryNode(ctx context.Context, addr string) (type
}
func (cluster *MiniCluster) GetDataNode(ctx context.Context, addr string) (types.DataNode, error) {
cluster.mu.RLock()
defer cluster.mu.RUnlock()
for _, dataNode := range cluster.DataNodes {
if dataNode.GetAddress() == addr {
return dataNode, nil
@ -1202,6 +1208,8 @@ func (cluster *MiniCluster) GetDataNode(ctx context.Context, addr string) (types
}
func (cluster *MiniCluster) GetIndexNode(ctx context.Context, addr string) (types.IndexNode, error) {
cluster.mu.RLock()
defer cluster.mu.RUnlock()
for _, indexNode := range cluster.IndexNodes {
if indexNode.GetAddress() == addr {
return indexNode, nil