AddPartition adds a new partition to the ring. Tokens are auto-generated using the spread minimizing strategy which generates deterministic unique tokens.
(id int32, state PartitionState, now time.Time)
| 202 | // AddPartition adds a new partition to the ring. Tokens are auto-generated using the spread minimizing strategy |
| 203 | // which generates deterministic unique tokens. |
| 204 | func (m *PartitionRingDesc) AddPartition(id int32, state PartitionState, now time.Time) { |
| 205 | // Spread-minimizing token generator is deterministic unique-token generator for given id and zone. |
| 206 | // Partitions don't use zones. |
| 207 | spreadMinimizing := NewSpreadMinimizingTokenGeneratorForInstanceAndZoneID("", int(id), 0, false) |
| 208 | |
| 209 | m.Partitions[id] = PartitionDesc{ |
| 210 | Id: id, |
| 211 | Tokens: spreadMinimizing.GenerateTokens(optimalTokensPerInstance, nil), |
| 212 | State: state, |
| 213 | StateTimestamp: now.Unix(), |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | // UpdatePartitionState changes the state of a partition. Returns true if the state was changed, |
| 218 | // or false if the update was a no-op. |