在Voldemort中,为什么哈希环只能扩展到2^31-1?

发布于 2024-11-30 01:51:42 字数 500 浏览 6 评论 0原文

在项目 voldemort 设计页面上:

http://project-voldemort.com/design.php

说明哈希环覆盖区间[0, 2^31-1]。

现在,区间 [0, 2^31-1] 表示总共 2^31 个数字,最大的数字 2^31-1 只是 31 位全部设置为 1。(为了让自己相信这一点,请考虑 2^3- 1. 2^3=8 为 0x1000。2^3-1=7 为 0x111)。

因此,如果使用普通的 32 位地址字来存储该值,则有 1 位空闲。

因此,为什么 2^31-1 是上限?这个额外的位是否用于某种系统簿记?

(例如,1 个额外位将为安全地添加两个有效哈希地址而不会溢出提供空间)。

最后,这个选择是 Voldemort 特有的,还是在其他一致性哈希方案中也看到过?

On the project voldemort design page:

http://project-voldemort.com/design.php

It is stated that the hash ring covers the interval [0, 2^31-1].

Now, the interval [0, 2^31-1] represents 2^31 total numbers, and the largest number 2^31-1 is just 31 bits all set to 1. (To convince yourself of this, consider 2^3-1. 2^3=8 and is 0x1000. 2^3-1=7 and is 0x111).

Thus, if a normal 32-bit address word is used to store the value, you have 1 bit free.

Thus, why is 2^31-1 the upper limit? Is that extra bit used for some kind of system bookkeeping?

(e.g. 1 extra bit would provide room for safely adding two valid hash addresses without overflow).

And finally, is this choice specific to voldemort, or is it seen in other consistent hashing schemes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如果没结果 2024-12-07 01:51:42

我认为你只有 1 位空闲,而不是 2 位。 -1 说明它以数字“0”而不是 1 开头(同样的原因循环从 0 计数到 count-1)。我猜他们使用 2^31 而不是 2^32 的原因是他们使用有符号整数,因此最后一位是符号位,因此不可用。

编辑:
从您链接的页面:

为了可视化一致性哈希方法,我们可以看到可能的情况
整数哈希值作为从 0 开始并循环到的环
2^31-1。

它指定一个整数,因此除非您想要负哈希值,否则您只能使用 2^31 而不是 2^32。

I think you only have 1 bit free not 2. The -1 accounts for the fact that it starts with the number '0' instead of 1 (the same reason loops count from 0 to count-1). I would guess the reason they use 2^31 instead of 2^32 is that they're using a signed integer so that last bit is the sign bit and so is not useable.

Edit:
From the page you linked:

To visualize the consistent hashing method we can see the possible
integer hash values as a ring beginning with 0 and circling around to
2^31-1.

It specifies an integer so unless you want negative hash values you're stuck with 2^31 instead of 2^32.

李不 2024-12-07 01:51:42

回答问题有点晚了,仅仅晚了 4 年:)

原因是 Voldemort 是用 Java 编写的,而 Java 没有 unsigned int。 2^31 对于分区来说已经非常高了。一般来说,我们建议仅运行几千个分区。

Answering a question little late, just by 4 years :)

The reason is Voldemort is written in Java and Java has no unsigned int. 2^31 is already very high for the partitions. Generally we recommend running with only few thousand partitions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文