diff --git a/config/base_config_test.go b/config/base_config_test.go index 7fa895ad49..15b468753d 100644 --- a/config/base_config_test.go +++ b/config/base_config_test.go @@ -116,12 +116,12 @@ func TestRefresh(t *testing.T) { config.GetEnvInstance().UpdateExternalConfigMap(mockMap) father := &ConsumerConfig{ - Check: &[]bool{true}[0], + Check: &[]bool{true}[0], BaseConfig: BaseConfig{ - ApplicationConfig:baseAppConfig, + ApplicationConfig: baseAppConfig, }, - Registries: baseRegistries, - References: baseMockRef, + Registries: baseRegistries, + References: baseMockRef, ShutdownConfig: &ShutdownConfig{ Timeout: "12s", StepTimeout: "2s", @@ -150,12 +150,12 @@ func TestAppExternalRefresh(t *testing.T) { mockMap["dubbo.consumer.check"] = "true" config.GetEnvInstance().UpdateExternalConfigMap(mockMap) father := &ConsumerConfig{ - Check: &[]bool{true}[0], + Check: &[]bool{true}[0], BaseConfig: BaseConfig{ - ApplicationConfig:baseAppConfig, + ApplicationConfig: baseAppConfig, }, - Registries: baseRegistries, - References: baseMockRef, + Registries: baseRegistries, + References: baseMockRef, } c.SetFatherConfig(father) @@ -178,12 +178,12 @@ func TestAppExternalWithoutIDRefresh(t *testing.T) { mockMap["dubbo.consumer.check"] = "true" config.GetEnvInstance().UpdateExternalConfigMap(mockMap) father := &ConsumerConfig{ - Check: &[]bool{true}[0], + Check: &[]bool{true}[0], BaseConfig: BaseConfig{ - ApplicationConfig:baseAppConfig, + ApplicationConfig: baseAppConfig, }, - Registries: baseRegistries, - References: baseMockRef, + Registries: baseRegistries, + References: baseMockRef, } c.SetFatherConfig(father) @@ -208,13 +208,13 @@ func TestRefreshSingleRegistry(t *testing.T) { config.GetEnvInstance().UpdateExternalConfigMap(mockMap) father := &ConsumerConfig{ - Check: &[]bool{true}[0], + Check: &[]bool{true}[0], BaseConfig: BaseConfig{ - ApplicationConfig: baseAppConfig, + ApplicationConfig: baseAppConfig, }, - Registries: map[string]*RegistryConfig{}, - Registry: &RegistryConfig{}, - References: baseMockRef, + Registries: map[string]*RegistryConfig{}, + Registry: &RegistryConfig{}, + References: baseMockRef, } c.SetFatherConfig(father) @@ -242,7 +242,7 @@ func TestRefreshProvider(t *testing.T) { BaseConfig: BaseConfig{ ApplicationConfig: baseAppConfig, }, - Registries: baseRegistries, + Registries: baseRegistries, Services: map[string]*ServiceConfig{ "MockService": { InterfaceName: "com.MockService", diff --git a/remoting/zookeeper/client.go b/remoting/zookeeper/client.go index a24e9eb828..8bbfd81909 100644 --- a/remoting/zookeeper/client.go +++ b/remoting/zookeeper/client.go @@ -433,6 +433,7 @@ func (z *ZookeeperClient) CreateWithValue(basePath string, value []byte) error { // CreateTempWithValue will create the node recursively, which means that if the parent node is absent, // it will create parent node first,and set value in last child path +// If the path exist, it will update data func (z *ZookeeperClient) CreateTempWithValue(basePath string, value []byte) error { var ( err error @@ -453,6 +454,9 @@ func (z *ZookeeperClient) CreateTempWithValue(basePath string, value []byte) err // last child need be ephemeral if i == length-1 { _, err = conn.Create(tmpPath, value, zk.FlagEphemeral, zk.WorldACL(zk.PermAll)) + if err == zk.ErrNodeExists { + return err + } } else { _, err = conn.Create(tmpPath, []byte{}, 0, zk.WorldACL(zk.PermAll)) } diff --git a/remoting/zookeeper/curator_discovery/service_discovery.go b/remoting/zookeeper/curator_discovery/service_discovery.go index 6c7ec15e9a..1b52a53d80 100644 --- a/remoting/zookeeper/curator_discovery/service_discovery.go +++ b/remoting/zookeeper/curator_discovery/service_discovery.go @@ -22,6 +22,8 @@ import ( "path" "strings" "sync" + + "github.com/dubbogo/go-zookeeper/zk" ) import ( @@ -71,6 +73,16 @@ func (sd *ServiceDiscovery) registerService(instance *ServiceInstance) error { return err } err = sd.client.CreateTempWithValue(path, data) + if err == zk.ErrNodeExists { + _, state, _ := sd.client.GetContent(path) + if state != nil { + _, err = sd.client.SetContent(path, data, state.Version+1) + if err != nil { + logger.Debugf("Try to update the node data failed. In most cases, it's not a problem. ") + } + } + return nil + } if err != nil { return err }