GetLoadDistribution provides a thread-safe snapshot of the current load distribution across members. It returns a map where the keys are member identifiers and the values are their respective loads.
()
| 349 | // GetLoadDistribution provides a thread-safe snapshot of the current load distribution across members. |
| 350 | // It returns a map where the keys are member identifiers and the values are their respective loads. |
| 351 | func (c *Consistent) GetLoadDistribution() map[string]float64 { |
| 352 | // Acquire a read lock to ensure thread-safe access to the loads map. |
| 353 | c.mu.RLock() |
| 354 | defer c.mu.RUnlock() |
| 355 | |
| 356 | // Create a copy of the loads map to avoid exposing internal state. |
| 357 | loadDistribution := make(map[string]float64) |
| 358 | for memberName, memberLoad := range c.loads { |
| 359 | loadDistribution[memberName] = memberLoad |
| 360 | } |
| 361 | |
| 362 | return loadDistribution |
| 363 | } |
| 364 | |
| 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. |