Skip to content

Commit

Permalink
Fix: do not copy sync.Map
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStocks committed Jul 2, 2019
1 parent bd297e8 commit 1178d9a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
17 changes: 13 additions & 4 deletions common/config/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,40 @@ func (env *Environment) UpdateExternalConfigMap(externalMap map[string]string) {
func (env *Environment) Configuration() *list.List {
list := list.New()
memConf := newInmemoryConfiguration()
memConf.setProperties(env.externalConfigMap)
memConf.setProperties(&(env.externalConfigMap))
list.PushBack(memConf)
return list
}

type InmemoryConfiguration struct {
store sync.Map
store *sync.Map
}

func newInmemoryConfiguration() *InmemoryConfiguration {
return &InmemoryConfiguration{}
}
func (conf *InmemoryConfiguration) setProperties(p sync.Map) {
func (conf *InmemoryConfiguration) setProperties(p *sync.Map) {
conf.store = p
}

func (conf *InmemoryConfiguration) GetProperty(key string) (bool, string) {
if conf.store == nil {
return false, ""
}

v, ok := conf.store.Load(key)
if ok {
return true, v.(string)
}
return false, ""

return false, ""
}

func (conf *InmemoryConfiguration) GetSubProperty(subKey string) map[string]struct{} {
if conf.store == nil {
return nil
}

properties := make(map[string]struct{})
conf.store.Range(func(key, value interface{}) bool {
if idx := strings.Index(key.(string), subKey); idx >= 0 {
Expand All @@ -100,5 +108,6 @@ func (conf *InmemoryConfiguration) GetSubProperty(subKey string) map[string]stru
}
return true
})

return properties
}
4 changes: 2 additions & 2 deletions config/registry_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ type RegistryConfig struct {
Group string `yaml:"group" json:"group,omitempty" property:"group"`
//for registry
Address string `yaml:"address" json:"address,omitempty" property:"address"`
Username string `yaml:"username" json:"address,omitempty" property:"username"`
Password string `yaml:"password" json:"address,omitempty" property:"password"`
Username string `yaml:"username" json:"username,omitempty" property:"username"`
Password string `yaml:"password" json:"password,omitempty" property:"password"`
}

func (*RegistryConfig) Prefix() string {
Expand Down
6 changes: 3 additions & 3 deletions remoting/zookeeper/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ func (l *ZkEventListener) handleZkNodeEvent(zkPath string, children []string, li
continue
}
// listen l service node
go func(node string) {
go func(node, childNode string) {
logger.Infof("delete zkNode{%s}", node)
if l.ListenServiceNodeEvent(node, listener) {
logger.Infof("delete content{%s}", n)
logger.Infof("delete content{%s}", childNode)
listener.DataChange(remoting.Event{Path: zkPath, Action: remoting.EventTypeDel})
}
logger.Warnf("listenSelf(zk path{%s}) goroutine exit now", zkPath)
}(newNode)
}(newNode, n)
}

// old node was deleted
Expand Down

0 comments on commit 1178d9a

Please sign in to comment.