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

计算 slot 的小问题 #1

Open
NoahNyy opened this issue Jul 12, 2023 · 2 comments
Open

计算 slot 的小问题 #1

NoahNyy opened this issue Jul 12, 2023 · 2 comments

Comments

@NoahNyy
Copy link

NoahNyy commented Jul 12, 2023

StringHashUtil.index 方法,按照文章介绍这里不是取模吗? 但代码好像直接是除法了

    public static int index(int slot, int shardingCount) {
        int segment = 1024 / shardingCount;
        int index = slot / segment;
        return index;
    }
@makemyownlife
Copy link
Owner

我的思路是这样的:假如有四个分片,segment = 1024/4 = 256 , slot 是对 1024取余 ,所以 slot / segment = 该 shardingkey 对应的分片。

@durantgod
Copy link

durantgod commented Sep 25, 2024

@makemyownlife 勇哥,这个地方我提交了个一致性hash算法实现,你那种写法,如果后面新增或者减少节点,会对存量数据有较大的影响。

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

3 participants