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

[BUG] Use the multi-registry feature with Nacos registry that set namingLoadCacheAtStart=true, the cache of NacosNamingService will overwrite each other #7822

Closed
2 tasks done
plusmancn opened this issue May 22, 2021 · 4 comments · Fixed by #8588
Labels
type/bug Bugs to being fixed

Comments

@plusmancn
Copy link
Contributor

  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked the FAQ of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: build from mater branch
  • Operating System version: Mac OSX
  • Java version: 1.8

Steps to reproduce this issue

When I use the multi-registry feature of Dubbo with setting namingLoadCacheAtStart=true(default is also true in Dubbo), the cache of NacosNamingService will overwrite each other.
If two registries have different services, some of the services will be lost because of overwriting.

For example, we have settings as below:

<dubbo:registry id="registryDev" address="nacos://127.0.0.1:8849?namingLoadCacheAtStart=true"/>
<dubbo:registry id="registryTest" address="nacos://127.0.0.1:8848?namingLoadCacheAtStart=true"/>

If registryStable overwrites registryDev, the consumer can't find the GreetingService in registryDev.
image

Expected Result

The different registry has different cache folder, so the cache will not overwrite each other.

PS: zookeeper works well with multi-registry feature of Dubbo.

Actual Result

The cache of NacosNamingService will overwrite each other.
If two registries have different services, some of the services will be lost because of overwriting.

@plusmancn
Copy link
Contributor Author

plusmancn commented May 22, 2021

Final Solution

  • Step1: Nacos support User-Defined cacheDir

I have submitted PRs to both Nacos Client v1.x and v2.x, see: alibaba/nacos#5747.
It will be released around July 2021.

  • Step2: Dubbo specify the cacheDir of Nacos

private static void setProperties(URL url, Properties properties) {
putPropertyIfAbsent(url, properties, NACOS_NAMING_LOG_NAME);
// @since 2.7.8 : Refactoring
// Get the parameters from constants
Map<String, String> parameters = url.getParameters(of(PropertyKeyConst.class));
// Put all parameters
properties.putAll(parameters);
putPropertyIfAbsent(url, properties, NAMING_LOAD_CACHE_AT_START, "true");
}

Try to Calculate the cacheDir path of Nacos Registry automatically, and then set it by properties.
The rule of generating cacheDir may base on Registry.id, Registry.address and etc.
The PR will be submitted once the Nacos 1.4.3 release.

Temporary Solution

Just set namingLoadCacheAtStart to false as follow mannully:

<dubbo:registry id="registryDev" address="nacos://127.0.0.1:8849?namingLoadCacheAtStart=false"/>
<dubbo:registry id="registryTest" address="nacos://127.0.0.1:8848?namingLoadCacheAtStart=false"/>

@AlbumenJ AlbumenJ added Notification type/bug Bugs to being fixed labels May 22, 2021
@plusmancn plusmancn mentioned this issue Aug 24, 2021
8 tasks
@plusmancn
Copy link
Contributor Author

plusmancn commented Aug 24, 2021

How to use it.

From Dubbo 3.0.2(which Nacos dependency 2.0.2), just set namingCacheRegistryDir to different sub dir, if you want to avoid NamingCache overwriting each other, for example:

<dubbo:registry id="registryDev" address="nacos://127.0.0.1:8849?namingCacheRegistryDir=sub1"/>
<dubbo:registry id="registryTest" address="nacos://127.0.0.1:8848?namingCacheRegistryDir=sub2"/>

@AlbumenJ
Copy link
Member

@plusmancn Could you please help to add some description related with this issue to apache/dubbo-website ?

@plusmancn
Copy link
Contributor Author

@plusmancn Could you please help to add some description related with this issue to apache/dubbo-website ?

I will

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Bugs to being fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants