Ring is a Service that maintains an in-memory copy of a ring and watches for changes. Support for read-only instances requires use of ShuffleShard or ShuffleShardWithLookback prior to getting a ReplicationSet.
| 238 | // Ring is a Service that maintains an in-memory copy of a ring and watches for changes. |
| 239 | // Support for read-only instances requires use of ShuffleShard or ShuffleShardWithLookback prior to getting a ReplicationSet. |
| 240 | type Ring struct { |
| 241 | services.Service |
| 242 | |
| 243 | key string |
| 244 | cfg Config |
| 245 | KVClient kv.Client |
| 246 | strategy ReplicationStrategy |
| 247 | |
| 248 | mtx sync.RWMutex |
| 249 | ringDesc *Desc |
| 250 | ringTokens []uint32 |
| 251 | ringTokensByZone map[string][]uint32 |
| 252 | |
| 253 | // Oldest value of RegisteredTimestamp from all instances. If any instance had RegisteredTimestamp == 0, |
| 254 | // then this value will be 0. |
| 255 | oldestRegisteredTimestamp int64 |
| 256 | |
| 257 | readOnlyInstances *int // Number of instances with ReadOnly flag set. Only valid if not nil. |
| 258 | // Oldest value of ReadOnlyUpdatedTimestamp for read-only instances. If there are no read-only instances, |
| 259 | // or if any read-only instance has ReadOnlyUpdatedTimestamp == 0 (which should not happen), then this value will be 0. |
| 260 | // Only valid if not nil. |
| 261 | oldestReadOnlyUpdatedTimestamp *int64 |
| 262 | |
| 263 | // Maps a token with the information of the instance holding it. This map is immutable and |
| 264 | // cannot be changed in place because it's shared "as is" between subrings (the only way to |
| 265 | // change it is to create a new one and replace it). |
| 266 | ringInstanceByToken map[uint32]instanceInfo |
| 267 | |
| 268 | // When did a set of instances change the last time (instance changing state or heartbeat is ignored for this timestamp). |
| 269 | lastTopologyChange time.Time |
| 270 | |
| 271 | // List of zones for which there's at least 1 instance in the ring. This list is guaranteed |
| 272 | // to be sorted alphabetically. |
| 273 | ringZones []string |
| 274 | |
| 275 | // Map containing all ring zones ever discovered, even if they have no instances, |
| 276 | // capped at 32 zones to limit cardinality. |
| 277 | trackedRingZones map[string]struct{} |
| 278 | |
| 279 | // Number of registered instances with tokens. |
| 280 | instancesWithTokensCount int |
| 281 | |
| 282 | // Number of registered instances per zone. |
| 283 | instancesCountPerZone map[string]int |
| 284 | |
| 285 | // Number of registered instances with tokens per zone. |
| 286 | instancesWithTokensCountPerZone map[string]int |
| 287 | |
| 288 | // Number of registered instances are writable and have tokens. |
| 289 | writableInstancesWithTokensCount int |
| 290 | |
| 291 | // Number of registered instances with tokens per zone that are writable. |
| 292 | writableInstancesWithTokensCountPerZone map[string]int |
| 293 | |
| 294 | // Cache of shuffle-sharded subrings per identifier. Invalidated when topology changes. |
| 295 | // If set to nil, no caching is done (used by tests, and subrings). |
| 296 | shuffledSubringCache map[subringCacheKey]*Ring |
| 297 | shuffledSubringWithLookbackCache map[subringCacheKey]cachedSubringWithLookback[*Ring] |
nothing calls this directly
no outgoing calls
no test coverage detected