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

服务节点集群部署,hash算法选择节点时bug #116

Open
139446702556 opened this issue Dec 28, 2020 · 1 comment
Open

服务节点集群部署,hash算法选择节点时bug #116

139446702556 opened this issue Dec 28, 2020 · 1 comment

Comments

@139446702556
Copy link

139446702556 commented Dec 28, 2020

SortArrayMapConsistentHash:
public void add(long key, String value) {
// fix #79
sortArrayMap.clear();
for (int i = 0; i < VIRTUAL_NODE_SIZE; i++) {
Long hash = super.hash("vir" + key + i);
sortArrayMap.add(hash,value);
}
sortArrayMap.add(key, value);
}
TreeMapConsistentHash:
public void add(long key, String value) {

    // fix https://github.com/crossoverJie/cim/issues/79
    treeMap.clear();
    for (int i = 0; i < VIRTUAL_NODE_SIZE; i++) {
        Long hash = super.hash("vir" + key + i);
        treeMap.put(hash,value);
    }
    treeMap.put(key, value);
}

master分支上的这两个hash的存储方式的add方法会导致集群部署时,始终只会从最后一个节点中的三个虚拟节点选择,而其他节点都被clear掉了

@alun2kb
Copy link

alun2kb commented Jan 15, 2021

哇,刚好在尝试部署多台 server,感谢指出避坑!

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

2 participants