From a208170c1fc6687c1434383d64be17a4deae4dbe Mon Sep 17 00:00:00 2001 From: congqixia Date: Wed, 8 Jan 2025 17:08:57 +0800 Subject: [PATCH] fix: Make runtime param accessor concurrent safe (#39050) Related to #39049 Signed-off-by: Congqi Xia --- pkg/util/paramtable/component_param.go | 9 +++++---- pkg/util/paramtable/runtime.go | 21 +++++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/pkg/util/paramtable/component_param.go b/pkg/util/paramtable/component_param.go index 4aeb628d3e57a..a01178b37ece7 100644 --- a/pkg/util/paramtable/component_param.go +++ b/pkg/util/paramtable/component_param.go @@ -33,6 +33,7 @@ import ( "github.com/milvus-io/milvus/pkg/log" "github.com/milvus-io/milvus/pkg/util/hardware" "github.com/milvus-io/milvus/pkg/util/metricsinfo" + "github.com/milvus-io/milvus/pkg/util/typeutil" ) const ( @@ -4872,11 +4873,11 @@ It's ok to set it into duration string, such as 30s or 1m30s, see time.ParseDura // runtimeConfig is just a private environment value table. type runtimeConfig struct { - createTime time.Time - updateTime time.Time - role string + createTime atomic.Time + updateTime atomic.Time + role atomic.String nodeID atomic.Int64 - components map[string]struct{} + components typeutil.ConcurrentSet[string] } type integrationTestConfig struct { diff --git a/pkg/util/paramtable/runtime.go b/pkg/util/paramtable/runtime.go index a961c5be63d23..63079dfb7052e 100644 --- a/pkg/util/paramtable/runtime.go +++ b/pkg/util/paramtable/runtime.go @@ -20,13 +20,15 @@ import ( "strconv" "sync" "time" + + "github.com/milvus-io/milvus/pkg/util/typeutil" ) var ( once sync.Once params ComponentParam runtimeParam = runtimeConfig{ - components: make(map[string]struct{}, 0), + components: typeutil.ConcurrentSet[string]{}, } hookParams hookConfig ) @@ -73,34 +75,33 @@ func GetStringNodeID() string { } func SetRole(role string) { - runtimeParam.role = role + runtimeParam.role.Store(role) } func GetRole() string { - return runtimeParam.role + return runtimeParam.role.Load() } func SetCreateTime(d time.Time) { - runtimeParam.createTime = d + runtimeParam.createTime.Store(d) } func GetCreateTime() time.Time { - return runtimeParam.createTime + return runtimeParam.createTime.Load() } func SetUpdateTime(d time.Time) { - runtimeParam.updateTime = d + runtimeParam.updateTime.Store(d) } func GetUpdateTime() time.Time { - return runtimeParam.updateTime + return runtimeParam.updateTime.Load() } func SetLocalComponentEnabled(component string) { - runtimeParam.components[component] = struct{}{} + runtimeParam.components.Insert(component) } func IsLocalComponentEnabled(component string) bool { - _, ok := runtimeParam.components[component] - return ok + return runtimeParam.components.Contain(component) }