-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Optimize checkLocalConfig logic #11869
base: develop
Are you sure you want to change the base?
Conversation
LGTM |
Please sign CLA first. |
done |
The PR title may need to be updated to English. |
boolean failOverFileCreated = !cacheData.isUseLocalConfigInfo() && file.exists(); | ||
|
||
// using local config info, but there is a change in local configuration | ||
boolean failOverFileChanged= cacheData.isUseLocalConfigInfo() && file.exists() && cacheData.getLocalConfigInfoVersion() != file.lastModified(); |
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.
= 号空格不一致
看上去是个负优化,原本比较清晰的逻辑,现在要看懂得不断的上下去找逻辑。当一个变量需要大段的注释去解释它的作用的时候要么是变量名字起的不好,要么是就不该用变量
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的初学者经验不足,我一开始看到这段逻辑的时候觉得很迷惑,不太知道是否使用本地配置、文件是否存在、版本号是否一致等条件组合在一起的含义,后来仔细阅读才得以明确。于是我按照我阅读代码得到的理解把if括号中的内容提取成变量,相应的注释也提取成变量的注释,消除了冗余的逻辑,并且用一个比较直观的名字来命名这个变量,其实这个注释完全可以不要的
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.
可以思考一下,failOverFileCreated
和 failOverFileChanged
对于使用的地方都是一样的处理逻辑,而 failOverFileDeleted
又是另一段逻辑,那是不是可以更抽象一下。
envName, dataId, group, tenant, md5, ContentUtils.truncateContent(content)); | ||
return; | ||
"[{}] [failover-change] failover file {}. dataId={}, group={}, tenant={}, md5={}, content={}", | ||
failOverFileCreated ? "created" : "changed", envName, dataId, group, tenant, md5, ContentUtils.truncateContent(content));; |
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.
多余的分号
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.
我重新读了一下逻辑, 这个重构后的逻辑颠覆了之前的设计理念。
之前之所以不使用变量,是为了在获取failover后, 再次进行文件存在的校验,换句话说进行了至少2次的文件存在校验。
而重构后的逻辑,只进行了一次校验,同时时间上也不太正确。
原: 是否存在 -》 存在读取 -〉 再次校验-》存在则使用,不存在则不使用。
新: 是否存在 -〉 是否删除 -> 存在读取 -> 删除则不使用。
这可能导致某些极端情况下和之前的客户端会有不同的行为, 我的建议是把校验逻辑和通用逻辑抽象成方法, 而不是只用变量存储,并且不建议修改顺序。
fix checkstyle pls. |
好的,考虑的好细致,感谢提醒 |
2. 恢复之前的校验顺序 3. 抽象通用逻辑
@@ -866,44 +866,54 @@ public void checkLocalConfig(CacheData cacheData) { | |||
final String group = cacheData.group; | |||
final String tenant = cacheData.tenant; | |||
final String envName = cacheData.envName; | |||
|
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-code-style进行reformat, 不需要删除缩紧
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.
done
|
||
// If use local config info, but the failover file is deleted, switch back to server config. | ||
if (cacheData.isUseLocalConfigInfo() && !file.exists()) { | ||
|
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.
同上
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.
done
@KomachiSion 请问这个pr合并之前还有什么我需要改动的吗 |
CICD通过的话就可以合并了 |
现在应该通过了? |
hi,麻烦帮忙合并一下? |
Please do not create a Pull Request without creating an issue first.
What is the purpose of the change
issue:#11866
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.