@Override protected ShardsIterator shards(ClusterState state, InternalRequest request) { // Will balance requests between shards // Resolve patterns and deduplicate return state.routingTable().index(request.concreteIndex()).randomAllActiveShardsIt(); }
if (indexRoutingTable.allPrimaryShardsActive() == false) { waitForActiveShards = SETTING_WAIT_FOR_ACTIVE_SHARDS.get(indexMetaData.getSettings()); for (final IntObjectCursor<IndexShardRoutingTable> shardRouting : indexRoutingTable.getShards()) { if (waitForActiveShards.enoughShardsActive(shardRouting.value) == false) {
@Override public String toString() { StringBuilder sb = new StringBuilder("routing_table (version ").append(version).append("):\n"); for (ObjectObjectCursor<String, IndexRoutingTable> entry : indicesRouting) { sb.append(entry.value.prettyPrint()).append('\n'); } return sb.toString(); }
/** * Returns <code>true</code> if all shards are primary and active. Otherwise <code>false</code>. */ public boolean allPrimaryShardsActive() { return primaryShardsActive() == shards().size(); }
public IndexShardRoutingTable shardRoutingTableOrNull(ShardId shardId) { return Optional .ofNullable(index(shardId.getIndexName())) .flatMap(irt -> Optional.ofNullable(irt.shard(shardId.getId()))) .orElse(null); }
public ImmutableOpenIntMap<IndexShardRoutingTable> getShards() { return shards(); }
/** * @return all shard ids the request should run on */ protected List<ShardId> shards(Request request, ClusterState clusterState) { List<ShardId> shardIds = new ArrayList<>(); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request); for (String index : concreteIndices) { IndexMetaData indexMetaData = clusterState.metaData().getIndices().get(index); if (indexMetaData != null) { for (IntObjectCursor<IndexShardRoutingTable> shardRouting : clusterState.getRoutingTable().indicesRouting().get(index).getShards()) { shardIds.add(shardRouting.value.shardId()); } } } return shardIds; }
public IndexRoutingTable build() throws RoutingValidationException { IndexRoutingTable indexRoutingTable = new IndexRoutingTable(index, shards.build()); indexRoutingTable.validate(); return indexRoutingTable; } }
/** * Finds all indices that have not all primaries available */ private Set<String> indicesWithMissingPrimaries(ClusterState clusterState, String[] concreteIndices) { Set<String> indices = new HashSet<>(); RoutingTable routingTable = clusterState.routingTable(); for (String index : concreteIndices) { IndexRoutingTable indexRoutingTable = routingTable.index(index); if (indexRoutingTable.allPrimaryShardsActive() == false) { indices.add(index); } } return indices; }
/** * Returns <code>true</code> if all primary shards are in * {@link ShardRoutingState#UNASSIGNED} state. Otherwise <code>false</code>. */ public boolean allPrimaryShardsUnassigned() { return primaryShardsUnassigned() == shards.size(); }
public static RoutingTable readFrom(StreamInput in) throws IOException { Builder builder = new Builder(); builder.version = in.readLong(); int size = in.readVInt(); for (int i = 0; i < size; i++) { IndexRoutingTable index = IndexRoutingTable.readFrom(in); builder.add(index); } return builder.build(); }
public IndexRoutingTable build() { return new IndexRoutingTable(index, shards.build()); } }
if (indexMetaData.getNumberOfShards() != shards().size()) { Set<Integer> expected = Sets.newHashSet(); for (int i = 0; i < indexMetaData.getNumberOfShards(); i++) { if (!shardRouting.index().equals(index())) { failures.add("shard routing has an index [" + shardRouting.index() + "] that is different than the routing table");
/** * Returns <code>true</code> if all shards are primary and active. Otherwise <code>false</code>. */ public boolean allPrimaryShardsActive() { return primaryShardsActive() == shards().size(); }
/** * All shards for the provided index and shard id * @return All the shard routing entries for the given index and shard id * @throws IndexNotFoundException if provided index does not exist * @throws ShardNotFoundException if provided shard id is unknown */ public IndexShardRoutingTable shardRoutingTable(String index, int shardId) { IndexRoutingTable indexRouting = index(index); if (indexRouting == null) { throw new IndexNotFoundException(index); } IndexShardRoutingTable shard = indexRouting.shard(shardId); if (shard == null) { throw new ShardNotFoundException(new ShardId(indexRouting.getIndex(), shardId)); } return shard; }
@Override protected ShardIterator shards(ClusterState clusterState, UpdateRequest request) { if (request.getShardId() != null) { return clusterState.routingTable().index(request.concreteIndex()).shard(request.getShardId().getId()).primaryShardIt(); } ShardIterator shardIterator = clusterService.operationRouting() .indexShards(clusterState, request.concreteIndex(), request.id(), request.routing()); ShardRouting shard; while ((shard = shardIterator.nextOrNull()) != null) { if (shard.primary()) { return new PlainShardIterator(shardIterator.shardId(), Collections.singletonList(shard)); } } return new PlainShardIterator(shardIterator.shardId(), Collections.emptyList()); }
public Builder add(IndexRoutingTable indexRoutingTable) { if (indicesRouting == null) { throw new IllegalStateException("once build is called the builder cannot be reused"); } if (indexRoutingTable.shards().size() > 0) indicesRouting.put(indexRoutingTable.getIndex().getName(), indexRoutingTable); return this; }
if (indexMetaData.getNumberOfShards() != shards().size()) { Set<Integer> expected = new HashSet<>(); for (int i = 0; i < indexMetaData.getNumberOfShards(); i++) {