Search in sources :

Example 21 with Settings

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

the class DecommissioningService method decommission.

private void decommission() {
    // fail on new requests so that clients don't use this node anymore
    sqlOperations.disable();
    /*
         * setting this setting will cause the {@link DecommissionAllocationDecider} to prevent allocations onto this node
         *
         * nodeIds are part of the key to prevent conflicts if other nodes are being decommissioned in parallel
         */
    Settings settings = Settings.builder().put(DECOMMISSION_PREFIX + clusterService.localNode().getId(), true).build();
    updateSettingsAction.execute(new ClusterUpdateSettingsRequest().transientSettings(settings), new ActionListener<ClusterUpdateSettingsResponse>() {

        @Override
        public void onResponse(ClusterUpdateSettingsResponse clusterUpdateSettingsResponse) {
            // changing settings triggers AllocationService.reroute -> shards will be relocated
            // NOTE: it waits for ALL relocating shards, not just those that involve THIS node.
            ClusterHealthRequest request = new ClusterHealthRequest().waitForRelocatingShards(0).waitForEvents(Priority.LANGUID).timeout(gracefulStopTimeout);
            if (dataAvailability == DataAvailability.FULL) {
                request = request.waitForGreenStatus();
            } else {
                request = request.waitForYellowStatus();
            }
            final long startTime = System.nanoTime();
            healthAction.execute(request, new ActionListener<ClusterHealthResponse>() {

                @Override
                public void onResponse(ClusterHealthResponse clusterHealthResponse) {
                    exitIfNoActiveRequests(startTime);
                }

                @Override
                public void onFailure(Throwable e) {
                    forceStopOrAbort(e);
                }
            });
        }

        @Override
        public void onFailure(Throwable e) {
            logger.error("Couldn't set settings. Graceful shutdown failed", e);
        }
    });
}
Also used : ActionListener(org.elasticsearch.action.ActionListener) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) ClusterUpdateSettingsResponse(org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse) CrateSettings(io.crate.metadata.settings.CrateSettings) Settings(org.elasticsearch.common.settings.Settings) ClusterUpdateSettingsRequest(org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest)

Example 22 with Settings

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

the class CreateRepositoryAnalyzer method analyze.

public CreateRepositoryAnalyzedStatement analyze(CreateRepository node, ParameterContext parameterContext) {
    String repositoryName = node.repository();
    if (repositoryService.getRepository(repositoryName) != null) {
        throw new RepositoryAlreadyExistsException(repositoryName);
    }
    Settings settings = repositoryParamValidator.convertAndValidate(node.type(), node.properties(), parameterContext);
    return new CreateRepositoryAnalyzedStatement(repositoryName, node.type(), settings);
}
Also used : RepositoryAlreadyExistsException(io.crate.exceptions.RepositoryAlreadyExistsException) Settings(org.elasticsearch.common.settings.Settings)

Example 23 with Settings

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

the class CreateSnapshotAnalyzer method analyze.

public CreateSnapshotAnalyzedStatement analyze(CreateSnapshot node, Analysis analysis) {
    Optional<QualifiedName> repositoryName = node.name().getPrefix();
    // validate repository
    Preconditions.checkArgument(repositoryName.isPresent(), "Snapshot must be specified by \"<repository_name>\".\"<snapshot_name>\"");
    Preconditions.checkArgument(repositoryName.get().getParts().size() == 1, String.format(Locale.ENGLISH, "Invalid repository name '%s'", repositoryName.get()));
    repositoryService.failIfRepositoryDoesNotExist(repositoryName.get().toString());
    // snapshot existence in repo is validated upon execution
    String snapshotName = node.name().getSuffix();
    SnapshotId snapshotId = new SnapshotId(repositoryName.get().toString(), snapshotName);
    // validate and extract settings
    Settings settings = GenericPropertiesConverter.settingsFromProperties(node.properties(), analysis.parameterContext(), SETTINGS).build();
    boolean ignoreUnavailable = settings.getAsBoolean(IGNORE_UNAVAILABLE.name(), IGNORE_UNAVAILABLE.defaultValue());
    // iterate tables
    if (node.tableList().isPresent()) {
        List<Table> tableList = node.tableList().get();
        Set<String> snapshotIndices = new HashSet<>(tableList.size());
        for (Table table : tableList) {
            TableInfo tableInfo;
            try {
                tableInfo = schemas.getTableInfo(TableIdent.of(table, analysis.sessionContext().defaultSchema()));
            } catch (ResourceUnknownException e) {
                if (ignoreUnavailable) {
                    LOGGER.info("ignoring: {}", e.getMessage());
                    continue;
                } else {
                    throw e;
                }
            }
            if (!(tableInfo instanceof DocTableInfo)) {
                throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Cannot create snapshot of tables in schema '%s'", tableInfo.ident().schema()));
            }
            Operation.blockedRaiseException(tableInfo, Operation.READ);
            DocTableInfo docTableInfo = (DocTableInfo) tableInfo;
            if (table.partitionProperties().isEmpty()) {
                snapshotIndices.addAll(Arrays.asList(docTableInfo.concreteIndices()));
            } else {
                PartitionName partitionName = PartitionPropertiesAnalyzer.toPartitionName(docTableInfo, table.partitionProperties(), analysis.parameterContext().parameters());
                if (!docTableInfo.partitions().contains(partitionName)) {
                    if (!ignoreUnavailable) {
                        throw new PartitionUnknownException(tableInfo.ident().fqn(), partitionName.ident());
                    } else {
                        LOGGER.info("ignoring unknown partition of table '{}' with ident '{}'", partitionName.tableIdent(), partitionName.ident());
                    }
                } else {
                    snapshotIndices.add(partitionName.asIndexName());
                }
            }
        }
        /**
             * For now, we always (in case there are indices to restore) include the globalMetaData,
             * not only if one of the tables in the table list is partitioned.
             * Previously we only included it in snapshots of full partitioned tables.
             * However, to make restoring of shapshots of single partitions work
             * we also need to include the global metadata (index templates).
             */
        return CreateSnapshotAnalyzedStatement.forTables(snapshotId, settings, ImmutableList.copyOf(snapshotIndices), !snapshotIndices.isEmpty());
    } else {
        for (SchemaInfo schemaInfo : schemas) {
            for (TableInfo tableInfo : schemaInfo) {
                // only check for user generated tables
                if (tableInfo instanceof DocTableInfo) {
                    Operation.blockedRaiseException(tableInfo, Operation.READ);
                }
            }
        }
        return CreateSnapshotAnalyzedStatement.all(snapshotId, settings);
    }
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) PartitionUnknownException(io.crate.exceptions.PartitionUnknownException) Table(io.crate.sql.tree.Table) QualifiedName(io.crate.sql.tree.QualifiedName) ResourceUnknownException(io.crate.exceptions.ResourceUnknownException) PartitionName(io.crate.metadata.PartitionName) SnapshotId(org.elasticsearch.cluster.metadata.SnapshotId) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) Settings(org.elasticsearch.common.settings.Settings) SchemaInfo(io.crate.metadata.table.SchemaInfo)

Example 24 with Settings

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

the class RestoreSnapshotAnalyzer method analyze.

public RestoreSnapshotAnalyzedStatement analyze(RestoreSnapshot node, Analysis analysis) {
    List<String> nameParts = node.name().getParts();
    Preconditions.checkArgument(nameParts.size() == 2, "Snapshot name not supported, only <repository>.<snapshot> works.");
    String repositoryName = nameParts.get(0);
    repositoryService.failIfRepositoryDoesNotExist(repositoryName);
    // validate and extract settings
    Settings settings = GenericPropertiesConverter.settingsFromProperties(node.properties(), analysis.parameterContext(), SETTINGS).build();
    if (node.tableList().isPresent()) {
        List<Table> tableList = node.tableList().get();
        Set<RestoreSnapshotAnalyzedStatement.RestoreTableInfo> restoreTables = new HashSet<>(tableList.size());
        for (Table table : tableList) {
            TableIdent tableIdent = TableIdent.of(table, analysis.sessionContext().defaultSchema());
            boolean tableExists = schemas.tableExists(tableIdent);
            if (tableExists) {
                if (table.partitionProperties().isEmpty()) {
                    throw new TableAlreadyExistsException(tableIdent);
                }
                TableInfo tableInfo = schemas.getTableInfo(tableIdent);
                if (!(tableInfo instanceof DocTableInfo)) {
                    throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Cannot restore snapshot of tables in schema '%s'", tableInfo.ident().schema()));
                }
                DocTableInfo docTableInfo = ((DocTableInfo) tableInfo);
                PartitionName partitionName = PartitionPropertiesAnalyzer.toPartitionName(tableIdent, docTableInfo, table.partitionProperties(), analysis.parameterContext().parameters());
                if (docTableInfo.partitions().contains(partitionName)) {
                    throw new PartitionAlreadyExistsException(partitionName);
                }
                restoreTables.add(new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(tableIdent, partitionName));
            } else {
                if (table.partitionProperties().isEmpty()) {
                    restoreTables.add(new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(tableIdent, null));
                } else {
                    PartitionName partitionName = PartitionPropertiesAnalyzer.toPartitionName(tableIdent, null, table.partitionProperties(), analysis.parameterContext().parameters());
                    restoreTables.add(new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(tableIdent, partitionName));
                }
            }
        }
        return RestoreSnapshotAnalyzedStatement.forTables(nameParts.get(1), repositoryName, settings, ImmutableList.copyOf(restoreTables));
    } else {
        return RestoreSnapshotAnalyzedStatement.all(nameParts.get(1), repositoryName, settings);
    }
}
Also used : TableAlreadyExistsException(io.crate.exceptions.TableAlreadyExistsException) DocTableInfo(io.crate.metadata.doc.DocTableInfo) Table(io.crate.sql.tree.Table) TableIdent(io.crate.metadata.TableIdent) PartitionName(io.crate.metadata.PartitionName) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) Settings(org.elasticsearch.common.settings.Settings) PartitionAlreadyExistsException(io.crate.exceptions.PartitionAlreadyExistsException) HashSet(java.util.HashSet)

Example 25 with Settings

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

the class CopyAnalyzer method settingsFromProperties.

private Settings settingsFromProperties(Map<String, Expression> properties, ExpressionAnalyzer expressionAnalyzer, ExpressionAnalysisContext expressionAnalysisContext) {
    Settings.Builder builder = Settings.builder();
    for (Map.Entry<String, Expression> entry : properties.entrySet()) {
        String key = entry.getKey();
        Expression expression = entry.getValue();
        if (expression instanceof ArrayLiteral) {
            throw new IllegalArgumentException("Invalid argument(s) passed to parameter");
        }
        if (expression instanceof QualifiedNameReference) {
            throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Can't use column reference in property assignment \"%s = %s\". Use literals instead.", key, ((QualifiedNameReference) expression).getName().toString()));
        }
        Symbol v = expressionAnalyzer.convert(expression, expressionAnalysisContext);
        if (!v.symbolType().isValueSymbol()) {
            throw new UnsupportedFeatureException("Only literals are allowed as parameter values");
        }
        builder.put(key, ValueSymbolVisitor.STRING.process(v));
    }
    return builder.build();
}
Also used : UnsupportedFeatureException(io.crate.exceptions.UnsupportedFeatureException) Symbol(io.crate.analyze.symbol.Symbol) ImmutableMap(com.google.common.collect.ImmutableMap) Settings(org.elasticsearch.common.settings.Settings)

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