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

Method WithPartitions

ring/partition_ring_model.go:180–200  ·  view source on GitHub ↗

WithPartitions returns a new PartitionRingDesc with only the specified partitions and their owners included.

(partitions map[int32]struct{})

Source from the content-addressed store, hash-verified

178
179// WithPartitions returns a new PartitionRingDesc with only the specified partitions and their owners included.
180func (m *PartitionRingDesc) WithPartitions(partitions map[int32]struct{}) PartitionRingDesc {
181 newPartitions := make(map[int32]PartitionDesc, len(partitions))
182 newOwners := make(map[string]OwnerDesc, len(partitions)*2) // assuming two owners per partition.
183
184 for pid, p := range m.Partitions {
185 if _, ok := partitions[pid]; ok {
186 newPartitions[pid] = p
187 }
188 }
189
190 for oid, o := range m.Owners {
191 if _, ok := partitions[o.OwnedPartition]; ok {
192 newOwners[oid] = o
193 }
194 }
195
196 return PartitionRingDesc{
197 Partitions: newPartitions,
198 Owners: newOwners,
199 }
200}
201
202// AddPartition adds a new partition to the ring. Tokens are auto-generated using the spread minimizing strategy
203// which generates deterministic unique tokens.

Callers 1

shuffleShardMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected