Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair the cache pollution caused by v.tenat != clientConfig.NamespaceId #221

Merged
merged 1 commit into from
May 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clients/config_client/config_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func longPulling(taskId int) func() error {
}
for _, v := range initializationList {
v.isInitializing = false
cacheMap.Set(util.GetConfigCacheKey(v.dataId, v.group, clientConfig.NamespaceId), v)
cacheMap.Set(util.GetConfigCacheKey(v.dataId, v.group, v.tenant), v)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better solution might be to use a separate cacheMap for each ConfigClient

Copy link
Contributor Author

@zou2699 zou2699 Apr 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc1.NamespaceId="namespace1"
client, _ := clients.NewConfigClient(
    vo.NacosClientParam{
        ClientConfig:  cc1,
        ServerConfigs: sc,
    },
)

// key test-data-1@@test-group@@namespace1
_ = client.ListenConfig(vo.ConfigParam{
DataId:   "test-data-1",
Group:    "test-group",
OnChange: func(namespace, group, dataId, data string) {
                   //...
},
})

cc2 := new(constant.ClientConfig)
*cc2 = *cc1
cc2.NamespaceId="2"
client, _ = clients.NewConfigClient(
    vo.NacosClientParam{
        ClientConfig:  cc2,
        ServerConfigs: sc,
    },
)
// key test-data-2@@test-group@@namespace2
_ = client.ListenConfig(vo.ConfigParam{
DataId:   "test-data-2",
Group:    "test-group",
OnChange: func(namespace, group, dataId, data string) {
                   //...
},
})

/*
But cachemap keys may be 
[ test-data-1@@test-group@@namespace1,
  test-data-2@@test-group@@namespace2,
  test-data-2@@test-group@@namespace1,  // this is wrong
]
*/

}
if len(strings.ToLower(strings.Trim(changed, " "))) == 0 {
logger.Info("[client.ListenConfig] no change")
Expand Down