ShuffleShardSeed returns seed for random number generator, computed from provided identifier.
(identifier, zone string)
| 13 | |
| 14 | // ShuffleShardSeed returns seed for random number generator, computed from provided identifier. |
| 15 | func ShuffleShardSeed(identifier, zone string) int64 { |
| 16 | // Use the identifier to compute a hash we'll use to seed the random. |
| 17 | hasher := md5.New() |
| 18 | hasher.Write(yoloBuf(identifier)) // nolint:errcheck |
| 19 | if zone != "" { |
| 20 | hasher.Write(seedSeparator) // nolint:errcheck |
| 21 | hasher.Write(yoloBuf(zone)) // nolint:errcheck |
| 22 | } |
| 23 | checksum := hasher.Sum(nil) |
| 24 | |
| 25 | // Generate the seed based on the first 64 bits of the checksum. |
| 26 | return int64(binary.BigEndian.Uint64(checksum)) |
| 27 | } |
| 28 | |
| 29 | // ShuffleShardExpectedInstancesPerZone returns the number of instances that should be selected for each |
| 30 | // zone when zone-aware replication is enabled. The algorithm expects the shard size to be divisible |