private static boolean clusterHas5xIndices(ClusterState state) { final Iterator<IndexMetaData> indices = state.metaData().indices().valuesIt(); for(;indices.hasNext();) { final IndexMetaData indexMetaData = indices.next(); if(indexMetaData.getCreationVersion().before(Version.V_6_0_0_alpha1)) { return true; } } return false; } }
final SortedMap<String, AliasOrIndex> lookup = state.metaData().getAliasAndIndexLookup(); final Set<String> aliases = lookup.entrySet().stream().filter(e->e.getValue().isAlias()).map(e->e.getKey()).collect(Collectors.toSet());
final IndexMetaData indexMetaData = clusterService.state().metaData().getIndices().get(requestAliasOrIndex);
final SortedMap<String, AliasOrIndex> lookup = clusterService.state().metaData().getAliasAndIndexLookup(); for(final String indexOrAlias: lookup.keySet()) { final String tenant = tenantNameForIndex(indexOrAlias);
/** * Returns <code>true</code> iff the metadata for the cluster has changed between * the previous cluster state and the new cluster state. Note that this is an object * reference equality test, not an equals test. */ public boolean metaDataChanged() { return state.metaData() != previousState.metaData(); }
/** * Creates a new <code>ClusterStateHealth</code> instance considering the current cluster state and all indices in the cluster. * * @param clusterState The current cluster state. Must not be null. */ public ClusterStateHealth(final ClusterState clusterState) { this(clusterState, clusterState.metaData().getConcreteAllIndices()); }
public static Set<Index> getRelevantIndicesForMasterEligibleNode(ClusterState state) { Set<Index> relevantIndices; relevantIndices = new HashSet<>(); // we have to iterate over the metadata to make sure we also capture closed indices for (IndexMetaData indexMetaData : state.metaData()) { relevantIndices.add(indexMetaData.getIndex()); } return relevantIndices; }
private List<Index> indicesDeletedFromTombstones() { // We look at the full tombstones list to see which indices need to be deleted. In the case of // a valid previous cluster state, indicesDeletedFromClusterState() will be used to get the deleted // list, so a diff doesn't make sense here. When a node (re)joins the cluster, its possible for it // to re-process the same deletes or process deletes about indices it never knew about. This is not // an issue because there are safeguards in place in the delete store operation in case the index // folder doesn't exist on the file system. List<IndexGraveyard.Tombstone> tombstones = state.metaData().indexGraveyard().getTombstones(); return tombstones.stream().map(IndexGraveyard.Tombstone::getIndex).collect(Collectors.toList()); }
@Override public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { logger.info("recovered [{}] indices into cluster_state", newState.metaData().indices().size()); } });
/** Returns true if the persistent tasks are not equal between the previous and the current cluster state **/ static boolean persistentTasksChanged(final ClusterChangedEvent event) { String type = PersistentTasksCustomMetaData.TYPE; return Objects.equals(event.state().metaData().custom(type), event.previousState().metaData().custom(type)) == false; }
protected IndexMetaData indexMetaData(ClusterState clusterState, String index) { IndexMetaData indexMetaData = clusterState.metaData().index(index); if (indexMetaData == null) { throw new IndexNotFoundException(index); } return indexMetaData; }
@SuppressWarnings("unchecked") public static <Params extends PersistentTaskParams> PersistentTask<Params> getTaskWithId(ClusterState clusterState, String taskId) { PersistentTasksCustomMetaData tasks = clusterState.metaData().custom(PersistentTasksCustomMetaData.TYPE); if (tasks != null) { return (PersistentTask<Params>) tasks.getTask(taskId); } return null; }
static ClusterGetSettingsResponse response( final ClusterState state, final boolean renderDefaults, final SettingsFilter settingsFilter, final ClusterSettings clusterSettings, final Settings settings) { return new ClusterGetSettingsResponse( settingsFilter.filter(state.metaData().persistentSettings()), settingsFilter.filter(state.metaData().transientSettings()), renderDefaults ? settingsFilter.filter(clusterSettings.diff(state.metaData().settings(), settings)) : Settings.EMPTY); }
private int getTotalNewShards(Index index, ClusterState currentState, int updatedNumberOfReplicas) { IndexMetaData indexMetaData = currentState.metaData().index(index); int shardsInIndex = indexMetaData.getNumberOfShards(); int oldNumberOfReplicas = indexMetaData.getNumberOfReplicas(); int replicaIncrease = updatedNumberOfReplicas - oldNumberOfReplicas; return replicaIncrease * shardsInIndex; }
@Override public void clusterChanged(ClusterChangedEvent event) { if (event.state().blocks().disableStatePersistence() == false) { processDanglingIndices(event.state().metaData()); } } }
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 void doExecute(MainRequest request, ActionListener<MainResponse> listener) { ClusterState clusterState = clusterService.state(); final boolean available = clusterState.getBlocks().hasGlobalBlock(RestStatus.SERVICE_UNAVAILABLE) == false; listener.onResponse( new MainResponse(nodeName, Version.CURRENT, clusterState.getClusterName(), clusterState.metaData().clusterUUID(), Build.CURRENT, available)); } }
@Override protected void resolveRequest(ClusterState state, InternalRequest request) { // update the routing (request#index here is possibly an alias or a parent) request.request().routing(state.metaData() .resolveIndexRouting(request.request().parent(), request.request().routing(), request.request().index())); // Fail fast on the node that received the request. if (request.request().routing() == null && state.getMetaData().routingRequired(request.concreteIndex(), request.request().type())) { throw new RoutingMissingException(request.concreteIndex(), request.request().type(), request.request().id()); } }
@Override protected void resolveRequest(ClusterState state, InternalRequest request) { IndexMetaData indexMeta = state.getMetaData().index(request.concreteIndex()); // update the routing (request#index here is possibly an alias) request.request().routing(state.metaData().resolveIndexRouting(request.request().parent(), request.request().routing(), request.request().index())); // Fail fast on the node that received the request. if (request.request().routing() == null && state.getMetaData().routingRequired(request.concreteIndex(), request.request().type())) { throw new RoutingMissingException(request.concreteIndex(), request.request().type(), request.request().id()); } }