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

Method ActivePartitionForKey

ring/partition_ring.go:137–158  ·  view source on GitHub ↗

ActivePartitionForKey returns partition for the given key. Only active partitions are considered. Only one partition is returned: in other terms, the replication factor is always 1.

(key uint32)

Source from the content-addressed store, hash-verified

135// ActivePartitionForKey returns partition for the given key. Only active partitions are considered.
136// Only one partition is returned: in other terms, the replication factor is always 1.
137func (r *PartitionRing) ActivePartitionForKey(key uint32) (int32, error) {
138 var (
139 start = searchToken(r.ringTokens, key)
140 iterations = 0
141 tokensCount = len(r.ringTokens)
142 )
143
144 for i := start; iterations < tokensCount; i++ {
145 iterations++
146
147 if i >= tokensCount {
148 i %= tokensCount
149 }
150
151 // If the partition is not active we'll keep walking the ring.
152 if r.ringPartitionActive[i] {
153 return r.ringPartitionIDs[i], nil
154 }
155 }
156
157 return 0, ErrNoActivePartitionFound
158}
159
160// ShuffleShardSize returns number of partitions that would be in the result of ShuffleShard call with the same size.
161func (r *PartitionRing) ShuffleShardSize(size int) int {

Calls 1

searchTokenFunction · 0.85