/** * Returns <code>true</code> iff the routing tables (for all indices) have * changed between the previous cluster state and the current cluster state. * Note that this is an object reference equality test, not an equals test. */ public boolean routingTableChanged() { return state.routingTable() != previousState.routingTable(); }
public RoutingTable getRoutingTable() { return routingTable(); }
/** * The refresh request works against *all* shards. */ @Override protected ShardsIterator shards(ClusterState clusterState, ForceMergeRequest request, String[] concreteIndices) { return clusterState.routingTable().allShards(concreteIndices); }
/** * Getting upgrade stats from *all* active shards. */ @Override protected ShardsIterator shards(ClusterState clusterState, UpgradeStatusRequest request, String[] concreteIndices) { return clusterState.routingTable().allShards(concreteIndices); }
/** * Segments goes across *all* active shards. */ @Override protected ShardsIterator shards(ClusterState clusterState, IndicesSegmentsRequest request, String[] concreteIndices) { return clusterState.routingTable().allShards(concreteIndices); }
/** * Status goes across *all* shards. */ @Override protected ShardsIterator shards(ClusterState clusterState, IndicesStatsRequest request, String[] concreteIndices) { return clusterState.routingTable().allShards(concreteIndices); }
/** * The refresh request works against *all* shards. */ @Override protected ShardsIterator shards(ClusterState clusterState, ClearIndicesCacheRequest request, String[] concreteIndices) { return clusterState.routingTable().allShards(concreteIndices); }
@Override protected ShardsIterator shards(ClusterState state, RecoveryRequest request, String[] concreteIndices) { return state.routingTable().allShardsIncludingRelocationTargets(concreteIndices); }
/** * Returns <code>true</code> iff the routing table has changed for the given index. * Note that this is an object reference equality test, not an equals test. */ public boolean indexRoutingTableChanged(String index) { Objects.requireNonNull(index, "index must not be null"); if (!state.routingTable().hasIndex(index) && !previousState.routingTable().hasIndex(index)) { return false; } if (state.routingTable().hasIndex(index) && previousState.routingTable().hasIndex(index)) { return state.routingTable().index(index) != previousState.routingTable().index(index); } return true; }
/** * 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; }
protected IndexRoutingTable indexRoutingTable(ClusterState clusterState, String index) { IndexRoutingTable indexRouting = clusterState.routingTable().index(index); if (indexRouting == null) { throw new IndexNotFoundException(index); } return indexRouting; }
/** * The upgrade request works against *all* shards. */ @Override protected ShardsIterator shards(ClusterState clusterState, UpgradeRequest request, String[] concreteIndices) { ShardsIterator iterator = clusterState.routingTable().allShards(concreteIndices); Set<String> indicesWithMissingPrimaries = indicesWithMissingPrimaries(clusterState, concreteIndices); if (indicesWithMissingPrimaries.isEmpty()) { return iterator; } // If some primary shards are not available the request should fail. throw new PrimaryMissingActionException("Cannot upgrade indices because the following indices are missing primary shards " + indicesWithMissingPrimaries); }
@Override protected ShardsIterator shards(ClusterState state, InternalRequest request) { // Will balance requests between shards // Resolve patterns and deduplicate return state.routingTable().index(request.concreteIndex()).randomAllActiveShardsIt(); }
/** * Returns the number of shards that are unassigned and currently being delayed. */ public static int getNumberOfDelayedUnassigned(ClusterState state) { int count = 0; for (ShardRouting shard : state.routingTable().shardsWithState(ShardRoutingState.UNASSIGNED)) { if (shard.unassignedInfo().isDelayed()) { count++; } } return count; }
@Override protected ShardsIterator shards(ClusterState state, InternalRequest request) { // Will balance requests between shards return state.routingTable().index(request.concreteIndex()).randomAllActiveShardsIt(); }
@Override protected ShardsIterator shards(ClusterState state, InternalRequest request) { if (request.concreteIndex() == null) { // just execute locally.... return null; } return state.routingTable().index(request.concreteIndex()).randomAllActiveShardsIt(); }
public ClusterState(long version, String stateUUID, ClusterState state) { this(state.clusterName, version, stateUUID, state.metaData(), state.routingTable(), state.nodes(), state.blocks(), state.customs(), false); }
public Builder(ClusterState state) { this.clusterName = state.clusterName; this.version = state.version(); this.uuid = state.stateUUID(); this.nodes = state.nodes(); this.routingTable = state.routingTable(); this.metaData = state.metaData(); this.blocks = state.blocks(); this.customs = ImmutableOpenMap.builder(state.customs()); this.fromDiff = false; }
@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()); }
final IndexShardRoutingTable getShardRoutingTable(ShardId shardId, ClusterState state) { final IndexRoutingTable indexRoutingTable = state.routingTable().index(shardId.getIndexName()); if (indexRoutingTable == null) { IndexMetaData index = state.getMetaData().index(shardId.getIndex()); if (index != null && index.getState() == IndexMetaData.State.CLOSE) { throw new IndexClosedException(shardId.getIndex()); } throw new IndexNotFoundException(shardId.getIndexName()); } final IndexShardRoutingTable shardRoutingTable = indexRoutingTable.shard(shardId.id()); if (shardRoutingTable == null) { throw new ShardNotFoundException(shardId); } return shardRoutingTable; }