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

TreeMapConsistentHash存在一个Bug #79

Closed
b1lz9 opened this issue Mar 9, 2020 · 2 comments · Fixed by #90 or #147
Closed

TreeMapConsistentHash存在一个Bug #79

b1lz9 opened this issue Mar 9, 2020 · 2 comments · Fixed by #90 or #147
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers

Comments

@b1lz9
Copy link

b1lz9 commented Mar 9, 2020

这是TreeMap的源码.

public class TreeMapConsistentHash extends AbstractConsistentHash {
    private TreeMap<Long,String> treeMap = new TreeMap<Long, String>() ;

    /**
     * 虚拟节点数量
     */
    private static final int VIRTUAL_NODE_SIZE = 2 ;

    @Override
    public void add(long key, String value) {
        for (int i = 0; i < VIRTUAL_NODE_SIZE; i++) {
            Long hash = super.hash("vir" + key + i);
            treeMap.put(hash,value);
        }
        treeMap.put(key, value);
    }

这里存在一个bug啊,当有一个节点下线时,虽然ServerCache更新了,
但这里的treeMap里面的数据是一直存在的.那么在获取路由时就会获取到已经下了线的Netty服务器地址.

@crossoverJie crossoverJie added bug Something isn't working enhancement New feature or request good first issue Good for newcomers labels Mar 9, 2020
@crossoverJie
Copy link
Owner

收到,近期会修复。

@lionjumpma
Copy link

那现在这个add方法在clear了以后不是任何时候都只有一个了吗。

@crossoverJie crossoverJie linked a pull request Sep 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants