WithPartitions returns a new PartitionRingDesc with only the specified partitions and their owners included.
(partitions map[int32]struct{})
| 178 | |
| 179 | // WithPartitions returns a new PartitionRingDesc with only the specified partitions and their owners included. |
| 180 | func (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. |