MCPcopy
hub / github.com/grafana/dskit / ShuffleShardSeed

Function ShuffleShardSeed

ring/shard/shard.go:15–27  ·  view source on GitHub ↗

ShuffleShardSeed returns seed for random number generator, computed from provided identifier.

(identifier, zone string)

Source from the content-addressed store, hash-verified

13
14// ShuffleShardSeed returns seed for random number generator, computed from provided identifier.
15func 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

Callers 1

userTokenFunction · 0.92

Calls 2

yoloBufFunction · 0.85
WriteMethod · 0.45

Tested by 1

userTokenFunction · 0.74