此内容没有您所选择的语言版本。

10.4.3. Hash Code Calculation Rules for Clients


Specific rules must be followed by clients when calculating the hash code for a server.
When virtual nodes are disabled:

When clients receive the base hash code of a server, it must be normalized to locate the exact position on the hash wheel. This normalization process includes:

  • Passing the base hash code to the hash function.
  • Calculations to avoid negative values.
The result is a number that indicates the node's position in the hash wheel.
The following code displays how the normalization process is carried out:
public static int getNormalizedHash(int nodeBaseHashCode, Hash hashFct) {
   return hashFct.hash(nodeBaseHashCode) & Integer.MAX_VALUE; 
}
Copy to Clipboard Toggle word wrap
When virtual nodes are enabled:

Each node represents N different virtual modes. Therefore, to calculate the hash code for each virtual node, use the numbers between 0 and N-1 and apply the following process:

Procedure 10.1. Hash Code Calculation with Virtual Nodes

  1. For the virtual node with the ID "0", use the following code to obtain the hash code:
    public static int getNormalizedHash(int nodeBaseHashCode, Hash hashFct) {
       return hashFct.hash(nodeBaseHashCode) & Integer.MAX_VALUE; 
    }
    
    Copy to Clipboard Toggle word wrap
  2. For all subsequent virtual nodes (with IDs from "1" to "N-1"), execute the following code:
    public static int virtualNodeHashCode(int nodeBaseHashCode, int id, Hash hashFct) {
       int virtualNodeBaseHashCode = id;
       virtualNodeBaseHashCode = 31 * virtualNodeBaseHashCode + nodeBaseHashCode;
       return getNormalizedHash(virtualNodeBaseHashCode, hashFct);
    }
    
    Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat