diff --git a/internal/api/config_manager.go b/internal/api/config_manager.go index e9e0b4d18..7b8c2cdb0 100644 --- a/internal/api/config_manager.go +++ b/internal/api/config_manager.go @@ -158,6 +158,12 @@ func compareAndSave[T any](c *gin.Context, old any, req *apistruct.SetConfigReq, } func (cm *ConfigManager) ResetConfig(c *gin.Context) { + go cm.restart(c) + apiresp.GinSuccess(c, nil) +} + +func (cm *ConfigManager) restart(c *gin.Context) { + <-etcd.CanRestart type initConf struct { old any new any @@ -214,5 +220,5 @@ func (cm *ConfigManager) ResetConfig(c *gin.Context) { return } } - apiresp.GinSuccess(c, nil) + etcd.CanRestart <- struct{}{} } diff --git a/pkg/common/discovery/etcd/config_manager.go b/pkg/common/discovery/etcd/config_manager.go index 46b676ec6..37fd3b031 100644 --- a/pkg/common/discovery/etcd/config_manager.go +++ b/pkg/common/discovery/etcd/config_manager.go @@ -5,7 +5,6 @@ import ( "os" "os/exec" "runtime" - "sync" "syscall" "github.com/openimsdk/tools/errs" @@ -19,9 +18,15 @@ const ( ) var ( - ShutDowns []func() error + ShutDowns []func() error + CanRestart chan struct{} ) +func init() { + CanRestart = make(chan struct{}, 1) + CanRestart <- struct{}{} +} + func RegisterShutDown(shutDown ...func() error) { ShutDowns = append(ShutDowns, shutDown...) } @@ -29,7 +34,6 @@ func RegisterShutDown(shutDown ...func() error) { type ConfigManager struct { client *clientv3.Client watchConfigNames []string - lock sync.RWMutex } func BuildKey(s string) string { @@ -57,12 +61,12 @@ func (c *ConfigManager) Watch(ctx context.Context) { for _, event := range watchResp.Events { if event.IsModify() { if datautil.Contain(string(event.Kv.Key), c.watchConfigNames...) { - c.lock.Lock() + <-CanRestart err := restartServer(ctx) if err != nil { log.ZError(ctx, "restart server err", err) + CanRestart <- struct{}{} } - c.lock.Unlock() } } }