use of org.elasticsearch.action.support.IndicesOptions in project crate by crate.
the class SnapshotRestoreDDLDispatcher method dispatch.
public CompletableFuture<Long> dispatch(final RestoreSnapshotAnalyzedStatement analysis) {
boolean waitForCompletion = analysis.settings().getAsBoolean(WAIT_FOR_COMPLETION.settingName(), WAIT_FOR_COMPLETION.defaultValue());
boolean ignoreUnavailable = analysis.settings().getAsBoolean(IGNORE_UNAVAILABLE.settingName(), IGNORE_UNAVAILABLE.defaultValue());
// ignore_unavailable as set by statement
IndicesOptions indicesOptions = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, IndicesOptions.lenientExpandOpen());
FutureActionListener<RestoreSnapshotResponse, Long> listener = new FutureActionListener<>(Functions.constant(1L));
resolveIndexNames(analysis.restoreTables(), ignoreUnavailable, transportActionProvider.transportGetSnapshotsAction(), analysis.repositoryName()).whenComplete((List<String> indexNames, Throwable t) -> {
if (t == null) {
RestoreSnapshotRequest request = new RestoreSnapshotRequest(analysis.repositoryName(), analysis.snapshotName()).indices(indexNames).indicesOptions(indicesOptions).settings(analysis.settings()).waitForCompletion(waitForCompletion).includeGlobalState(false).includeAliases(true);
transportActionProvider.transportRestoreSnapshotAction().execute(request, listener);
} else {
listener.onFailure(t);
}
});
return listener;
}
use of org.elasticsearch.action.support.IndicesOptions in project engine by craftercms.
the class SiteAwareElasticsearchService method updateIndex.
/**
* {@inheritDoc}
*/
@Override
protected void updateIndex(final SearchRequest request) {
SiteContext siteContext = SiteContext.getCurrent();
if (siteContext == null) {
throw new IllegalStateException("Current site context not found");
}
// Generate the default alias for the current site
String aliasName = String.format(indexIdFormat, siteContext.getSiteName());
// Get the requested indices
String[] currentIndices = request.indices();
String[] updatedIndices;
if (ArrayUtils.isNotEmpty(currentIndices)) {
updatedIndices = new String[currentIndices.length + 1];
// Add the site name prefix for all indices
for (int i = 0; i < currentIndices.length; i++) {
updatedIndices[i] = addPrefix(siteContext, currentIndices[i]);
}
// Also add the default index
updatedIndices[currentIndices.length] = aliasName;
// Add the site name prefix for the boosting if needed
List<SearchSourceBuilder.IndexBoost> indexBoosts = new ArrayList<>(request.source().indexBoosts());
if (isNotEmpty(indexBoosts)) {
indexBoosts.forEach(indexBoost -> request.source().indexBoost(addPrefix(siteContext, indexBoost.getIndex()), indexBoost.getBoost()));
// Prevent missing index errors, this is needed because the original index boost can't be removed
IndicesOptions originalOptions = request.indicesOptions();
request.indicesOptions(IndicesOptions.fromOptions(true, originalOptions.allowNoIndices(), originalOptions.expandWildcardsOpen(), originalOptions.expandWildcardsClosed(), originalOptions.allowAliasesToMultipleIndices(), originalOptions.forbidClosedIndices(), originalOptions.ignoreAliases(), originalOptions.ignoreThrottled()));
}
} else {
// Only query the default index
updatedIndices = new String[] { aliasName };
}
request.indices(updatedIndices);
}
use of org.elasticsearch.action.support.IndicesOptions in project crate by crate.
the class RestoreSnapshotPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row parameters, SubQueryResults subQueryResults) {
BoundRestoreSnapshot stmt = bind(restoreSnapshot, plannerContext.transactionContext(), dependencies.nodeContext(), parameters, subQueryResults, dependencies.schemas());
var settings = stmt.settings();
boolean ignoreUnavailable = IGNORE_UNAVAILABLE.get(settings);
var transportActionProvider = dependencies.transportActionProvider();
resolveIndexNames(restoreSnapshot.repository(), stmt.restoreTables(), ignoreUnavailable, transportActionProvider.transportGetSnapshotsAction()).whenComplete((ResolveIndicesAndTemplatesContext ctx, Throwable t) -> {
if (t == null) {
String[] indexNames = ctx.resolvedIndices().toArray(new String[0]);
String[] templateNames = stmt.includeTables() && stmt.restoreTables().isEmpty() ? new String[] { ALL_TEMPLATES } : ctx.resolvedTemplates().toArray(new String[0]);
// ignore_unavailable as set by statement
IndicesOptions indicesOptions = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, IndicesOptions.lenientExpandOpen());
RestoreSnapshotRequest request = new RestoreSnapshotRequest(restoreSnapshot.repository(), restoreSnapshot.snapshot()).indices(indexNames).templates(templateNames).indicesOptions(indicesOptions).settings(settings).waitForCompletion(WAIT_FOR_COMPLETION.get(settings)).includeIndices(stmt.includeTables()).includeAliases(stmt.includeTables()).includeCustomMetadata(stmt.includeCustomMetadata()).customMetadataTypes(stmt.customMetadataTypes()).includeGlobalSettings(stmt.includeGlobalSettings()).globalSettings(stmt.globalSettings());
transportActionProvider.transportRestoreSnapshotAction().execute(request, new OneRowActionListener<>(consumer, r -> new Row1(r == null ? -1L : 1L)));
}
});
}
use of org.elasticsearch.action.support.IndicesOptions in project crate by crate.
the class CreateSnapshotPlan method createRequest.
@VisibleForTesting
public static CreateSnapshotRequest createRequest(AnalyzedCreateSnapshot createSnapshot, CoordinatorTxnCtx txnCtx, NodeContext nodeCtx, Row parameters, SubQueryResults subQueryResults, Schemas schemas) {
Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(txnCtx, nodeCtx, x, parameters, subQueryResults);
Settings settings = GenericPropertiesConverter.genericPropertiesToSettings(createSnapshot.properties().map(eval), SnapshotSettings.SETTINGS);
boolean ignoreUnavailable = IGNORE_UNAVAILABLE.get(settings);
final HashSet<String> snapshotIndices;
final HashSet<String> templates = new HashSet<>();
if (createSnapshot.tables().isEmpty()) {
for (SchemaInfo schemaInfo : schemas) {
for (TableInfo tableInfo : schemaInfo.getTables()) {
// only check for user generated tables
if (tableInfo instanceof DocTableInfo) {
Operation.blockedRaiseException(tableInfo, Operation.READ);
}
}
}
snapshotIndices = new HashSet<>(AnalyzedCreateSnapshot.ALL_INDICES);
} else {
snapshotIndices = new HashSet<>(createSnapshot.tables().size());
for (Table<Symbol> table : createSnapshot.tables()) {
DocTableInfo docTableInfo;
try {
docTableInfo = (DocTableInfo) schemas.resolveTableInfo(table.getName(), Operation.CREATE_SNAPSHOT, txnCtx.sessionContext().sessionUser(), txnCtx.sessionContext().searchPath());
} catch (Exception e) {
if (ignoreUnavailable && e instanceof ResourceUnknownException) {
LOGGER.info("Ignore unknown relation '{}' for the '{}' snapshot'", table.getName(), createSnapshot.snapshot());
continue;
} else {
throw e;
}
}
if (docTableInfo.isPartitioned()) {
templates.add(PartitionName.templateName(docTableInfo.ident().schema(), docTableInfo.ident().name()));
}
if (table.partitionProperties().isEmpty()) {
snapshotIndices.addAll(Arrays.asList(docTableInfo.concreteIndices()));
} else {
var partitionName = toPartitionName(docTableInfo, Lists2.map(table.partitionProperties(), x -> x.map(eval)));
if (!docTableInfo.partitions().contains(partitionName)) {
if (!ignoreUnavailable) {
throw new PartitionUnknownException(partitionName);
} else {
LOGGER.info("ignoring unknown partition of table '{}' with ident '{}'", partitionName.relationName(), partitionName.ident());
}
} else {
snapshotIndices.add(partitionName.asIndexName());
}
}
}
}
return new CreateSnapshotRequest(createSnapshot.snapshot().getRepository(), createSnapshot.snapshot().getSnapshotId().getName()).includeGlobalState(createSnapshot.tables().isEmpty()).waitForCompletion(WAIT_FOR_COMPLETION.get(settings)).indices(snapshotIndices.toArray(new String[0])).indicesOptions(IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, IndicesOptions.lenientExpandOpen())).templates(templates.stream().toList()).settings(settings);
}
use of org.elasticsearch.action.support.IndicesOptions in project crate by crate.
the class DeleteAllPartitions method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier executor, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
if (partitions.isEmpty()) {
consumer.accept(InMemoryBatchIterator.of(new Row1(0L), SentinelRow.SENTINEL), null);
} else {
/*
* table is partitioned, in case of concurrent "delete from partitions"
* it could be that some partitions are already deleted,
* so ignore it if some are missing
*/
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(partitions().toArray(new String[0])).indicesOptions(IndicesOptions.lenientExpandOpen());
executor.transportActionProvider().transportDeleteIndexAction().execute(deleteIndexRequest, new OneRowActionListener<>(consumer, r -> Row1.ROW_COUNT_UNKNOWN));
}
}
Aggregations