org.elasticsearch.action.support.ActiveShardCount Java Examples

The following examples show how to use org.elasticsearch.action.support.ActiveShardCount. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AlterTableOperation.java    From crate with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: ReplicationOperation.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether we can perform a write based on the required active shard count setting.
 * Returns **null* if OK to proceed, or a string describing the reason to stop
 */
protected String checkActiveShardCount() {
    final ShardId shardId = primary.routingEntry().shardId();
    final ActiveShardCount waitForActiveShards = request.waitForActiveShards();
    if (waitForActiveShards == ActiveShardCount.NONE) {
        return null;  // not waiting for any shards
    }
    final IndexShardRoutingTable shardRoutingTable = primary.getReplicationGroup().getRoutingTable();
    if (waitForActiveShards.enoughShardsActive(shardRoutingTable)) {
        return null;
    } else {
        final String resolvedShards = waitForActiveShards == ActiveShardCount.ALL ? Integer.toString(shardRoutingTable.shards().size())
                                          : waitForActiveShards.toString();
        logger.trace("[{}] not enough active copies to meet shard count of [{}] (have {}, needed {}), scheduling a retry. op [{}], " +
                     "request [{}]", shardId, waitForActiveShards, shardRoutingTable.activeShards().size(),
                     resolvedShards, opType, request);
        return "Not enough active copies to meet shard count of [" + waitForActiveShards + "] (have " +
                   shardRoutingTable.activeShards().size() + ", needed " + resolvedShards + ").";
    }
}
 
Example #3
Source File: ClusterHealthRequest.java    From crate with Apache License 2.0 6 votes vote down vote up
public ClusterHealthRequest(StreamInput in) throws IOException {
    super(in);
    int size = in.readVInt();
    if (size == 0) {
        indices = Strings.EMPTY_ARRAY;
    } else {
        indices = new String[size];
        for (int i = 0; i < indices.length; i++) {
            indices[i] = in.readString();
        }
    }
    timeout = in.readTimeValue();
    if (in.readBoolean()) {
        waitForStatus = ClusterHealthStatus.fromValue(in.readByte());
    }
    waitForNoRelocatingShards = in.readBoolean();
    waitForActiveShards = ActiveShardCount.readFrom(in);
    waitForNodes = in.readString();
    if (in.readBoolean()) {
        waitForEvents = Priority.readFrom(in);
    }
    waitForNoInitializingShards = in.readBoolean();
}
 
Example #4
Source File: CreateIndexRequest.java    From crate with Apache License 2.0 6 votes vote down vote up
public CreateIndexRequest(StreamInput in) throws IOException {
    super(in);
    cause = in.readString();
    index = in.readString();
    settings = readSettingsFromStream(in);
    int size = in.readVInt();
    for (int i = 0; i < size; i++) {
        final String type = in.readString();
        String source = in.readString();
        mappings.put(type, source);
    }
    int aliasesSize = in.readVInt();
    for (int i = 0; i < aliasesSize; i++) {
        aliases.add(new Alias(in));
    }
    updateAllTypes = in.readBoolean();
    waitForActiveShards = ActiveShardCount.readFrom(in);
}
 
Example #5
Source File: TransportCreatePartitionsAction.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected void masterOperation(final CreatePartitionsRequest request,
                               final ClusterState state,
                               final ActionListener<AcknowledgedResponse> listener) throws ElasticsearchException {

    if (request.indices().isEmpty()) {
        listener.onResponse(new AcknowledgedResponse(true));
        return;
    }

    createIndices(request, ActionListener.wrap(response -> {
        if (response.isAcknowledged()) {
            activeShardsObserver.waitForActiveShards(request.indices().toArray(new String[0]), ActiveShardCount.DEFAULT, request.ackTimeout(),
                shardsAcked -> {
                    if (!shardsAcked && logger.isInfoEnabled()) {
                        String partitionTemplateName = PartitionName.templateName(request.indices().iterator().next());
                        IndexTemplateMetaData templateMetaData = state.metaData().getTemplates().get(partitionTemplateName);

                        logger.info("[{}] Table partitions created, but the operation timed out while waiting for " +
                                     "enough shards to be started. Timeout={}, wait_for_active_shards={}. " +
                                     "Consider decreasing the 'number_of_shards' table setting (currently: {}) or adding nodes to the cluster.",
                            request.indices(), request.timeout(),
                            SETTING_WAIT_FOR_ACTIVE_SHARDS.get(templateMetaData.getSettings()),
                            INDEX_NUMBER_OF_SHARDS_SETTING.get(templateMetaData.getSettings()));
                    }
                    listener.onResponse(new AcknowledgedResponse(response.isAcknowledged()));
                }, listener::onFailure);
        } else {
            logger.warn("[{}] Table partitions created, but publishing new cluster state timed out. Timeout={}",
                request.indices(), request.timeout());
            listener.onResponse(new AcknowledgedResponse(false));
        }
    }, listener::onFailure));
}
 
Example #6
Source File: ReplicationOperationTests.java    From crate with Apache License 2.0 5 votes vote down vote up
Request(ShardId shardId) {
    this();
    this.shardId = shardId;
    this.index = shardId.getIndexName();
    this.waitForActiveShards = ActiveShardCount.NONE;
    // keep things simple
}
 
Example #7
Source File: ESIntegTestCase.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a settings object used in {@link #createIndex(String...)} and {@link #prepareCreate(String)} and friends.
 * This method can be overwritten by subclasses to set defaults for the indices that are created by the test.
 * By default it returns a settings object that sets a random number of shards. Number of shards and replicas
 * can be controlled through specific methods.
 */
public Settings indexSettings() {
    Settings.Builder builder = Settings.builder();
    int numberOfShards = numberOfShards();
    if (numberOfShards > 0) {
        builder.put(SETTING_NUMBER_OF_SHARDS, numberOfShards).build();
    }
    int numberOfReplicas = numberOfReplicas();
    if (numberOfReplicas >= 0) {
        builder.put(SETTING_NUMBER_OF_REPLICAS, numberOfReplicas).build();
    }
    // 30% of the time
    if (randomInt(9) < 3) {
        final String dataPath = randomAlphaOfLength(10);
        logger.info("using custom data_path for index: [{}]", dataPath);
        builder.put(IndexMetaData.SETTING_DATA_PATH, dataPath);
    }
    // always default delayed allocation to 0 to make sure we have tests are not delayed
    builder.put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), 0);
    builder.put(SETTING_AUTO_EXPAND_REPLICAS, "false");
    builder.put(SETTING_WAIT_FOR_ACTIVE_SHARDS.getKey(), ActiveShardCount.ONE.toString());
    builder.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean());
    if (randomBoolean()) {
        builder.put(IndexSettings.INDEX_SOFT_DELETES_RETENTION_OPERATIONS_SETTING.getKey(), between(0, 1000));
    }
    return builder.build();
}
 
Example #8
Source File: ActionListeners.java    From crate with Apache License 2.0 5 votes vote down vote up
public static <T extends AcknowledgedResponse> ActionListener<T> waitForShards(ActionListener<T> delegate,
                                                                               ActiveShardsObserver observer,
                                                                               TimeValue timeout,
                                                                               Runnable onShardsNotAcknowledged,
                                                                               Supplier<String[]> indices) {

    return ActionListener.wrap(
        resp -> {
            if (resp.isAcknowledged()) {
                observer.waitForActiveShards(
                    indices.get(),
                    ActiveShardCount.DEFAULT,
                    timeout,
                    shardsAcknowledged -> {
                        if (!shardsAcknowledged) {
                            onShardsNotAcknowledged.run();
                        }
                        delegate.onResponse(resp);
                    },
                    delegate::onFailure
                );
            } else {
                delegate.onResponse(resp);
            }
        },
        delegate::onFailure
    );
}
 
Example #9
Source File: TransportReplicationAction.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves derived values in the request. For example, the target shard id of the incoming request, if not set at request construction.
 * Additional processing or validation of the request should be done here.
 *
 * @param indexMetaData index metadata of the concrete index this request is going to operate on
 * @param request       the request to resolve
 */
protected void resolveRequest(final IndexMetaData indexMetaData, final Request request) {
    if (request.waitForActiveShards() == ActiveShardCount.DEFAULT) {
        // if the wait for active shard count has not been set in the request,
        // resolve it from the index settings
        request.waitForActiveShards(indexMetaData.getWaitForActiveShards());
    }
}
 
Example #10
Source File: ReplicationRequest.java    From crate with Apache License 2.0 5 votes vote down vote up
public ReplicationRequest(StreamInput in) throws IOException {
    super(in);
    if (in.readBoolean()) {
        shardId = new ShardId(in);
    } else {
        shardId = null;
    }
    waitForActiveShards = ActiveShardCount.readFrom(in);
    timeout = in.readTimeValue();
    index = in.readString();
    routedBasedOnClusterVersion = in.readVLong();
}
 
Example #11
Source File: ClusterHealthRequestBuilder.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the number of shard copies that must be active before getting the health status.
 * Defaults to {@link ActiveShardCount#NONE}, meaning we don't wait on any active shards.
 * Set this value to {@link ActiveShardCount#ALL} to wait for all shards (primary and
 * all replicas) to be active across all indices in the cluster. Otherwise, use
 * {@link ActiveShardCount#from(int)} to set this value to any non-negative integer, up to the
 * total number of shard copies that would exist across all indices in the cluster.
 */
public ClusterHealthRequestBuilder setWaitForActiveShards(ActiveShardCount waitForActiveShards) {
    if (waitForActiveShards.equals(ActiveShardCount.DEFAULT)) {
        // the default for cluster health is 0, not 1
        request.waitForActiveShards(ActiveShardCount.NONE);
    } else {
        request.waitForActiveShards(waitForActiveShards);
    }
    return this;
}
 
Example #12
Source File: EsPublisher.java    From tunnel with Apache License 2.0 5 votes vote down vote up
private BulkRequest createBulkRequest(List<DocWriteRequest> doc) {
    BulkRequest br = new BulkRequest();
    br.add(doc);
    br.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
    br.waitForActiveShards(ActiveShardCount.ONE);
    return br;
}
 
Example #13
Source File: EsPublisher.java    From tunnel with Apache License 2.0 5 votes vote down vote up
private BulkRequest createBulkRequest(List<DocWriteRequest> doc) {
    BulkRequest br = new BulkRequest();
    br.add(doc);
    br.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
    br.waitForActiveShards(ActiveShardCount.ONE);
    return br;
}
 
Example #14
Source File: DefaultElasticSearchService.java    From vertx-elasticsearch-service with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteByQuery(List<String> indices, DeleteByQueryOptions options, Handler<AsyncResult<com.hubrick.vertx.elasticsearch.model.DeleteByQueryResponse>> resultHandler) {
    final DeleteByQueryRequestBuilder deleteByQueryRequestBuilder = new DeleteByQueryRequestBuilder(client, DeleteByQueryAction.INSTANCE);

    deleteByQueryRequestBuilder.source(indices.toArray(new String[indices.size()]));
    if (options != null) {
        populateSearchRequestBuilder(deleteByQueryRequestBuilder.source(), options);
        if (options.getMaxRetries() != null) deleteByQueryRequestBuilder.setMaxRetries(options.getMaxRetries());
        if (options.getSlices() != null) deleteByQueryRequestBuilder.setSlices(options.getSlices());
        if (options.getWaitForActiveShards() != null)
            deleteByQueryRequestBuilder.waitForActiveShards(ActiveShardCount.from(options.getWaitForActiveShards()));
        if (options.getConflicts() != null)
            deleteByQueryRequestBuilder.abortOnVersionConflict(Optional.ofNullable(options.getConflicts()).map(e -> !Conflicts.PROCEED.equals(e)).orElse(true));
        if (options.getRequestsPerSecond() != null)
            deleteByQueryRequestBuilder.setRequestsPerSecond(options.getRequestsPerSecond());
    }

    deleteByQueryRequestBuilder.execute(new ActionListener<BulkByScrollResponse>() {
        @Override
        public void onResponse(BulkByScrollResponse deleteByQueryResponse) {
            resultHandler.handle(Future.succeededFuture(mapToDeleteByQueryResponse(deleteByQueryResponse)));
        }

        @Override
        public void onFailure(Exception t) {
            handleFailure(resultHandler, t);
        }
    });
}
 
Example #15
Source File: ElasticSearch7Client.java    From skywalking with Apache License 2.0 5 votes vote down vote up
public void synchronousBulk(BulkRequest request) {
    request.timeout(TimeValue.timeValueMinutes(2));
    request.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL);
    request.waitForActiveShards(ActiveShardCount.ONE);
    try {
        int size = request.requests().size();
        BulkResponse responses = client.bulk(request, RequestOptions.DEFAULT);
        log.info("Synchronous bulk took time: {} millis, size: {}", responses.getTook().getMillis(), size);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }
}
 
Example #16
Source File: ElasticSearchClient.java    From skywalking with Apache License 2.0 5 votes vote down vote up
public void synchronousBulk(BulkRequest request) {
    request.timeout(TimeValue.timeValueMinutes(2));
    request.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL);
    request.waitForActiveShards(ActiveShardCount.ONE);
    try {
        int size = request.requests().size();
        BulkResponse responses = client.bulk(request);
        log.info("Synchronous bulk took time: {} millis, size: {}", responses.getTook().getMillis(), size);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }
}
 
Example #17
Source File: IndexMetaData.java    From crate with Apache License 2.0 5 votes vote down vote up
private IndexMetaData(Index index, long version, long mappingVersion, long settingsVersion, long[] primaryTerms, State state, int numberOfShards, int numberOfReplicas, Settings settings,
                      ImmutableOpenMap<String, MappingMetaData> mappings, ImmutableOpenMap<String, AliasMetaData> aliases,
                      ImmutableOpenMap<String, DiffableStringMap> customData, ImmutableOpenIntMap<Set<String>> inSyncAllocationIds,
                      DiscoveryNodeFilters requireFilters, DiscoveryNodeFilters initialRecoveryFilters, DiscoveryNodeFilters includeFilters, DiscoveryNodeFilters excludeFilters,
                      Version indexCreatedVersion, Version indexUpgradedVersion,
                      int routingNumShards, int routingPartitionSize, ActiveShardCount waitForActiveShards) {

    this.index = index;
    this.version = version;
    assert mappingVersion >= 0 : mappingVersion;
    this.mappingVersion = mappingVersion;
    assert settingsVersion >= 0 : settingsVersion;
    this.settingsVersion = settingsVersion;
    this.primaryTerms = primaryTerms;
    assert primaryTerms.length == numberOfShards;
    this.state = state;
    this.numberOfShards = numberOfShards;
    this.numberOfReplicas = numberOfReplicas;
    this.totalNumberOfShards = numberOfShards * (numberOfReplicas + 1);
    this.settings = settings;
    this.mappings = mappings;
    this.customData = customData;
    this.aliases = aliases;
    this.inSyncAllocationIds = inSyncAllocationIds;
    this.requireFilters = requireFilters;
    this.includeFilters = includeFilters;
    this.excludeFilters = excludeFilters;
    this.initialRecoveryFilters = initialRecoveryFilters;
    this.indexCreatedVersion = indexCreatedVersion;
    this.indexUpgradedVersion = indexUpgradedVersion;
    this.routingNumShards = routingNumShards;
    this.routingFactor = routingNumShards / numberOfShards;
    this.routingPartitionSize = routingPartitionSize;
    this.waitForActiveShards = waitForActiveShards;
    assert numberOfShards * routingFactor == routingNumShards : routingNumShards + " must be a multiple of " + numberOfShards;
}
 
Example #18
Source File: ReplicationRequest.java    From crate with Apache License 2.0 4 votes vote down vote up
public ActiveShardCount waitForActiveShards() {
    return this.waitForActiveShards;
}
 
Example #19
Source File: ReplicationOperationTests.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testWaitForActiveShards() throws Exception {
    final String index = "test";
    final ShardId shardId = new ShardId(index, "_na_", 0);
    final int assignedReplicas = randomInt(2);
    final int unassignedReplicas = randomInt(2);
    final int totalShards = 1 + assignedReplicas + unassignedReplicas;
    final int activeShardCount = randomIntBetween(0, totalShards);
    Request request = new Request(shardId).waitForActiveShards(
        activeShardCount == totalShards ? ActiveShardCount.ALL : ActiveShardCount.from(activeShardCount));
    final boolean passesActiveShardCheck = activeShardCount <= assignedReplicas + 1;

    ShardRoutingState[] replicaStates = new ShardRoutingState[assignedReplicas + unassignedReplicas];
    for (int i = 0; i < assignedReplicas; i++) {
        replicaStates[i] = randomFrom(ShardRoutingState.STARTED, ShardRoutingState.RELOCATING);
    }
    for (int i = assignedReplicas; i < replicaStates.length; i++) {
        replicaStates[i] = ShardRoutingState.UNASSIGNED;
    }

    final ClusterState state = state(index, true, ShardRoutingState.STARTED, replicaStates);
    logger.debug("using active shard count of [{}], assigned shards [{}], total shards [{}]." +
                 " expecting op to [{}]. using state: \n{}",
                 request.waitForActiveShards(), 1 + assignedReplicas, 1 + assignedReplicas + unassignedReplicas,
                 passesActiveShardCheck ? "succeed" : "retry", state);
    final long primaryTerm = state.metaData().index(index).primaryTerm(shardId.id());
    final IndexShardRoutingTable shardRoutingTable = state.routingTable().index(index).shard(shardId.id());

    final Set<String> inSyncAllocationIds = state.metaData().index(index).inSyncAllocationIds(0);
    Set<String> trackedShards = new HashSet<>();
    addTrackingInfo(shardRoutingTable, null, trackedShards, new HashSet<>());
    final ReplicationGroup initialReplicationGroup = new ReplicationGroup(shardRoutingTable, inSyncAllocationIds, trackedShards);

    PlainActionFuture<TestPrimary.Result> listener = new PlainActionFuture<>();
    final ShardRouting primaryShard = shardRoutingTable.primaryShard();
    final TestReplicationOperation op = new TestReplicationOperation(request,
                                                                     new TestPrimary(primaryShard, () -> initialReplicationGroup),
                                                                     listener, new TestReplicaProxy(primaryTerm), logger, "test");

    if (passesActiveShardCheck) {
        assertThat(op.checkActiveShardCount(), nullValue());
        op.execute();
        assertTrue("operations should have been performed, active shard count is met",
                   request.processedOnPrimary.get());
    } else {
        assertThat(op.checkActiveShardCount(), notNullValue());
        op.execute();
        assertFalse("operations should not have been perform, active shard count is *NOT* met",
                    request.processedOnPrimary.get());
        assertListenerThrows("should throw exception to trigger retry", listener, UnavailableShardsException.class);
    }
}
 
Example #20
Source File: InformationPartitionsTableInfo.java    From crate with Apache License 2.0 4 votes vote down vote up
public static SystemTable<PartitionInfo> create() {
    return SystemTable.<PartitionInfo>builder(IDENT)
        .add("table_schema", STRING, r -> r.name().relationName().schema())
        .add("table_name", STRING, r -> r.name().relationName().name())
        .add("partition_ident", STRING, r -> r.name().ident())
        .addDynamicObject("values", STRING, PartitionInfo::values)
        .add("number_of_shards", INTEGER, PartitionInfo::numberOfShards)
        .add("number_of_replicas", STRING, PartitionInfo::numberOfReplicas)
        .add("routing_hash_function", STRING, r -> IndexMappings.DEFAULT_ROUTING_HASH_FUNCTION_PRETTY_NAME)
        .add("closed", BOOLEAN, PartitionInfo::isClosed)
        .startObject("version")
            .add(Version.Property.CREATED.toString(), STRING, r -> r.versionCreated().externalNumber())
            .add(Version.Property.UPGRADED.toString(), STRING, r -> r.versionUpgraded().externalNumber())
        .endObject()
        .startObject("settings")
            .startObject("blocks")
                .add("read_only", BOOLEAN, fromSetting(IndexMetaData.INDEX_READ_ONLY_SETTING))
                .add("read", BOOLEAN, fromSetting(IndexMetaData.INDEX_BLOCKS_READ_SETTING))
                .add("write", BOOLEAN, fromSetting(IndexMetaData.INDEX_BLOCKS_WRITE_SETTING))
                .add("metadata", BOOLEAN, fromSetting(IndexMetaData.INDEX_BLOCKS_METADATA_SETTING))
            .endObject()

            .add("codec", STRING, fromSetting(INDEX_CODEC_SETTING))

            .startObject("store")
                .add("type", STRING, fromSetting(IndexModule.INDEX_STORE_TYPE_SETTING))
            .endObject()

            .startObject("translog")
                .add("flush_threshold_size", LONG, fromByteSize(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING))
                .add("sync_interval", LONG, fromTimeValue(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING))
                .add("durability", STRING, fromSetting(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING, Translog.Durability::name))
            .endObject()

            .startObject("routing")
                .startObject("allocation")
                    .add("enable", STRING, fromSetting(EnableAllocationDecider.INDEX_ROUTING_ALLOCATION_ENABLE_SETTING, EnableAllocationDecider.Allocation::toString))
                    .add("total_shards_per_node", INTEGER, fromSetting(ShardsLimitAllocationDecider.INDEX_TOTAL_SHARDS_PER_NODE_SETTING))
                .endObject()
            .endObject()

            .startObject("warmer")
                .add("enabled", BOOLEAN, fromSetting(IndexSettings.INDEX_WARMER_ENABLED_SETTING))
            .endObject()

            .startObject("unassigned")
                .startObject("node_left")
                    .add("delayed_timeout", LONG, fromTimeValue(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING))
                .endObject()
            .endObject()

            .startObject("mapping")
                .startObject("total_fields")
                    .add("limit", INTEGER, fromSetting(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING, INTEGER::value))
                .endObject()
            .endObject()

            .startObject("merge")
                .startObject("scheduler")
                    .add("max_thread_count", INTEGER, fromSetting(MAX_THREAD_COUNT_SETTING))
                    .add("max_merge_count", INTEGER, fromSetting(MAX_MERGE_COUNT_SETTING))
                .endObject()
            .endObject()

            .startObject("write")
                .add("wait_for_active_shards", STRING, fromSetting(IndexMetaData.SETTING_WAIT_FOR_ACTIVE_SHARDS, ActiveShardCount::toString))
            .endObject()

        .endObject()
        .setPrimaryKeys(
            new ColumnIdent("table_schema"),
            new ColumnIdent("table_name"),
            new ColumnIdent("partition_ident")
        )
        .build();
}
 
Example #21
Source File: ReplicationRequestBuilder.java    From crate with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the number of shard copies that must be active before proceeding with the write.
 * See {@link ReplicationRequest#waitForActiveShards(ActiveShardCount)} for details.
 */
@SuppressWarnings("unchecked")
public RequestBuilder setWaitForActiveShards(ActiveShardCount waitForActiveShards) {
    request.waitForActiveShards(waitForActiveShards);
    return (RequestBuilder) this;
}
 
Example #22
Source File: TransportRefreshAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected BasicReplicationRequest newShardRequest(RefreshRequest request, ShardId shardId) {
    BasicReplicationRequest replicationRequest = new BasicReplicationRequest(shardId);
    replicationRequest.waitForActiveShards(ActiveShardCount.NONE);
    return replicationRequest;
}
 
Example #23
Source File: ClusterHealthRequest.java    From crate with Apache License 2.0 4 votes vote down vote up
public ActiveShardCount waitForActiveShards() {
    return waitForActiveShards;
}
 
Example #24
Source File: CreateIndexClusterStateUpdateRequest.java    From crate with Apache License 2.0 4 votes vote down vote up
public ActiveShardCount waitForActiveShards() {
    return waitForActiveShards;
}
 
Example #25
Source File: ShardFlushRequest.java    From crate with Apache License 2.0 4 votes vote down vote up
public ShardFlushRequest(FlushRequest request, ShardId shardId) {
    super(shardId);
    this.request = request;
    this.waitForActiveShards = ActiveShardCount.NONE; // don't wait for any active shards before proceeding, by default
}
 
Example #26
Source File: CreateIndexRequest.java    From crate with Apache License 2.0 4 votes vote down vote up
public ActiveShardCount waitForActiveShards() {
    return waitForActiveShards;
}
 
Example #27
Source File: ResizeRequestBuilder.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the number of shard copies that should be active for creation of the
 * new shrunken index to return. Defaults to {@link ActiveShardCount#DEFAULT}, which will
 * wait for one shard copy (the primary) to become active. Set this value to
 * {@link ActiveShardCount#ALL} to wait for all shards (primary and all replicas) to be active
 * before returning. Otherwise, use {@link ActiveShardCount#from(int)} to set this value to any
 * non-negative integer, up to the number of copies per shard (number of replicas + 1),
 * to wait for the desired amount of shard copies to become active before returning.
 * Index creation will only wait up until the timeout value for the number of shard copies
 * to be active before returning.  Check {@link ResizeResponse#isShardsAcknowledged()} to
 * determine if the requisite shard copies were all started before returning or timing out.
 *
 * @param waitForActiveShards number of active shard copies to wait on
 */
public ResizeRequestBuilder setWaitForActiveShards(ActiveShardCount waitForActiveShards) {
    this.request.setWaitForActiveShards(waitForActiveShards);
    return this;
}
 
Example #28
Source File: ResizeRequestBuilder.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * A shortcut for {@link #setWaitForActiveShards(ActiveShardCount)} where the numerical
 * shard count is passed in, instead of having to first call {@link ActiveShardCount#from(int)}
 * to get the ActiveShardCount.
 */
public ResizeRequestBuilder setWaitForActiveShards(final int waitForActiveShards) {
    return setWaitForActiveShards(ActiveShardCount.from(waitForActiveShards));
}
 
Example #29
Source File: IndexMetaData.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the configured {@link #SETTING_WAIT_FOR_ACTIVE_SHARDS}, which defaults
 * to an active shard count of 1 if not specified.
 */
public ActiveShardCount getWaitForActiveShards() {
    return waitForActiveShards;
}
 
Example #30
Source File: ResizeRequest.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the number of shard copies that should be active for creation of the
 * new shrunken index to return. Defaults to {@link ActiveShardCount#DEFAULT}, which will
 * wait for one shard copy (the primary) to become active. Set this value to
 * {@link ActiveShardCount#ALL} to wait for all shards (primary and all replicas) to be active
 * before returning. Otherwise, use {@link ActiveShardCount#from(int)} to set this value to any
 * non-negative integer, up to the number of copies per shard (number of replicas + 1),
 * to wait for the desired amount of shard copies to become active before returning.
 * Index creation will only wait up until the timeout value for the number of shard copies
 * to be active before returning.  Check {@link ResizeResponse#isShardsAcknowledged()} to
 * determine if the requisite shard copies were all started before returning or timing out.
 *
 * @param waitForActiveShards number of active shard copies to wait on
 */
public void setWaitForActiveShards(ActiveShardCount waitForActiveShards) {
    this.getTargetIndexRequest().waitForActiveShards(waitForActiveShards);
}