Search in sources :

Example 1 with ResizeResponse

use of org.elasticsearch.action.admin.indices.shrink.ResizeResponse in project crate by crate.

the class AlterTableOperation method resizeIndex.

private CompletableFuture<Long> resizeIndex(IndexMetadata sourceIndex, @Nullable String sourceIndexAlias, String targetIndexName, int targetNumberOfShards) {
    Settings targetIndexSettings = Settings.builder().put(SETTING_NUMBER_OF_SHARDS, targetNumberOfShards).build();
    int currentNumShards = sourceIndex.getNumberOfShards();
    ResizeRequest request = new ResizeRequest(targetIndexName, sourceIndex.getIndex().getName());
    request.getTargetIndexRequest().settings(targetIndexSettings);
    if (sourceIndexAlias != null) {
        request.getTargetIndexRequest().alias(new Alias(sourceIndexAlias));
    }
    request.setResizeType(targetNumberOfShards > currentNumShards ? ResizeType.SPLIT : ResizeType.SHRINK);
    request.setCopySettings(Boolean.TRUE);
    request.setWaitForActiveShards(ActiveShardCount.ONE);
    FutureActionListener<ResizeResponse, Long> listener = new FutureActionListener<>(resp -> resp.isAcknowledged() ? 1L : 0L);
    transportResizeAction.execute(request, listener);
    return listener;
}
Also used : ResizeResponse(org.elasticsearch.action.admin.indices.shrink.ResizeResponse) Alias(org.elasticsearch.action.admin.indices.alias.Alias) FutureActionListener(io.crate.action.FutureActionListener) Settings(org.elasticsearch.common.settings.Settings) ResizeRequest(org.elasticsearch.action.admin.indices.shrink.ResizeRequest)

Aggregations

FutureActionListener (io.crate.action.FutureActionListener)1 Alias (org.elasticsearch.action.admin.indices.alias.Alias)1 ResizeRequest (org.elasticsearch.action.admin.indices.shrink.ResizeRequest)1 ResizeResponse (org.elasticsearch.action.admin.indices.shrink.ResizeResponse)1 Settings (org.elasticsearch.common.settings.Settings)1