mirror of https://github.com/milvus-io/milvus.git
fix: Make runtime param accessor concurrent safe (#39050)
Related to #39049 Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>pull/38867/head
parent
a89ac861da
commit
a208170c1f
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue