Skip to content

Commit

Permalink
Merge pull request apolloconfig#147 from zouyx/feature/FixConcurrency…
Browse files Browse the repository at this point in the history
…Problem

修复并发写 map
  • Loading branch information
zouyx committed Nov 13, 2020
2 parents 2fd2269 + c7c360e commit 047e235
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions env/file/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"fmt"
"github.com/zouyx/agollo/v4/env/config"
"sync"

"github.com/zouyx/agollo/v4/component/log"
jsonConfig "github.com/zouyx/agollo/v4/env/config/json"
Expand All @@ -35,6 +36,8 @@ var (
jsonFileConfig = &jsonConfig.ConfigFile{}
//configFileMap 存取namespace文件地址
configFileMap = make(map[string]string, 1)
//configFileMapLock configFileMap的读取锁
configFileMapLock sync.Mutex
)

// FileHandler 默认备份文件读写
Expand All @@ -49,6 +52,8 @@ func (fileHandler *FileHandler) WriteConfigFile(config *config.ApolloConfig, con
// GetConfigFile get real config file
func (fileHandler *FileHandler) GetConfigFile(configDir string, appID string, namespace string) string {
key := fmt.Sprintf("%s-%s", appID, namespace)
configFileMapLock.Lock()
defer configFileMapLock.Unlock()
fullPath := configFileMap[key]
if fullPath == "" {
filePath := fmt.Sprintf("%s%s", key, Suffix)
Expand Down

0 comments on commit 047e235

Please sign in to comment.