Search in sources :

Example 36 with TimeValue

use of io.crate.common.unit.TimeValue in project crate by crate.

the class ProcessInfo method toXContent.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject(Fields.PROCESS);
    builder.humanReadableField(Fields.REFRESH_INTERVAL_IN_MILLIS, Fields.REFRESH_INTERVAL, new TimeValue(refreshInterval));
    builder.field(Fields.ID, id);
    builder.field(Fields.MLOCKALL, mlockall);
    builder.endObject();
    return builder;
}
Also used : TimeValue(io.crate.common.unit.TimeValue)

Example 37 with TimeValue

use of io.crate.common.unit.TimeValue in project crate by crate.

the class MasterDisruptionIT method testVerifyApiBlocksDuringPartition.

/**
 * Verify that the proper block is applied when nodes lose their master
 */
@Test
public void testVerifyApiBlocksDuringPartition() throws Exception {
    internalCluster().startNodes(3);
    logger.info("creating table t with 1 shards and 2 replicas");
    execute("create table t (id int primary key, x string) clustered into 1 shards with " + "(number_of_replicas = 2)");
    // Everything is stable now, it is now time to simulate evil...
    // but first make sure we have no initializing shards and all is green
    // (waiting for green here, because indexing / search in a yellow index is fine as long as no other nodes go down)
    ensureGreen();
    TwoPartitions partitions = TwoPartitions.random(random(), internalCluster().getNodeNames());
    NetworkDisruption networkDisruption = addRandomDisruptionType(partitions);
    assertEquals(1, partitions.getMinoritySide().size());
    final String isolatedNode = partitions.getMinoritySide().iterator().next();
    assertEquals(2, partitions.getMajoritySide().size());
    final String nonIsolatedNode = partitions.getMajoritySide().iterator().next();
    // Simulate a network issue between the unlucky node and the rest of the cluster.
    networkDisruption.startDisrupting();
    // The unlucky node must report *no* master node, since it can't connect to master and in fact it should
    // continuously ping until network failures have been resolved. However
    // It may a take a bit before the node detects it has been cut off from the elected master
    logger.info("waiting for isolated node [{}] to have no master", isolatedNode);
    assertNoMaster(isolatedNode, NoMasterBlockService.NO_MASTER_BLOCK_WRITES, TimeValue.timeValueSeconds(30));
    logger.info("wait until elected master has been removed and a new 2 node cluster was from (via [{}])", isolatedNode);
    ensureStableCluster(2, nonIsolatedNode);
    for (String node : partitions.getMajoritySide()) {
        ClusterState nodeState = getNodeClusterState(node);
        boolean success = true;
        if (nodeState.nodes().getMasterNode() == null) {
            success = false;
        }
        if (!nodeState.blocks().global().isEmpty()) {
            success = false;
        }
        if (!success) {
            fail("node [" + node + "] has no master or has blocks, despite of being on the right side of the partition. State dump:\n" + nodeState);
        }
    }
    networkDisruption.stopDisrupting();
    // Wait until the master node sees al 3 nodes again.
    ensureStableCluster(3, new TimeValue(DISRUPTION_HEALING_OVERHEAD.millis() + networkDisruption.expectedTimeToHeal().millis()));
    logger.info("Verify no master block with {} set to {}", NoMasterBlockService.NO_MASTER_BLOCK_SETTING.getKey(), "all");
    client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put(NoMasterBlockService.NO_MASTER_BLOCK_SETTING.getKey(), "all")).get();
    networkDisruption.startDisrupting();
    // The unlucky node must report *no* master node, since it can't connect to master and in fact it should
    // continuously ping until network failures have been resolved. However
    // It may a take a bit before the node detects it has been cut off from the elected master
    logger.info("waiting for isolated node [{}] to have no master", isolatedNode);
    assertNoMaster(isolatedNode, NoMasterBlockService.NO_MASTER_BLOCK_ALL, TimeValue.timeValueSeconds(30));
    // make sure we have stable cluster & cross partition recoveries are canceled by the removal of the missing node
    // the unresponsive partition causes recoveries to only time out after 15m (default) and these will cause
    // the test to fail due to unfreed resources
    ensureStableCluster(2, nonIsolatedNode);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) TwoPartitions(org.elasticsearch.test.disruption.NetworkDisruption.TwoPartitions) NetworkDisruption(org.elasticsearch.test.disruption.NetworkDisruption) TimeValue(io.crate.common.unit.TimeValue) Test(org.junit.Test)

Example 38 with TimeValue

use of io.crate.common.unit.TimeValue in project crate by crate.

