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] When Service Discovery is enabled, the same registryId may create two ServiceDiscoveryRegistry #14347

Open
3 of 4 tasks
huisman6 opened this issue Jun 19, 2024 · 2 comments
Labels
component/need-triage Need maintainers to triage type/need-triage Need maintainers to triage

Comments

@huisman6
Copy link

Pre-check

  • I am sure that all the content I provide is in English.

Search before asking

  • I had searched in the issues and found no similar issues.

Apache Dubbo Component

Java SDK (apache/dubbo)

Dubbo Version

dubbo3.2.12 , jdk17

Steps to reproduce this issue

We have a Dubbo 3.2 service provider that is also a Dubbo Consumer. With application-level Service Discovery enabled, the same registryId creates two ServiceDiscoveryRegistry after ServiceConfig #doExportUrl and RefrenceConfig#refer.

I created a reproducible Dubbo application, the configuration of application-level Service Discovery is as follows:

dubbo:
  application:
    name: dubbo-playground
    metadata-type: local
    register-mode: instance
    migration.step: FORCE_APPLICATION
  registry:
    id: registry-multiple
    address: default://localhost:8848
    use-as-config-center: false
    use-as-metadata-center: false
    register-mode: instance
    parameters:
      registry-type: service

Our application supports dynamically adjusting instance weights, warm-up duration, and other service discovery metadata through the Http Endpoint runtime.

When the instance metadata changes, it triggers instance re-registration or update. In the underlying implementation, all discovery registries are obtained through RegistryManager#getServiceDiscoveries and its API is called.

Now the same registryId creates two ServiceDiscoveryRegistry, which means that we need to update the metadata once and send two requests to the same service discovery registry.

ServiceDiscoveryRegistry created twice because ServiceDiscoveryRegistryFactory registry cache key contains the full url parameter.

public class ServiceDiscoveryRegistryFactory extends AbstractRegistryFactory {

    @Override
    protected String createRegistryCacheKey(URL url) {
        return url.toFullString();
    }
 }

When ServiceConfig exports the service, it adds a URL parameter register = false.

private void doExportUrl(URL url, boolean withMetaData, RegisterTypeEnum registerType) {
    if (!url.getParameter(REGISTER_KEY, true)) {
        registerType = RegisterTypeEnum.MANUAL_REGISTER;
    }
    if (registerType == RegisterTypeEnum.NEVER_REGISTER
            || registerType == RegisterTypeEnum.MANUAL_REGISTER
            || registerType == RegisterTypeEnum.AUTO_REGISTER_BY_DEPLOYER) {
        url = url.addParameter(REGISTER_KEY, false);
    }

However, when using ReferenceConfig#createInvoker, there is no parameter register = false in the Registry URL, resulting in two cache keys.

What you expected to happen

Is it possible to adjust the registry cache key to the following code to ensure that the same registryId always returns the same ServiceDiscoveryRegistry?

protected String createRegistryCacheKey(URL url) {
    String registryCluster=url.getParameter(RegistryConstants.REGISTRY_CLUSTER_KEY);
    if (StringUtils.hasText(registryCluster)){
        return registryCluster;
    }
    return url.toFullString();
}

Anything else

No response

Are you willing to submit a pull request to fix on your own?

  • Yes I am willing to submit a pull request on my own!

Code of Conduct

@huisman6 huisman6 added component/need-triage Need maintainers to triage type/need-triage Need maintainers to triage labels Jun 19, 2024
@vishv843
Copy link

Hey, can I work on this?

@wcy666103
Copy link
Contributor

Hey, can I work on this?

Of course,go for it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/need-triage Need maintainers to triage type/need-triage Need maintainers to triage
Projects
Status: Todo
Development

No branches or pull requests

3 participants