Search in sources :

Example 91 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class TransportPutIndexTemplateAction method masterOperation.

@Override
protected void masterOperation(final PutIndexTemplateRequest request, final ClusterState state, final ActionListener<PutIndexTemplateResponse> listener) {
    String cause = request.cause();
    if (cause.length() == 0) {
        cause = "api";
    }
    final Settings.Builder templateSettingsBuilder = Settings.builder();
    templateSettingsBuilder.put(request.settings()).normalizePrefix(IndexMetaData.INDEX_SETTING_PREFIX);
    indexScopedSettings.validate(templateSettingsBuilder);
    indexTemplateService.putTemplate(new MetaDataIndexTemplateService.PutRequest(cause, request.name()).patterns(request.patterns()).order(request.order()).settings(templateSettingsBuilder.build()).mappings(request.mappings()).aliases(request.aliases()).customs(request.customs()).create(request.create()).masterTimeout(request.masterNodeTimeout()).version(request.version()), new MetaDataIndexTemplateService.PutListener() {

        @Override
        public void onResponse(MetaDataIndexTemplateService.PutResponse response) {
            listener.onResponse(new PutIndexTemplateResponse(response.acknowledged()));
        }

        @Override
        public void onFailure(Exception e) {
            logger.debug((Supplier<?>) () -> new ParameterizedMessage("failed to put template [{}]", request.name()), e);
            listener.onFailure(e);
        }
    });
}
Also used : Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) Settings(org.elasticsearch.common.settings.Settings) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) MetaDataIndexTemplateService(org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService)

Example 92 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class MetaDataCreateIndexService method validateShrinkIndex.

/**
     * Validates the settings and mappings for shrinking an index.
     * @return the list of nodes at least one instance of the source index shards are allocated
     */
static List<String> validateShrinkIndex(ClusterState state, String sourceIndex, Set<String> targetIndexMappingsTypes, String targetIndexName, Settings targetIndexSettings) {
    if (state.metaData().hasIndex(targetIndexName)) {
        throw new ResourceAlreadyExistsException(state.metaData().index(targetIndexName).getIndex());
    }
    final IndexMetaData sourceMetaData = state.metaData().index(sourceIndex);
    if (sourceMetaData == null) {
        throw new IndexNotFoundException(sourceIndex);
    }
    // ensure index is read-only
    if (state.blocks().indexBlocked(ClusterBlockLevel.WRITE, sourceIndex) == false) {
        throw new IllegalStateException("index " + sourceIndex + " must be read-only to shrink index. use \"index.blocks.write=true\"");
    }
    if (sourceMetaData.getNumberOfShards() == 1) {
        throw new IllegalArgumentException("can't shrink an index with only one shard");
    }
    if ((targetIndexMappingsTypes.size() > 1 || (targetIndexMappingsTypes.isEmpty() || targetIndexMappingsTypes.contains(MapperService.DEFAULT_MAPPING)) == false)) {
        throw new IllegalArgumentException("mappings are not allowed when shrinking indices" + ", all mappings are copied from the source index");
    }
    if (IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.exists(targetIndexSettings)) {
        // this method applies all necessary checks ie. if the target shards are less than the source shards
        // of if the source shards are divisible by the number of target shards
        IndexMetaData.getRoutingFactor(sourceMetaData, IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.get(targetIndexSettings));
    }
    // now check that index is all on one node
    final IndexRoutingTable table = state.routingTable().index(sourceIndex);
    Map<String, AtomicInteger> nodesToNumRouting = new HashMap<>();
    int numShards = sourceMetaData.getNumberOfShards();
    for (ShardRouting routing : table.shardsWithState(ShardRoutingState.STARTED)) {
        nodesToNumRouting.computeIfAbsent(routing.currentNodeId(), (s) -> new AtomicInteger(0)).incrementAndGet();
    }
    List<String> nodesToAllocateOn = new ArrayList<>();
    for (Map.Entry<String, AtomicInteger> entries : nodesToNumRouting.entrySet()) {
        int numAllocations = entries.getValue().get();
        assert numAllocations <= numShards : "wait what? " + numAllocations + " is > than num shards " + numShards;
        if (numAllocations == numShards) {
            nodesToAllocateOn.add(entries.getKey());
        }
    }
    if (nodesToAllocateOn.isEmpty()) {
        throw new IllegalStateException("index " + sourceIndex + " must have all shards allocated on the same node to shrink index");
    }
    return nodesToAllocateOn;
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) SETTING_INDEX_UUID(org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_INDEX_UUID) DateTimeZone(org.joda.time.DateTimeZone) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) Alias(org.elasticsearch.action.admin.indices.alias.Alias) Environment(org.elasticsearch.env.Environment) BiFunction(java.util.function.BiFunction) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) CreateIndexClusterStateUpdateResponse(org.elasticsearch.cluster.ack.CreateIndexClusterStateUpdateResponse) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) IndexCreationException(org.elasticsearch.indices.IndexCreationException) Locale(java.util.Locale) Map(java.util.Map) ValidationException(org.elasticsearch.common.ValidationException) ThreadPool(org.elasticsearch.threadpool.ThreadPool) State(org.elasticsearch.cluster.metadata.IndexMetaData.State) Path(java.nio.file.Path) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) CreateIndexClusterStateUpdateRequest(org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest) Priority(org.elasticsearch.common.Priority) Predicate(java.util.function.Predicate) UUIDs(org.elasticsearch.common.UUIDs) Set(java.util.Set) ObjectCursor(com.carrotsearch.hppc.cursors.ObjectCursor) ActiveShardCount(org.elasticsearch.action.support.ActiveShardCount) ContextPreservingActionListener(org.elasticsearch.action.support.ContextPreservingActionListener) MapperService(org.elasticsearch.index.mapper.MapperService) List(java.util.List) Version(org.elasticsearch.Version) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) Supplier(org.apache.logging.log4j.util.Supplier) ClusterStateUpdateResponse(org.elasticsearch.cluster.ack.ClusterStateUpdateResponse) InvalidIndexNameException(org.elasticsearch.indices.InvalidIndexNameException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) AckedClusterStateUpdateTask(org.elasticsearch.cluster.AckedClusterStateUpdateTask) ClusterService(org.elasticsearch.cluster.service.ClusterService) HashMap(java.util.HashMap) Index(org.elasticsearch.index.Index) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) ActiveShardsObserver(org.elasticsearch.action.support.ActiveShardsObserver) Strings(org.elasticsearch.common.Strings) Inject(org.elasticsearch.common.inject.Inject) ArrayList(java.util.ArrayList) SETTING_NUMBER_OF_REPLICAS(org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS) XContentHelper(org.elasticsearch.common.xcontent.XContentHelper) IndexRemovalReason(org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason) Custom(org.elasticsearch.cluster.metadata.IndexMetaData.Custom) Regex(org.elasticsearch.common.regex.Regex) SETTING_VERSION_CREATED(org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_VERSION_CREATED) IndicesService(org.elasticsearch.indices.IndicesService) SETTING_AUTO_EXPAND_REPLICAS(org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS) ClusterBlockLevel(org.elasticsearch.cluster.block.ClusterBlockLevel) SETTING_CREATION_DATE(org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_CREATION_DATE) PathUtils(org.elasticsearch.common.io.PathUtils) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) AbstractComponent(org.elasticsearch.common.component.AbstractComponent) SETTING_NUMBER_OF_SHARDS(org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS) IndexService(org.elasticsearch.index.IndexService) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) CollectionUtil(org.apache.lucene.util.CollectionUtil) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) MergeReason(org.elasticsearch.index.mapper.MapperService.MergeReason) Comparator(java.util.Comparator) Collections(java.util.Collections) ActionListener(org.elasticsearch.action.ActionListener) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Map(java.util.Map) HashMap(java.util.HashMap)

Example 93 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class MetaDataDeleteIndexService method deleteIndices.

/**
     * Delete some indices from the cluster state.
     */
public ClusterState deleteIndices(ClusterState currentState, Set<Index> indices) {
    final MetaData meta = currentState.metaData();
    final Set<IndexMetaData> metaDatas = indices.stream().map(i -> meta.getIndexSafe(i)).collect(toSet());
    // Check if index deletion conflicts with any running snapshots
    SnapshotsService.checkIndexDeletion(currentState, metaDatas);
    RoutingTable.Builder routingTableBuilder = RoutingTable.builder(currentState.routingTable());
    MetaData.Builder metaDataBuilder = MetaData.builder(meta);
    ClusterBlocks.Builder clusterBlocksBuilder = ClusterBlocks.builder().blocks(currentState.blocks());
    final IndexGraveyard.Builder graveyardBuilder = IndexGraveyard.builder(metaDataBuilder.indexGraveyard());
    final int previousGraveyardSize = graveyardBuilder.tombstones().size();
    for (final Index index : indices) {
        String indexName = index.getName();
        logger.info("{} deleting index", index);
        routingTableBuilder.remove(indexName);
        clusterBlocksBuilder.removeIndexBlocks(indexName);
        metaDataBuilder.remove(indexName);
    }
    // add tombstones to the cluster state for each deleted index
    final IndexGraveyard currentGraveyard = graveyardBuilder.addTombstones(indices).build(settings);
    // the new graveyard set on the metadata
    metaDataBuilder.indexGraveyard(currentGraveyard);
    logger.trace("{} tombstones purged from the cluster state. Previous tombstone size: {}. Current tombstone size: {}.", graveyardBuilder.getNumPurged(), previousGraveyardSize, currentGraveyard.getTombstones().size());
    MetaData newMetaData = metaDataBuilder.build();
    ClusterBlocks blocks = clusterBlocksBuilder.build();
    // update snapshot restore entries
    ImmutableOpenMap<String, ClusterState.Custom> customs = currentState.getCustoms();
    final RestoreInProgress restoreInProgress = currentState.custom(RestoreInProgress.TYPE);
    if (restoreInProgress != null) {
        RestoreInProgress updatedRestoreInProgress = RestoreService.updateRestoreStateWithDeletedIndices(restoreInProgress, indices);
        if (updatedRestoreInProgress != restoreInProgress) {
            ImmutableOpenMap.Builder<String, ClusterState.Custom> builder = ImmutableOpenMap.builder(customs);
            builder.put(RestoreInProgress.TYPE, updatedRestoreInProgress);
            customs = builder.build();
        }
    }
    return allocationService.reroute(ClusterState.builder(currentState).routingTable(routingTableBuilder.build()).metaData(newMetaData).blocks(blocks).customs(customs).build(), "deleted indices [" + indices + "]");
}
Also used : Arrays(java.util.Arrays) AckedClusterStateUpdateTask(org.elasticsearch.cluster.AckedClusterStateUpdateTask) Priority(org.elasticsearch.common.Priority) SnapshotsService(org.elasticsearch.snapshots.SnapshotsService) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) AbstractComponent(org.elasticsearch.common.component.AbstractComponent) ClusterService(org.elasticsearch.cluster.service.ClusterService) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) Set(java.util.Set) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) Index(org.elasticsearch.index.Index) RestoreService(org.elasticsearch.snapshots.RestoreService) Sets(org.elasticsearch.common.util.set.Sets) Inject(org.elasticsearch.common.inject.Inject) DeleteIndexClusterStateUpdateRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexClusterStateUpdateRequest) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) RestoreInProgress(org.elasticsearch.cluster.RestoreInProgress) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) ClusterStateUpdateResponse(org.elasticsearch.cluster.ack.ClusterStateUpdateResponse) ActionListener(org.elasticsearch.action.ActionListener) Collectors.toSet(java.util.stream.Collectors.toSet) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) Index(org.elasticsearch.index.Index) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) RestoreInProgress(org.elasticsearch.cluster.RestoreInProgress) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable)

Example 94 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class MetaDataIndexTemplateService method validateAndAddTemplate.

private static void validateAndAddTemplate(final PutRequest request, IndexTemplateMetaData.Builder templateBuilder, IndicesService indicesService, NamedXContentRegistry xContentRegistry) throws Exception {
    Index createdIndex = null;
    final String temporaryIndexName = UUIDs.randomBase64UUID();
    try {
        // use the provided values, otherwise just pick valid dummy values
        int dummyPartitionSize = IndexMetaData.INDEX_ROUTING_PARTITION_SIZE_SETTING.get(request.settings);
        int dummyShards = request.settings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, dummyPartitionSize == 1 ? 1 : dummyPartitionSize + 1);
        //create index service for parsing and validating "mappings"
        Settings dummySettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(request.settings).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, dummyShards).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).build();
        final IndexMetaData tmpIndexMetadata = IndexMetaData.builder(temporaryIndexName).settings(dummySettings).build();
        IndexService dummyIndexService = indicesService.createIndex(tmpIndexMetadata, Collections.emptyList(), shardId -> {
        });
        createdIndex = dummyIndexService.index();
        templateBuilder.order(request.order);
        templateBuilder.version(request.version);
        templateBuilder.patterns(request.indexPatterns);
        templateBuilder.settings(request.settings);
        Map<String, Map<String, Object>> mappingsForValidation = new HashMap<>();
        for (Map.Entry<String, String> entry : request.mappings.entrySet()) {
            try {
                templateBuilder.putMapping(entry.getKey(), entry.getValue());
            } catch (Exception e) {
                throw new MapperParsingException("Failed to parse mapping [{}]: {}", e, entry.getKey(), e.getMessage());
            }
            mappingsForValidation.put(entry.getKey(), MapperService.parseMapping(xContentRegistry, entry.getValue()));
        }
        dummyIndexService.mapperService().merge(mappingsForValidation, MergeReason.MAPPING_UPDATE, false);
    } finally {
        if (createdIndex != null) {
            indicesService.removeIndex(createdIndex, NO_LONGER_ASSIGNED, " created for parsing template mapping");
        }
    }
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) IndexService(org.elasticsearch.index.IndexService) HashMap(java.util.HashMap) Index(org.elasticsearch.index.Index) HashMap(java.util.HashMap) Map(java.util.Map) Settings(org.elasticsearch.common.settings.Settings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) ValidationException(org.elasticsearch.common.ValidationException) MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) InvalidIndexTemplateException(org.elasticsearch.indices.InvalidIndexTemplateException) IndexTemplateMissingException(org.elasticsearch.indices.IndexTemplateMissingException)

