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

TagRouter的stream操作导致ConsistentHashLoadBalance每次都需要重新进行hash环的映射。 #5429

Closed
thisiswanghy opened this issue Dec 4, 2019 · 5 comments

Comments

@thisiswanghy
Copy link
Contributor

Environment

  • Dubbo version: 2.7.4.1

ConsistentHashLoadBalance 用到了 System.identityHashCode(invokers); 来判断 hash 值,从而判断是否有服务端的上下线操作。
而TagRouter的org.apache.dubbo.rpc.cluster.router.tag.TagRouter#filterUsingStaticTag方法中的 stream 操作会修改 invokers 的值,所以 ConsistentHashLoadBalance 受到了影响。
导致即使在服务端没有上下线操作的时候,一致性hash负载均衡算法每次都需要重新进行hash环的映射。

@thisiswanghy
Copy link
Contributor Author

#5424

@CodingSinger
Copy link
Member

i think should replace java.lang.System#identityHashCode with hashCode .
@chickenlj
what's your opinion?

@thisiswanghy
Copy link
Contributor Author

https://mp.weixin.qq.com/s/ctBM0WO-uWNlTWHI-TPniw
bug的详细描述

@kimmking
Copy link
Member

kimmking commented Dec 9, 2019

@CodingSinger I commit some comments for your bugfix.

CodingSinger added a commit to CodingSinger/dubbo that referenced this issue Dec 9, 2019
@LinShunKang
Copy link
Contributor

@beiwei30
In Dubbo 2.6.x branch, there is the same problem,TagRouter always return new List<Invoker<T>>:

public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
// filter
List<Invoker<T>> result = new ArrayList<Invoker<T>>();
// Dynamic param
String tag = RpcContext.getContext().getAttachment(Constants.TAG_KEY);
// Tag request
if (!StringUtils.isEmpty(tag)) {
// Select tag invokers first
for (Invoker<T> invoker : invokers) {
if (tag.equals(invoker.getUrl().getParameter(Constants.TAG_KEY))) {
result.add(invoker);
}
}
}
// If Constants.REQUEST_TAG_KEY unspecified or no invoker be selected, downgrade to normal invokers
if (result.isEmpty()) {
// Only forceTag = true force match, otherwise downgrade
String forceTag = RpcContext.getContext().getAttachment(Constants.FORCE_USE_TAG);
if (StringUtils.isEmpty(forceTag) || "false".equals(forceTag)) {
for (Invoker<T> invoker : invokers) {
if (StringUtils.isEmpty(invoker.getUrl().getParameter(Constants.TAG_KEY))) {
result.add(invoker);
}
}
}
}
return result;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants