此内容没有您所选择的语言版本。
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; }
public static int getNormalizedHash(int nodeBaseHashCode, Hash hashFct) {
return hashFct.hash(nodeBaseHashCode) & Integer.MAX_VALUE;
}
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
- 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; }
public static int getNormalizedHash(int nodeBaseHashCode, Hash hashFct) { return hashFct.hash(nodeBaseHashCode) & Integer.MAX_VALUE; }
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - For all subsequent virtual nodes (with IDs from "1" to "N-1"), execute the following code:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow