buildRingForTheShard builds read-only ring for the shard (this ring won't be updated in the future).
(shard map[string]InstanceDesc)
| 1167 | |
| 1168 | // buildRingForTheShard builds read-only ring for the shard (this ring won't be updated in the future). |
| 1169 | func (r *Ring) buildRingForTheShard(shard map[string]InstanceDesc) *Ring { |
| 1170 | shardDesc := &Desc{Ingesters: shard} |
| 1171 | shardTokensByZone := shardDesc.getTokensByZone() |
| 1172 | shardTokens := mergeTokenGroups(shardTokensByZone) |
| 1173 | zones := getZones(shardTokensByZone) |
| 1174 | |
| 1175 | ring := &Ring{ |
| 1176 | cfg: r.cfg, |
| 1177 | strategy: r.strategy, |
| 1178 | logger: r.logger, |
| 1179 | ringDesc: shardDesc, |
| 1180 | ringTokens: shardTokens, |
| 1181 | ringTokensByZone: shardTokensByZone, |
| 1182 | ringZones: zones, |
| 1183 | trackedRingZones: map[string]struct{}{}, |
| 1184 | instancesWithTokensCount: shardDesc.instancesWithTokensCount(), |
| 1185 | instancesCountPerZone: shardDesc.instancesCountPerZone(), |
| 1186 | instancesWithTokensCountPerZone: shardDesc.instancesWithTokensCountPerZone(), |
| 1187 | writableInstancesWithTokensCount: shardDesc.writableInstancesWithTokensCount(), |
| 1188 | writableInstancesWithTokensCountPerZone: shardDesc.writableInstancesWithTokensCountPerZone(), |
| 1189 | |
| 1190 | oldestRegisteredTimestamp: shardDesc.getOldestRegisteredTimestamp(), |
| 1191 | |
| 1192 | // We reference the original map as is in order to avoid copying. It's safe to do |
| 1193 | // because this map is immutable by design and it's a superset of the actual instances |
| 1194 | // with the subring. |
| 1195 | ringInstanceByToken: r.ringInstanceByToken, |
| 1196 | |
| 1197 | // For caching to work, remember these values. |
| 1198 | lastTopologyChange: r.lastTopologyChange, |
| 1199 | } |
| 1200 | |
| 1201 | ring.updateRingZones(zones) |
| 1202 | return ring |
| 1203 | } |
| 1204 | |
| 1205 | // mergeTokenGroups returns a sorted list of all tokens in each entry in groupsByName. |
| 1206 | // Each element of groupsByName is assumed to already be sorted. |
no test coverage detected