-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
[ISSUE #12189] Refactor Client SDK. #12432
Conversation
第一次尝试提交PR, 希望大佬能够review指点一下, 非常感谢🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看起来有不少冲突,您的PR基于的基础分支应该比较老旧了, 建议尽快更新一下。
目前相对其他PR比较好的点:
- 保留了请求地址服务器时Header的语意。
- 通过ServerListHolder分离了Endpoint和ServerAddr的逻辑。
目前有问题的点:
- 配置中心ClientWorker和注册中心的HttpProxy的逻辑改动可能导致和以前的逻辑不一致,有风险
- 有些地址服务器相关参数过旧需要更新
- 地址服务器逻辑中缺少对queryParameter的支持(可以查看当前的配置中心部分的地址服务器寻址逻辑)
待确认:
- 同时传入endpoint和serverAddr, 但从endpoint中获取到了返回码200, 但是为空列表时,是否和现在的逻辑不一致
serverListMgr.getCurrentServerAddr(), result.getCode()); | ||
} else { | ||
// Update the currently available server addr | ||
serverListMgr.updateCurrentServerAddr(currentServerAddr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个逻辑是配置中心为了保持一个访问同一只可访问的server而保持的逻辑, 我看你下面的acquireNextServer并没有保留这个逻辑,但是又移除了, 可能有点问题。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个逻辑是配置中心为了保持一个访问同一只可访问的server而保持的逻辑, 我看你下面的acquireNextServer并没有保留这个逻辑,但是又移除了, 可能有点问题。
这里是复用Naming模块的nextServer逻辑基于currentIndex, 在失败重试获取的逻辑里面会递增index, 应该不会导致Server下次访问会变动?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
配置和服务的一致性协议有所区别, 配置中心应该是尽可能保证访问到同一个节点上,注册中心可以随机分配。
因此这个逻辑之前时放在agent里和proxy里,没有放在地址服务器里。
既然这次是重构地址服务器,就不要改动外层agent和proxy的逻辑。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
配置和服务的一致性协议有所区别, 配置中心应该是尽可能保证访问到同一个节点上,注册中心可以随机分配。
因此这个逻辑之前时放在agent里和proxy里,没有放在地址服务器里。
既然这次是重构地址服务器,就不要改动外层agent和proxy的逻辑。
是的, 这里在重试genNextServer()
找到可用Server后下标固定还是这个Server, 所以移除了updateCurrentServerAddr()
, 注册中心则还是沿用以前的逻辑在构建时随机指定了一个下标。
@@ -24,7 +24,10 @@ | |||
* @author onew | |||
*/ | |||
public class Constants { | |||
|
|||
public static final String ENDPOINT_NAME = "endpoint"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么不复用com.alibaba.nacos.api.PropertyKeyConst?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么不复用com.alibaba.nacos.api.PropertyKeyConst?
这里是因为觉得有语意问题, 这个常量类都是用作NacosClientProperties在使用的.
if (NAMING_LOGGER.isDebugEnabled()) { | ||
NAMING_LOGGER.debug("request {} failed.", server, e); | ||
} | ||
Random random = new Random(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有个问题, 如果这样修改了, 是否会导致如果只输入一个域名或ip的情况下, 客户端失去了失败重试的能力。
continue; | ||
} | ||
List<String> serverList = delegate.initServerList(properties); | ||
if (CollectionUtils.isNotEmpty(serverList)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
问个问题, 如果我同时输入endpoint,和serverAddr, 但是endpoint的地址返回的是空列表(内容为空列表,状态码为200), 是否和原先的寻址逻辑不符合?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
问个问题, 如果我同时输入endpoint,和serverAddr, 但是endpoint的地址返回的是空列表(内容为空列表,状态码为200), 是否和原先的寻址逻辑不符合?
确实不符合, 我再优化一下, 只考虑重构没有考虑到兼容版本问题
if (!StringUtils.isBlank(contentPathTmp)) { | ||
this.contentPath = contentPathTmp; | ||
} | ||
String serverListNameTmp = properties.getProperty(PropertyKeyConst.CLUSTER_NAME); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参数名已在2.3.3版本修改,请更新最新的代码。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参数名已在2.3.3版本修改,请更新最新的代码。
非常抱歉, 没有确认分支就开始开发, 我更新再优化一下
if (StringUtils.isNotEmpty(endpoint)) { | ||
this.namespace = properties.getProperty(PropertyKeyConst.NAMESPACE); | ||
this.moduleName = properties.getProperty(PropertyKeyConst.MODULE_NAME); | ||
String contentPathTmp = properties.getProperty(PropertyKeyConst.CONTEXT_PATH); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CONTEXT_PATH的逻辑也有修改,请同步
# Conflicts: # client/src/main/java/com/alibaba/nacos/client/config/impl/ServerListManager.java # client/src/main/java/com/alibaba/nacos/client/naming/core/ServerListManager.java # client/src/test/java/com/alibaba/nacos/client/config/NacosConfigServiceTest.java # client/src/test/java/com/alibaba/nacos/client/config/http/ServerHttpAgentTest.java # client/src/test/java/com/alibaba/nacos/client/config/impl/ClientWorkerTest.java # client/src/test/java/com/alibaba/nacos/client/config/impl/ServerListManagerTest.java # client/src/test/java/com/alibaba/nacos/client/naming/remote/http/NamingHttpClientProxyTest.java # client/src/test/java/com/alibaba/nacos/client/naming/utils/ServerDiscoveryHttpUtilTest.java # client/src/test/java/com/alibaba/nacos/client/serverlist/ServerListManagerTest.java
更新了一下, 也烦请大佬有空review一下 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉上问题已经快收敛完了, 再看下评论进行一次修改。
另外有一个问题可以思考下:
moduleName时通过单独的参数传递进去还是方properties里比较好?
我感觉放properties有一点晦涩,直接传进去是不是明显一点。
serverListMgr.getCurrentServerAddr(), result.getCode()); | ||
} else { | ||
// Update the currently available server addr | ||
serverListMgr.updateCurrentServerAddr(currentServerAddr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
配置和服务的一致性协议有所区别, 配置中心应该是尽可能保证访问到同一个节点上,注册中心可以随机分配。
因此这个逻辑之前时放在agent里和proxy里,没有放在地址服务器里。
既然这次是重构地址服务器,就不要改动外层agent和proxy的逻辑。
NacosException exception = new NacosException(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请使用nacos codestyle来reformat code, 不要修改缩进
if (null != refreshServerListExecutor) { | ||
ThreadUtils.shutdownThreadPool(refreshServerListExecutor, NAMING_LOGGER); | ||
} | ||
NamingHttpClientManager.getInstance().shutdown(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
地址服务器应该处于更底层的逻辑,依赖NamingHttpClientManager可能不是很合适。
以及日志也打印在NAMING_LOGGER也不是很合适,
日志可以打印到REMOTE_LOGGER里, http访问可以通过NacosRestTemplate来替代。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
地址服务器应该处于更底层的逻辑,依赖NamingHttpClientManager可能不是很合适。 以及日志也打印在NAMING_LOGGER也不是很合适,
日志可以打印到REMOTE_LOGGER里, http访问可以通过NacosRestTemplate来替代。
是的, 作为底层逻辑不应该依赖上层业务 我更正一下
owner = delegate; | ||
return serverList; | ||
} | ||
throw new NacosLoadException("serverList is empty,please check configuration"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以将NacosServerListHolder对应的class或name包含在异常中。这样提示信息能看到是目前是哪个类型被应用了,但是没获取到服务列表。
# db.password=nacos | ||
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC | ||
db.user=root | ||
db.password=118756 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
本地配置不用一起提交
确实, 看一下是有点晦涩,这个属性我觉得应该是必要属性要依赖方感知和设置这个属性, 放properties的话貌似还需要去理解上下文这个属性的作用, 假设另一个模块引用的话可能是不知道这个属性的. |
更正了一版, 对于 |
boolean isFixServer = agent.serverListManager.isFixed; | ||
metric.put("isFixedServer", isFixServer); | ||
metric.put("addressUrl", agent.serverListManager.addressServerUrl); | ||
metric.put("addressUrl", agent.serverListManager.getUrlString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个逻辑不一样吧, 之前的这个记录的是地址服务器的信息,现在变成了获取到的地址。
metric.put("serverUrls", agent.serverListManager.getUrlString()); | ||
|
||
String serverListHolderName = agent.serverListManager.getServerListHolderName(); | ||
metric.put("isFixedServer", FixedConfigNacosServerListHolder.NAME.equals(serverListHolderName)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用方还需要感知类型不太好。
@@ -119,7 +118,7 @@ private void init(Properties properties) throws NacosException { | |||
private void initLogName(NacosClientProperties properties) { | |||
logName = properties.getProperty(UtilAndComs.NACOS_NAMING_LOG_NAME, DEFAULT_NAMING_LOG_FILE_PATH); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请勿修改缩进。
@@ -372,7 +370,7 @@ public String reqApi(String api, Map<String, String> params, Map<String, String> | |||
} else { | |||
Random random = new Random(); | |||
int index = random.nextInt(servers.size()); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
缩进问题请全部检查一下
* @param properties nacos client properties | ||
* @return | ||
*/ | ||
public static String initContextPath(NacosClientProperties properties) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个方法名最好叫initEndpointContextPath,不然之后的开发者可能会误解。
@XiaZhouxx 您好, 我收到主办方的消息, 说您的PR没有在活动官网上登记, 这样的话这个PR不算是有效的参赛PR, 方便抽空把报名信息在官网上填写一下。 对填写有疑问也可以发邮件到 [email protected] 询问。 |
收到, 已经填报PR, 代码也重新格式化排版 @KomachiSion 也烦请大佬抽空看一下 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前初步review似乎没有太大的问题了, 之后会在活动截止前对PR进行整体评判后决定是否合入。
我先跑一下CI,请关注一下结果,避免后续需要合入时由于CI问题被阻塞。
好的, 辛苦了 |
@KomachiSion 抱歉大佬有几个文件没有添加 |
根据最后的评分结果, #12274 会被合并入主干分支, 感谢参赛同学的贡献,该PR也有很多可取之处, 欢迎继续贡献此模块内容,将这部分内容优化的更好。 |
Please do not create a Pull Request without creating an issue first.
What is the purpose of the change
client sdk 寻址逻辑重构.
Brief changelog
XX
Verifying this change
XXXX
Follow this checklist to help us incorporate your contribution quickly and easily:
[ISSUE #123] Fix UnknownException when host config not exist
. Each commit in the pull request should have a meaningful subject line and body.mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true
to make sure basic checks pass. Runmvn clean install -DskipITs
to make sure unit-test pass. Runmvn clean test-compile failsafe:integration-test
to make sure integration-test pass.本改动借助了通灵义码进行辅助编程