Skip to content

Commit

Permalink
fix: paramtable cache cause dynamic config non-dynamic (milvus-io#33473)
Browse files Browse the repository at this point in the history
relate: milvus-io#33461

Signed-off-by: aoiasd <[email protected]>
  • Loading branch information
aoiasd authored Jun 4, 2024
1 parent ac5e098 commit 2422084
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/roles/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func (mr *MilvusRoles) Run() {
}

tracer.SetTracerProvider(exp, params.TraceCfg.SampleFraction.GetAsFloat())
log.Info("Reset tracer finished", zap.String("Exporter", params.TraceCfg.Exporter.GetValue()))
log.Info("Reset tracer finished", zap.String("Exporter", params.TraceCfg.Exporter.GetValue()), zap.Float64("SampleFraction", params.TraceCfg.SampleFraction.GetAsFloat()))

if paramtable.GetRole() == typeutil.QueryNodeRole || paramtable.GetRole() == typeutil.StandaloneRole {
initcore.InitTraceConfig(params)
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/env_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func (es EnvSource) GetSourceName() string {
return "EnvironmentSource"
}

func (es EnvSource) SetManager(m ConfigManager) {
}

func (es EnvSource) SetEventHandler(eh EventHandler) {
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/config/etcd_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"sync"
"time"

"github.com/samber/lo"
clientv3 "go.etcd.io/etcd/client/v3"
"go.uber.org/zap"

Expand All @@ -44,6 +45,7 @@ type EtcdSource struct {

updateMu sync.Mutex
configRefresher *refresher
manager ConfigManager
}

func NewEtcdSource(etcdInfo *EtcdInfo) (*EtcdSource, error) {
Expand Down Expand Up @@ -115,6 +117,12 @@ func (es *EtcdSource) Close() {
es.configRefresher.stop()
}

func (es *EtcdSource) SetManager(m ConfigManager) {
es.Lock()
defer es.Unlock()
es.manager = m
}

func (es *EtcdSource) SetEventHandler(eh EventHandler) {
es.configRefresher.SetEventHandler(eh)
}
Expand Down Expand Up @@ -172,6 +180,9 @@ func (es *EtcdSource) update(configs map[string]string) error {
return err
}
es.currentConfigs = configs
if es.manager != nil {
es.manager.EvictCacheValueByFormat(lo.Map(events, func(event *Event, _ int) string { return event.Key })...)
}
es.Unlock()

es.configRefresher.fireEvents(events...)
Expand Down
11 changes: 11 additions & 0 deletions pkg/config/file_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"sync"

"github.com/cockroachdb/errors"
"github.com/samber/lo"
"github.com/spf13/cast"
"github.com/spf13/viper"
"go.uber.org/zap"
Expand All @@ -36,6 +37,7 @@ type FileSource struct {

updateMu sync.Mutex
configRefresher *refresher
manager ConfigManager
}

func NewFileSource(fileInfo *FileInfo) *FileSource {
Expand Down Expand Up @@ -91,6 +93,12 @@ func (fs *FileSource) Close() {
fs.configRefresher.stop()
}

func (fs *FileSource) SetManager(m ConfigManager) {
fs.Lock()
defer fs.Unlock()
fs.manager = m
}

func (fs *FileSource) SetEventHandler(eh EventHandler) {
fs.RWMutex.Lock()
defer fs.RWMutex.Unlock()
Expand Down Expand Up @@ -173,6 +181,9 @@ func (fs *FileSource) update(configs map[string]string) error {
return err
}
fs.configs = configs
if fs.manager != nil {
fs.manager.EvictCacheValueByFormat(lo.Map(events, func(event *Event, _ int) string { return event.Key })...)
}
fs.Unlock()

fs.configRefresher.fireEvents(events...)
Expand Down
11 changes: 11 additions & 0 deletions pkg/config/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ func (m *Manager) EvictCachedValue(key string) {
m.configCache.Remove(key)
}

func (m *Manager) EvictCacheValueByFormat(keys ...string) {
set := typeutil.NewSet(keys...)
m.configCache.Range(func(key string, value interface{}) bool {
if set.Contain(formatKey(key)) {
m.configCache.Remove(key)
}
return true
})
}

func (m *Manager) GetConfig(key string) (string, error) {
realKey := formatKey(key)
v, ok := m.overlays.Get(realKey)
Expand Down Expand Up @@ -210,6 +220,7 @@ func (m *Manager) AddSource(source Source) error {
return err
}

source.SetManager(m)
m.sources.Insert(sourceName, source)

err := m.pullSourceConfigs(sourceName)
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ func (ErrSource) GetPriority() int {
return 2
}

func (ErrSource) SetManager(m ConfigManager) {
}

// GetSourceName implements Source
func (ErrSource) GetSourceName() string {
return "ErrSource"
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ const (
LowPriority = NormalPriority + 10
)

type ConfigManager interface {
EvictCacheValueByFormat(keys ...string)
}

type Source interface {
GetConfigurations() (map[string]string, error)
GetConfigurationByKey(string) (string, error)
GetPriority() int
GetSourceName() string
SetEventHandler(eh EventHandler)
SetManager(m ConfigManager)
UpdateOptions(opt Options)
Close()
}
Expand Down

0 comments on commit 2422084

Please sign in to comment.