TarsJava icon indicating copy to clipboard operation
TarsJava copied to clipboard

主控节点异常时无法使用本地缓存

Open beyondhc opened this issue 2 years ago • 0 comments

`private void updateServantEndpoints(ServantProxyConfig cfg) { CommunicatorConfig communicatorConfig = communicator.getCommunicatorConfig();

    String endpoints = null;
    if (!ParseTools.hasServerNode(cfg.getObjectName()) && !cfg.isDirectConnection() && !communicatorConfig.getLocator().startsWith(cfg.getSimpleObjectName())) {
        try {
            /** query server nodes from registerServer */
            if (RegisterManager.getInstance().getHandler() != null) {
                endpoints = ParseTools.parse(RegisterManager.getInstance().getHandler().query(cfg.getSimpleObjectName()),
                        cfg.getSimpleObjectName());
            } else {
                endpoints = communicator.getQueryHelper().getServerNodes(cfg);
            }
            if (StringUtils.isEmpty(endpoints)) {
                throw new CommunicatorConfigException(cfg.getSimpleObjectName(), "servant node is empty on get by registry! communicator id=" + communicator.getId());
            }
            ServantCacheManager.getInstance().save(communicator.getId(), cfg.getSimpleObjectName(), endpoints, communicatorConfig.getDataPath());
        } catch (CommunicatorConfigException e) {
            /** If it fails, pull it from the local cache  file */
            endpoints = ServantCacheManager.getInstance().get(communicator.getId(), cfg.getSimpleObjectName(), communicatorConfig.getDataPath());
            logger.error(cfg.getSimpleObjectName() + " error occurred on get by registry, use by local cache=" + endpoints + "|" + e.getLocalizedMessage(), e);
        }

        if (StringUtils.isEmpty(endpoints)) {
            throw new CommunicatorConfigException(cfg.getSimpleObjectName(), "error occurred on create proxy, servant endpoint is empty! locator =" + communicatorConfig.getLocator() + "|communicator id=" + communicator.getId());
        }
        cfg.setObjectName(endpoints);
    }

    if (StringUtils.isEmpty(cfg.getObjectName())) {
        throw new CommunicatorConfigException(cfg.getSimpleObjectName(), "error occurred on create proxy, servant endpoint is empty!");
    }
}`

@TimmyYu 此处从查询节点返回节点为空才会进入CommunicatorConfigException异常分支使用本地缓存,如果主控服务down机,getServerNodes()报TimeoutException @@时则无法catch异常,导致无法使用本地缓存。这里catch CommunicatorConfigException 是否可以使用Throwable,当从主控 查询节点信息异常或者为空时均使用本地缓存

beyondhc avatar Mar 01 '23 03:03 beyondhc