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);
}
});
}
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);
}
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);
}
}
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);
}
}
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();
}
Aggregations