/** * 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; }
/** * The refresh request works against *all* shards. */ @Override protected ShardsIterator shards(ClusterState clusterState, ForceMergeRequest request, String[] concreteIndices) { return clusterState.routingTable().allShards(concreteIndices); }
public GroupShardsIterator allActiveShardsGrouped(String[] indices, boolean includeEmpty) { return allActiveShardsGrouped(indices, includeEmpty, false); }
/** * All the shards (replicas) for the provided index. * * @param index The index to return all the shards (replicas). * @return All the shards matching the specific index * @throws IndexNotFoundException If the index passed does not exists */ public List<ShardRouting> allShards(String index) { List<ShardRouting> shards = new ArrayList<>(); IndexRoutingTable indexRoutingTable = index(index); if (indexRoutingTable == null) { throw new IndexNotFoundException(index); } for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) { for (ShardRouting shardRouting : indexShardRoutingTable) { shards.add(shardRouting); } } return shards; }
RoutingTable.Builder routingTableBuilder = RoutingTable.builder(); String[] indices = indexNameExpressionResolver.concreteIndexNames(currentState, request); for (String filteredIndex : indices) { if (currentState.routingTable().getIndicesRouting().containsKey(filteredIndex)) { routingTableBuilder.add(currentState.routingTable().getIndicesRouting().get(filteredIndex));
private ClusterState buildResult(ClusterState oldState, RoutingAllocation allocation) { final RoutingTable oldRoutingTable = oldState.routingTable(); final RoutingNodes newRoutingNodes = allocation.routingNodes(); final RoutingTable newRoutingTable = new RoutingTable.Builder().updateNodes(oldRoutingTable.version(), newRoutingNodes).build(); final MetaData newMetaData = allocation.updateMetaDataWithRoutingChanges(newRoutingTable); assert newRoutingTable.validate(newMetaData); // validates the routing table is coherent with the cluster state metadata final ClusterState.Builder newStateBuilder = ClusterState.builder(oldState) .routingTable(newRoutingTable) .metaData(newMetaData); final RestoreInProgress restoreInProgress = allocation.custom(RestoreInProgress.TYPE); if (restoreInProgress != null) { RestoreInProgress updatedRestoreInProgress = allocation.updateRestoreInfoWithRoutingChanges(restoreInProgress); if (updatedRestoreInProgress != restoreInProgress) { ImmutableOpenMap.Builder<String, ClusterState.Custom> customsBuilder = ImmutableOpenMap.builder(allocation.getCustoms()); customsBuilder.put(RestoreInProgress.TYPE, updatedRestoreInProgress); newStateBuilder.customs(customsBuilder.build()); } } return newStateBuilder.build(); }
indices = new HashMap<>(); for (String index : concreteIndices) { IndexRoutingTable indexRoutingTable = clusterState.routingTable().index(index); IndexMetaData indexMetaData = clusterState.metaData().index(index); if (indexRoutingTable == null) { this.activeShardsPercent = 100; } else { List<ShardRouting> shardRoutings = clusterState.getRoutingTable().allShards(); int activeShardCount = 0; int totalShardCount = 0;
private ClusterState patchVersions(ClusterState previousClusterState, ClusterTasksResult<?> executionResult) { ClusterState newClusterState = executionResult.resultingState; if (previousClusterState != newClusterState) { // only the master controls the version numbers Builder builder = ClusterState.builder(newClusterState).incrementVersion(); if (previousClusterState.routingTable() != newClusterState.routingTable()) { builder.routingTable(RoutingTable.builder(newClusterState.routingTable()) .version(newClusterState.routingTable().version() + 1).build()); } if (previousClusterState.metaData() != newClusterState.metaData()) { builder.metaData(MetaData.builder(newClusterState.metaData()).version(newClusterState.metaData().version() + 1)); } newClusterState = builder.build(); } return newClusterState; }
public Builder updateNodes(RoutingNodes routingNodes) { this.version = routingNodes.routingTable().version(); IndexShardRoutingTable refData = routingNodes.routingTable().index(shardRoutingEntry.index()).shard(shardRoutingEntry.id()); indexBuilder.addShard(refData, shardRoutingEntry); indexRoutingTableBuilders.put(index, indexBuilder); IndexShardRoutingTable refData = routingNodes.routingTable().index(shardRoutingEntry.index()).shard(shardRoutingEntry.id()); indexBuilder.addShard(refData, shardRoutingEntry);
public static RoutingTable build(ClusterService clusterService, ClusterState clusterState, Index index) { ImmutableOpenMap.Builder<String, IndexRoutingTable> indicesRoutingMap = new ImmutableOpenMap.Builder<>(); for(ObjectObjectCursor<String, IndexRoutingTable> entry : clusterState.routingTable().indicesRouting()) { if (!entry.key.equals(index)) indicesRoutingMap.put(entry.value.getIndex().getName(), entry.value); } // may update the routing table for the specified index IndexMetaData indexMetaData = clusterState.metaData().index(index); if (indexMetaData != null) { IndexRoutingTable.Builder indexRoutingTableBuilder = new IndexRoutingTable.Builder(index, clusterService, clusterState); if (indexRoutingTableBuilder.shards.size() > 0) indicesRoutingMap.put(index.getName(), indexRoutingTableBuilder.build()); } return new RoutingTable(clusterState.routingTable().version(), indicesRoutingMap.build()); }
return clusterState; } else { final RoutingTable.Builder routingTableBuilder = RoutingTable.builder(clusterState.routingTable()); final MetaData.Builder metaDataBuilder = MetaData.builder(clusterState.metaData()); for (Map.Entry<Integer, List<String>> entry : autoExpandReplicaChanges.entrySet()) {
/** * Build a RoutingTable according to clusterState ( * -Allocate unallocated indices with one primary shard on local node). * -Remove obsolete IndexRoutingTable */ public Builder(ClusterService clusterService, ClusterState clusterState) { version = clusterState.routingTable().version(); for (ObjectObjectCursor<String, IndexMetaData> entry : clusterState.metaData().getIndices()) { IndexRoutingTable.Builder indexRoutingTableBuilder = new IndexRoutingTable.Builder(entry.value.getIndex(), clusterService, clusterState); if (indexRoutingTableBuilder.shards.size() > 0) indicesRouting.put(entry.key, indexRoutingTableBuilder.build()); } }
/** * Return GroupShardsIterator where each assigned shard routing has it's own shard iterator. * * @param includeEmpty if true, a shard iterator will be added for non-assigned shards as well * @param includeRelocationTargets if true, an <b>extra</b> shard iterator will be added for relocating shards. The extra * iterator contains a single ShardRouting pointing at the relocating target */ public GroupShardsIterator<ShardIterator> allAssignedShardsGrouped(String[] indices, boolean includeEmpty, boolean includeRelocationTargets) { return allSatisfyingPredicateShardsGrouped(indices, includeEmpty, includeRelocationTargets, ASSIGNED_PREDICATE); }
@Override public RoutingTable apply(RoutingTable part) { return new RoutingTable(version, indicesRouting.apply(part.indicesRouting)); }
/** * Returns a set of nodes that have at least one shard of the given index. */ public synchronized Set<String> nodesInclude(String index) { if (clusterService().state().routingTable().hasIndex(index)) { List<ShardRouting> allShards = clusterService().state().routingTable().allShards(index); DiscoveryNodes discoveryNodes = clusterService().state().getNodes(); Set<String> nodes = new HashSet<>(); for (ShardRouting shardRouting : allShards) { if (shardRouting.assignedToNode()) { DiscoveryNode discoveryNode = discoveryNodes.get(shardRouting.currentNodeId()); nodes.add(discoveryNode.getName()); } } return nodes; } return Collections.emptySet(); }
public static RoutingTable build(ClusterService clusterService, ClusterState clusterState) { ImmutableOpenMap.Builder<String, IndexRoutingTable> indicesRoutingMap = new ImmutableOpenMap.Builder<>(); for(ObjectObjectCursor<String, IndexMetaData> entry : clusterState.metaData().getIndices()) { IndexRoutingTable.Builder indexRoutingTableBuilder = new IndexRoutingTable.Builder(entry.value.getIndex(), clusterService, clusterState); if (indexRoutingTableBuilder.shards.size() > 0) indicesRoutingMap.put(indexRoutingTableBuilder.index.getName(), indexRoutingTableBuilder.build()); } return new RoutingTable(clusterState.routingTable().version(), indicesRoutingMap.build()); }
public GroupShardsIterator<ShardIterator> allAssignedShardsGrouped(String[] indices, boolean includeEmpty) { return allAssignedShardsGrouped(indices, includeEmpty, false); }
if (state.routingTable().hasIndex(TASK_INDEX) == false) { CreateIndexRequest createIndexRequest = new CreateIndexRequest(); createIndexRequest.settings(taskResultIndexSettings());
for (Entry<String, IndexRoutingTable> entry : stateResponse.getState().getRoutingTable().getIndicesRouting().entrySet())
/** * 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; }