Skip to content

Commit

Permalink
fix: Make runtime param accessor concurrent safe
Browse files Browse the repository at this point in the history
Related to milvus-io#39049

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
  • Loading branch information
congqixia committed Jan 7, 2025
1 parent 47e7ea2 commit e707664
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
9 changes: 5 additions & 4 deletions pkg/util/paramtable/component_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 11 additions & 10 deletions pkg/util/paramtable/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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)
}

0 comments on commit e707664

Please sign in to comment.