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 #4344] cacheMap property optimization #4353
Conversation
wangxiaowei14227 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
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.
You need use nacos code style to reformat your change files first.
Please see style/codeStyle.md
in source code
为什么我没有修改其他的源代码,但是checkstyle却无法通过?
…------------------ 原始邮件 ------------------
发件人: "杨翊 SionYang"<notifications@github.com>;
发送时间: 2020年11月27日(星期五) 下午5:06
收件人: "alibaba/nacos"<nacos@noreply.github.com>;
抄送: "炮打资产阶级司令部"<2484713618@qq.com>; "Author"<author@noreply.github.com>;
主题: Re: [alibaba/nacos] issues #4344 (#4353)
@KomachiSion requested changes on this pull request.
You need use nacos code style to reformat your change files first.
Please see style/codeStyle.md in source code
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
} | ||
|
||
// reset so that server not hang this check | ||
lastCacheData.setInitializing(true); |
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.
if lastCacheData == null
you can't set CacheData.Initializing =true
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.
lastCacheData not null
**CacheData cacheData = new CacheData(configFilterChainManager, agent.getName(), dataId, group, tenant);**
if (lastCacheData == null) {
//fix issue # 1317
if (enableRemoteSyncConfig) {
String[] ct = getServerConfig(dataId, group, tenant, 3000L);
cacheData.setContent(ct[0]);
}
**lastCacheData = cacheData;**
}
``
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 are some different with old logic.
In old logic, it seems that only not new cacheData need to set Initializing.
But in your new logic, all cacheData what ever old or new will set Initializing. It might cause bugs.
CacheData cacheFromMap = getCache(dataId, group);
// multiple listeners on the same dataid+group and race condition,so double check again
//other listener thread beat me to set to cacheMap
if (null != cacheFromMap) { // the cache data from cache, means it is old cache
cache = cacheFromMap; // set cache as old cache
//reset so that server not hang this check
cache.setInitializing(true); // set old cache Initializing
} else {
int taskId = cacheMap.get().size() / (int) ParamUtil.getPerTaskConfigSize();
cache.setTaskId(taskId);
}
CacheData cacheData = new CacheData(configFilterChainManager, agent.getName(), dataId, group);
CacheData lastCacheData = cacheMap.putIfAbsent(key, cacheData);
if (lastCacheData == null) { // old cache non-exist
...
lastCacheData = cacheData; // set old cache as new cache
...
}
lastCacheData.setInitializing(true); // set new cache Initializing,
} | ||
|
||
// reset so that server not hang this check | ||
lastCacheData.setInitializing(true); |
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.
Same as above
您修改了这一个文件,然后用的idea的reformat功能,可能不是您手动而是idea自动触发的,由于codeStyle设置的不同,导致您改动了文件的其他地方的codestyle,所以checkstyle就通不过了, 还是建议您看一下源码目录下 style/codeStyle.ms 设置一下codestyle。 然后再手动把这个文件reformat一下,重新提交。 |
@@ -64,6 +64,7 @@ | |||
* | |||
* @author Nacos | |||
*/ | |||
@SuppressWarnings("checkstyle:EmptyLineSeparator") |
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.
没有特殊原因,不要使用@SuppressWarnings,请按照规定修复code-style问题
@@ -65,9 +65,9 @@ | |||
* @author Nacos | |||
*/ | |||
public class ClientWorker implements Closeable { | |||
|
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一次应该就不会出现这种改动了。
CacheData cache = getCache(dataId, group); | ||
if (null != cache) { | ||
return cache; | ||
} |
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.
I think this part logic can't be remove.
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.
why? putIfAbsent将会返回old value。
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.
如果能get到old value,下面一堆逻辑其实都不需要执行了吧。
} | ||
|
||
// reset so that server not hang this check | ||
lastCacheData.setInitializing(true); |
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 are some different with old logic.
In old logic, it seems that only not new cacheData need to set Initializing.
But in your new logic, all cacheData what ever old or new will set Initializing. It might cause bugs.
CacheData cacheFromMap = getCache(dataId, group);
// multiple listeners on the same dataid+group and race condition,so double check again
//other listener thread beat me to set to cacheMap
if (null != cacheFromMap) { // the cache data from cache, means it is old cache
cache = cacheFromMap; // set cache as old cache
//reset so that server not hang this check
cache.setInitializing(true); // set old cache Initializing
} else {
int taskId = cacheMap.get().size() / (int) ParamUtil.getPerTaskConfigSize();
cache.setTaskId(taskId);
}
CacheData cacheData = new CacheData(configFilterChainManager, agent.getName(), dataId, group);
CacheData lastCacheData = cacheMap.putIfAbsent(key, cacheData);
if (lastCacheData == null) { // old cache non-exist
...
lastCacheData = cacheData; // set old cache as new cache
...
}
lastCacheData.setInitializing(true); // set new cache Initializing,
new CacheData 的isInitializing 属性是true,所以我觉得可以减少一次判断 |
// multiple listeners on the same dataid+group and race condition | ||
CacheData lastCacheData = cacheMap.putIfAbsent(key, cacheData); | ||
if (lastCacheData == null) { | ||
//fix issue # 1317 |
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.
这里没有设置taskId
int taskId = cacheMap.size() / (int) ParamUtil.getPerTaskConfigSize();
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.
这里develop分支也么有设置taskId,默认都是0。
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.
这个需要设置的,不设置是无法进行长轮询的,这里应该是个bug,在2.0里面已经得到修复了
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.
addCacheDataIfAbsent(String dataId, String group, String tenant) 新增的时候没有设置taskId
int taskId = cacheMap.size() / (int) ParamUtil.getPerTaskConfigSize();
@chuntaojun @paderlol Please double check again. @TsingLiang Please make sure this refactor will not affect the runtime. @christophe-liwei I found that your commit user is not your github id. So the CLA can't pass. Please re-head your commit and set your git user and email as your githubid and github email, otherwise CLA no sign we can't merge this PR. |
Still no right for commit log user, and CLA still pending. If you don't know how to fix this problem. You can close PR, and checkout a new branch from |
如何签署cla |
你已经签署了, 但是你的git 提交记录还有你以前本地用户 如果你不知道如何去掉那些提交,建议重新从develop重新拉一个分支,然后重新用github的user和email作为提交用户再提交一次,重新创建一个PR。这样就不会有问题。 |
@KomachiSion 好的 |
#4344
The
cacheMap
attribute in ClientWorker now uese an instance lock, which can be reduced byputIfAbsent
from ConcurrentHashMap.