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

ReferenceCache.get(ReferenceConfigBase<T>) 没有使用缓存,导致dubbo service的consumer节点持续增加 (zookeeper) #10012

Closed
saleson opened this issue May 7, 2022 · 3 comments
Labels
type/enhancement Everything related with code enhancement or performance
Milestone

Comments

@saleson
Copy link
Contributor

saleson commented May 7, 2022

Environment

  • Dubbo version: 3.5
  • Java version: 1.8

出现该问题的代码:

private static ReferenceCache refCache = SimpleReferenceCache.getCache();

public static GenericService getService(String serviceName, String version){
  ReferenceConfig<GeniricService> refConf = new ReferenceConfig();
  refConf.setProtocol("zookeeper");
  refConf.setAddress(registryAddress);
  refConf.setRegistry(registryConfig);
  refConf.setGeneric("true");
  refConf.setInterface(serviceName);
  refConf.setVersion(version);
  refConf.setTimeout(5000);
  return refCache.get(refConf);
}

Expected Behavior

从缓存中获取GenericService

Actual Behavior

SimpleReferenceCache.get()方法没有从缓存中获取,而是直接调用了ReferenceConfig.get(),且执行了ReferenceConfig.init()另外创建了新的GenericService, 在zookeeper上也在相应的service节点下添加了consumer节点

SimpleReferenceCache.get(ReferenceConfigBase):

    public <T> T get(ReferenceConfigBase<T> rc) {
        String key = generator.generateKey(rc);
        Class<?> type = rc.getInterfaceClass();
        Object proxy = rc.get();

        references.computeIfAbsent(rc, _rc -> {
            List<ReferenceConfigBase<?>> referencesOfType = referenceTypeMap.computeIfAbsent(type, _t -> Collections.synchronizedList(new ArrayList<>()));
            referencesOfType.add(rc);
            List<ReferenceConfigBase<?>> referenceConfigList = referenceKeyMap.computeIfAbsent(key, _k -> Collections.synchronizedList(new ArrayList<>()));
            referenceConfigList.add(rc);
            return proxy;
        });

        return (T) proxy;
    }

如果使用DubboBootstrap.getInstance().getCache().get(refConf);也会出现一样的情况,DubboBootstrap.getInstance().getCache()返回的是CompositeReferenceCache对象,而CompositeReferenceCache.get(ReferenceConfigBase)方法如下:

    public <T> T get(ReferenceConfigBase<T> referenceConfig) {
        return referenceConfig.get();
    }

可以看出,在CompositeReferenceCache.get(ReferenceConfigBase)方法和SimpleReferenceCache.get(ReferenceConfigBase)方法中都没有使用到缓存。

@saleson saleson added the type/bug Bugs to being fixed label May 7, 2022
@chickenlj chickenlj added this to the 3.0.9 milestone May 9, 2022
@chickenlj chickenlj added type/enhancement Everything related with code enhancement or performance and removed type/bug Bugs to being fixed labels May 9, 2022
@chickenlj
Copy link
Contributor

related #9829

@saleson
Copy link
Contributor Author

saleson commented May 9, 2022

#9829 修复了SimpleReferenceCache.get(ReferenceConfigBase)中的逻辑, CompositeReferenceCache.get(ReferenceConfigBase)方法仍是没有修复

@saleson
Copy link
Contributor Author

saleson commented May 12, 2022

@chickenlj 大佬,CompositeReferenceCache.get(ReferenceConfigBase)方法没有使用缓存的问题需要重新提个issue么?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Everything related with code enhancement or performance
Projects
None yet
Development

No branches or pull requests

2 participants