GetPartitionID calculates and returns the partition ID for a given key. The partition ID is determined by hashing the key and applying modulo operation with the partition count.
(key []byte)
| 365 | // GetPartitionID calculates and returns the partition ID for a given key. |
| 366 | // The partition ID is determined by hashing the key and applying modulo operation with the partition count. |
| 367 | func (c *Consistent) GetPartitionID(key []byte) int { |
| 368 | // Generate a hash value for the given key using the configured hasher. |
| 369 | hashValue := c.hasher(key) |
| 370 | |
| 371 | // Calculate the partition ID by taking the modulus of the hash value with the partition count. |
| 372 | return int(hashValue % c.partitionCount) |
| 373 | } |
| 374 | |
| 375 | // GetPartitionOwner retrieves the owner of the specified partition in a thread-safe manner. |
| 376 | // It ensures that the access to shared resources is synchronized. |