Example 95 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class MetaDataUpdateSettingsService method updateSettings.

public void updateSettings(final UpdateSettingsClusterStateUpdateRequest request, final ActionListener<ClusterStateUpdateResponse> listener) {
    final Settings normalizedSettings = Settings.builder().put(request.settings()).normalizePrefix(IndexMetaData.INDEX_SETTING_PREFIX).build();
    Settings.Builder settingsForClosedIndices = Settings.builder();
    Settings.Builder settingsForOpenIndices = Settings.builder();
    Settings.Builder skipppedSettings = Settings.builder();
    indexScopedSettings.validate(normalizedSettings);
    // never allow to change the number of shards
    for (Map.Entry<String, String> entry : normalizedSettings.getAsMap().entrySet()) {
        if (entry.getKey().equals(IndexMetaData.SETTING_NUMBER_OF_SHARDS)) {
            listener.onFailure(new IllegalArgumentException("can't change the number of shards for an index"));
            return;
        }
        Setting setting = indexScopedSettings.get(entry.getKey());
        // we already validated the normalized settings
        assert setting != null;
        settingsForClosedIndices.put(entry.getKey(), entry.getValue());
        if (setting.isDynamic()) {
            settingsForOpenIndices.put(entry.getKey(), entry.getValue());
        } else {
            skipppedSettings.put(entry.getKey(), entry.getValue());
        }
    }
    final Settings skippedSettigns = skipppedSettings.build();
    final Settings closedSettings = settingsForClosedIndices.build();
    final Settings openSettings = settingsForOpenIndices.build();
    final boolean preserveExisting = request.isPreserveExisting();
    clusterService.submitStateUpdateTask("update-settings", new AckedClusterStateUpdateTask<ClusterStateUpdateResponse>(Priority.URGENT, request, wrapPreservingContext(listener)) {

        @Override
        protected ClusterStateUpdateResponse newResponse(boolean acknowledged) {
            return new ClusterStateUpdateResponse(acknowledged);
        }

        @Override
        public ClusterState execute(ClusterState currentState) {
            RoutingTable.Builder routingTableBuilder = RoutingTable.builder(currentState.routingTable());
            MetaData.Builder metaDataBuilder = MetaData.builder(currentState.metaData());
            // allow to change any settings to a close index, and only allow dynamic settings to be changed
            // on an open index
            Set<Index> openIndices = new HashSet<>();
            Set<Index> closeIndices = new HashSet<>();
            final String[] actualIndices = new String[request.indices().length];
            for (int i = 0; i < request.indices().length; i++) {
                Index index = request.indices()[i];
                actualIndices[i] = index.getName();
                final IndexMetaData metaData = currentState.metaData().getIndexSafe(index);
                if (metaData.getState() == IndexMetaData.State.OPEN) {
                    openIndices.add(index);
                } else {
                    closeIndices.add(index);
                }
            }
            if (!skippedSettigns.isEmpty() && !openIndices.isEmpty()) {
                throw new IllegalArgumentException(String.format(Locale.ROOT, "Can't update non dynamic settings [%s] for open indices %s", skippedSettigns.getAsMap().keySet(), openIndices));
            }
            int updatedNumberOfReplicas = openSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, -1);
            if (updatedNumberOfReplicas != -1 && preserveExisting == false) {
                // we do *not* update the in sync allocation ids as they will be removed upon the first index
                // operation which make these copies stale
                // TODO: update the list once the data is deleted by the node?
                routingTableBuilder.updateNumberOfReplicas(updatedNumberOfReplicas, actualIndices);
                metaDataBuilder.updateNumberOfReplicas(updatedNumberOfReplicas, actualIndices);
                logger.info("updating number_of_replicas to [{}] for indices {}", updatedNumberOfReplicas, actualIndices);
            }
            ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks());
            maybeUpdateClusterBlock(actualIndices, blocks, IndexMetaData.INDEX_READ_ONLY_BLOCK, IndexMetaData.INDEX_READ_ONLY_SETTING, openSettings);
            maybeUpdateClusterBlock(actualIndices, blocks, IndexMetaData.INDEX_METADATA_BLOCK, IndexMetaData.INDEX_BLOCKS_METADATA_SETTING, openSettings);
            maybeUpdateClusterBlock(actualIndices, blocks, IndexMetaData.INDEX_WRITE_BLOCK, IndexMetaData.INDEX_BLOCKS_WRITE_SETTING, openSettings);
            maybeUpdateClusterBlock(actualIndices, blocks, IndexMetaData.INDEX_READ_BLOCK, IndexMetaData.INDEX_BLOCKS_READ_SETTING, openSettings);
            if (!openIndices.isEmpty()) {
                for (Index index : openIndices) {
                    IndexMetaData indexMetaData = metaDataBuilder.getSafe(index);
                    Settings.Builder updates = Settings.builder();
                    Settings.Builder indexSettings = Settings.builder().put(indexMetaData.getSettings());
                    if (indexScopedSettings.updateDynamicSettings(openSettings, indexSettings, updates, index.getName())) {
                        if (preserveExisting) {
                            indexSettings.put(indexMetaData.getSettings());
                        }
                        metaDataBuilder.put(IndexMetaData.builder(indexMetaData).settings(indexSettings));
                    }
                }
            }
            if (!closeIndices.isEmpty()) {
                for (Index index : closeIndices) {
                    IndexMetaData indexMetaData = metaDataBuilder.getSafe(index);
                    Settings.Builder updates = Settings.builder();
                    Settings.Builder indexSettings = Settings.builder().put(indexMetaData.getSettings());
                    if (indexScopedSettings.updateSettings(closedSettings, indexSettings, updates, index.getName())) {
                        if (preserveExisting) {
                            indexSettings.put(indexMetaData.getSettings());
                        }
                        metaDataBuilder.put(IndexMetaData.builder(indexMetaData).settings(indexSettings));
                    }
                }
            }
            ClusterState updatedState = ClusterState.builder(currentState).metaData(metaDataBuilder).routingTable(routingTableBuilder.build()).blocks(blocks).build();
            // now, reroute in case things change that require it (like number of replicas)
            updatedState = allocationService.reroute(updatedState, "settings update");
            try {
                for (Index index : openIndices) {
                    final IndexMetaData currentMetaData = currentState.getMetaData().getIndexSafe(index);
                    final IndexMetaData updatedMetaData = updatedState.metaData().getIndexSafe(index);
                    indicesService.verifyIndexMetadata(currentMetaData, updatedMetaData);
                }
                for (Index index : closeIndices) {
                    final IndexMetaData currentMetaData = currentState.getMetaData().getIndexSafe(index);
                    final IndexMetaData updatedMetaData = updatedState.metaData().getIndexSafe(index);
                    indicesService.verifyIndexMetadata(currentMetaData, updatedMetaData);
                }
            } catch (IOException ex) {
                throw ExceptionsHelper.convertToElastic(ex);
            }
            return updatedState;
        }
    });
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) HashSet(java.util.HashSet) Set(java.util.Set) Setting(org.elasticsearch.common.settings.Setting) Index(org.elasticsearch.index.Index) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) ClusterStateUpdateResponse(org.elasticsearch.cluster.ack.ClusterStateUpdateResponse) Settings(org.elasticsearch.common.settings.Settings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings)

Aggregations

Settings (org.elasticsearch.common.settings.Settings)1248 Test (org.junit.Test)197 IndexSettings (org.elasticsearch.index.IndexSettings)167 IOException (java.io.IOException)133 Path (java.nio.file.Path)121 ClusterState (org.elasticsearch.cluster.ClusterState)120 ArrayList (java.util.ArrayList)108 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)106 HashMap (java.util.HashMap)105 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)98 Version (org.elasticsearch.Version)91 Matchers.containsString (org.hamcrest.Matchers.containsString)91 Environment (org.elasticsearch.env.Environment)87 Map (java.util.Map)85 List (java.util.List)79 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)72 Index (org.elasticsearch.index.Index)70 HashSet (java.util.HashSet)58 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)54 ThreadPool (org.elasticsearch.threadpool.ThreadPool)54