the class GatewayServiceTests method testDefaultRecoverAfterTime.

public void testDefaultRecoverAfterTime() {
    // check that the default is not set
    GatewayService service = createService(Settings.builder());
    assertNull(service.recoverAfterTime());
    // ensure default is set when setting expected_data_nodes
    service = createService(Settings.builder().put("gateway.expected_data_nodes", 1));
    assertThat(service.recoverAfterTime(), Matchers.equalTo(GatewayService.DEFAULT_RECOVER_AFTER_TIME_IF_EXPECTED_NODES_IS_SET));
    // ensure settings override default
    final TimeValue timeValue = TimeValue.timeValueHours(3);
    // ensure default is set when setting expected_nodes
    service = createService(Settings.builder().put("gateway.recover_after_time", timeValue.toString()));
    assertThat(service.recoverAfterTime().millis(), Matchers.equalTo(timeValue.millis()));
}
Also used : TimeValue(io.crate.common.unit.TimeValue)

Example 39 with TimeValue

use of io.crate.common.unit.TimeValue in project crate by crate.

the class TransportSchemaUpdateAction method updateTemplate.

private CompletableFuture<AcknowledgedResponse> updateTemplate(ImmutableOpenMap<String, IndexTemplateMetadata> templates, String indexName, String mappingSource, TimeValue timeout) {
    CompletableFuture<AcknowledgedResponse> future = new CompletableFuture<>();
    String templateName = PartitionName.templateName(indexName);
    Map<String, Object> newMapping;
    try {
        XContentParser parser = JsonXContent.JSON_XCONTENT.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, mappingSource);
        newMapping = parser.map();
        if (newMappingAlreadyApplied(templates.get(templateName), newMapping)) {
            return CompletableFuture.completedFuture(new AcknowledgedResponse(true));
        }
    } catch (Exception e) {
        return CompletableFuture.failedFuture(e);
    }
    clusterService.submitStateUpdateTask("update-template-mapping", new ClusterStateUpdateTask(Priority.HIGH) {

        @Override
        public ClusterState execute(ClusterState currentState) throws Exception {
            return updateTemplate(xContentRegistry, currentState, templateName, newMapping);
        }

        @Override
        public TimeValue timeout() {
            return timeout;
        }

        @Override
        public void onFailure(String source, Exception e) {
            future.completeExceptionally(e);
        }

        @Override
        public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
            future.complete(new AcknowledgedResponse(true));
        }
    });
    return future;
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) CompletableFuture(java.util.concurrent.CompletableFuture) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) ClusterStateUpdateTask(org.elasticsearch.cluster.ClusterStateUpdateTask) XContentParser(org.elasticsearch.common.xcontent.XContentParser) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) IOException(java.io.IOException) TimeValue(io.crate.common.unit.TimeValue)

Example 40 with TimeValue

use of io.crate.common.unit.TimeValue in project crate by crate.

the class SchemaUpdateClient method blockingUpdateOnMaster.

public void blockingUpdateOnMaster(Index index, Mapping mappingUpdate) {
    TimeValue timeout = this.dynamicMappingUpdateTimeout;
    var response = FutureUtils.get(schemaUpdateAction.execute(new SchemaUpdateRequest(index, mappingUpdate.toString())));
    if (!response.isAcknowledged()) {
        throw new ElasticsearchTimeoutException("Failed to acknowledge mapping update within [" + timeout + "]");
    }
}
Also used : ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) TimeValue(io.crate.common.unit.TimeValue)

Aggregations

TimeValue (io.crate.common.unit.TimeValue)75 Test (org.junit.Test)23 ClusterState (org.elasticsearch.cluster.ClusterState)20 IOException (java.io.IOException)17 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)12 ActionListener (org.elasticsearch.action.ActionListener)12 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)11 ArrayList (java.util.ArrayList)10 ThreadPool (org.elasticsearch.threadpool.ThreadPool)10 ElasticsearchException (org.elasticsearch.ElasticsearchException)9 Settings (org.elasticsearch.common.settings.Settings)9 Logger (org.apache.logging.log4j.Logger)8 ClusterStateUpdateTask (org.elasticsearch.cluster.ClusterStateUpdateTask)8 ClusterService (org.elasticsearch.cluster.service.ClusterService)8 List (java.util.List)7 LogManager (org.apache.logging.log4j.LogManager)7 Version (org.elasticsearch.Version)7 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)6 ClusterStateObserver (org.elasticsearch.cluster.ClusterStateObserver)6 StreamInput (org.elasticsearch.common.io.stream.StreamInput)6