diff --git a/pkg/node/core/config/datacenter.go b/pkg/node/core/config/datacenter.go index 311f9d97d..7dc57a6c1 100644 --- a/pkg/node/core/config/datacenter.go +++ b/pkg/node/core/config/datacenter.go @@ -140,12 +140,48 @@ func (d *DataCenterConfig) GetConfig(name string) *model.ConfigUnit { return d.config.Get(name) } +//CacheConfig 更新配置缓存 +func (d *DataCenterConfig) CacheConfig(c *model.ConfigUnit) error { + if c.Name == "" { + return fmt.Errorf("config name can not be empty") + } + logrus.Debugf("add config %v", c) + //将值类型由[]interface{} 转 []string + if c.ValueType == "array" { + switch c.Value.(type) { + case []interface{}: + var data []string + for _, v := range c.Value.([]interface{}) { + data = append(data, v.(string)) + } + c.Value = data + } + oldC := d.config.Get(c.Name) + if oldC != nil { + + switch oldC.Value.(type) { + case string: + value := append(c.Value.([]string), oldC.Value.(string)) + util.Deweight(&value) + c.Value = value + case []string: + value := append(c.Value.([]string), oldC.Value.([]string)...) + util.Deweight(&value) + c.Value = value + default: + } + } + } + d.config.Add(*c) + return nil +} + //PutConfig 增加or更新配置 func (d *DataCenterConfig) PutConfig(c *model.ConfigUnit) error { if c.Name == "" { return fmt.Errorf("config name can not be empty") } - logrus.Debugf("add config %v",c) + logrus.Debugf("add config %v", c) //将值类型由[]interface{} 转 []string if c.ValueType == "array" { switch c.Value.(type) { @@ -186,7 +222,7 @@ func (d *DataCenterConfig) PutConfig(c *model.ConfigUnit) error { func (d *DataCenterConfig) PutConfigKV(kv *mvccpb.KeyValue) { var cn model.ConfigUnit if err := ffjson.Unmarshal(kv.Value, &cn); err == nil { - d.PutConfig(&cn) + d.CacheConfig(&cn) } else { logrus.Errorf("parse config error,%s", err.Error()) } diff --git a/pkg/node/masterserver/task/engine.go b/pkg/node/masterserver/task/engine.go index 5ce81a014..9ca335522 100644 --- a/pkg/node/masterserver/task/engine.go +++ b/pkg/node/masterserver/task/engine.go @@ -143,17 +143,16 @@ func (t *TaskEngine) haveMaster() (bool, error) { } if !resp.Succeeded { ctx, cancel := context.WithTimeout(t.ctx, time.Second*3) - ch := store.DefalutClient.WatchByCtx(ctx, "/rainbond/task/scheduler/authority") + defer cancel() + ch := store.DefalutClient.WatchByCtx(ctx, key) for { select { case <-t.ctx.Done(): - cancel() return false, nil case events := <-ch: for _, event := range events.Events { //watch 到删除操作,返回去获取权限 if event.Type == client.EventTypeDelete { - cancel() return false, nil } }