Search in sources :

Example 21 with TimeValue

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

the class ScalingExecutorBuilder method build.

@Override
ThreadPool.ExecutorHolder build(final ScalingExecutorSettings settings) {
    TimeValue keepAlive = settings.keepAlive;
    int core = settings.core;
    int max = settings.max;
    final ThreadPool.Info info = new ThreadPool.Info(name(), ThreadPool.ThreadPoolType.SCALING, core, max, keepAlive, null);
    final ThreadFactory threadFactory = EsExecutors.daemonThreadFactory(EsExecutors.threadName(settings.nodeName, name()));
    final ExecutorService executor = EsExecutors.newScaling(settings.nodeName + "/" + name(), core, max, keepAlive.millis(), TimeUnit.MILLISECONDS, threadFactory);
    return new ThreadPool.ExecutorHolder(executor, info);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) TimeValue(io.crate.common.unit.TimeValue)

Example 22 with TimeValue

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

the class ScalingExecutorBuilder method getSettings.

@Override
ScalingExecutorSettings getSettings(Settings settings) {
    final String nodeName = Node.NODE_NAME_SETTING.get(settings);
    final int coreThreads = coreSetting.get(settings);
    final int maxThreads = maxSetting.get(settings);
    final TimeValue keepAlive = keepAliveSetting.get(settings);
    return new ScalingExecutorSettings(nodeName, coreThreads, maxThreads, keepAlive);
}
Also used : TimeValue(io.crate.common.unit.TimeValue)

Example 23 with TimeValue

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

the class SnapshotInfo method toXContent.

@Override
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException {
    // write snapshot info to repository snapshot blob format
    if (CONTEXT_MODE_SNAPSHOT.equals(params.param(CONTEXT_MODE_PARAM))) {
        return toXContentInternal(builder, params);
    }
    final boolean verbose = params.paramAsBoolean("verbose", GetSnapshotsRequest.DEFAULT_VERBOSE_MODE);
    // write snapshot info for the API and any other situations
    builder.startObject();
    builder.field(SNAPSHOT, snapshotId.getName());
    builder.field(UUID, snapshotId.getUUID());
    if (version != null) {
        builder.field(VERSION_ID, version.internalId);
        builder.field(VERSION, version.toString());
    }
    builder.startArray(INDICES);
    for (String index : indices) {
        builder.value(index);
    }
    builder.endArray();
    if (includeGlobalState != null) {
        builder.field(INCLUDE_GLOBAL_STATE, includeGlobalState);
    }
    if (verbose || state != null) {
        builder.field(STATE, state);
    }
    if (reason != null) {
        builder.field(REASON, reason);
    }
    if (verbose || startTime != 0) {
        builder.field(START_TIME, DATE_TIME_FORMATTER.format(Instant.ofEpochMilli(startTime).atZone(ZoneOffset.UTC)));
        builder.field(START_TIME_IN_MILLIS, startTime);
    }
    if (verbose || endTime != 0) {
        builder.field(END_TIME, DATE_TIME_FORMATTER.format(Instant.ofEpochMilli(endTime).atZone(ZoneOffset.UTC)));
        builder.field(END_TIME_IN_MILLIS, endTime);
        builder.humanReadableField(DURATION_IN_MILLIS, DURATION, new TimeValue(endTime - startTime));
    }
    if (verbose || !shardFailures.isEmpty()) {
        builder.startArray(FAILURES);
        for (SnapshotShardFailure shardFailure : shardFailures) {
            shardFailure.toXContent(builder, params);
        }
        builder.endArray();
    }
    if (verbose || totalShards != 0) {
        builder.startObject(SHARDS);
        builder.field(TOTAL, totalShards);
        builder.field(FAILED, failedShards());
        builder.field(SUCCESSFUL, successfulShards);
        builder.endObject();
    }
    builder.endObject();
    return builder;
}
Also used : TimeValue(io.crate.common.unit.TimeValue)

Example 24 with TimeValue

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

the class IndexSettingsTests method testGCDeletesSetting.

@Test
public void testGCDeletesSetting() {
    TimeValue gcDeleteSetting = new TimeValue(Math.abs(randomInt()), TimeUnit.MILLISECONDS);
    IndexMetadata metaData = newIndexMeta("index", Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexSettings.INDEX_GC_DELETES_SETTING.getKey(), gcDeleteSetting.getStringRep()).build());
    IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
    assertThat(TimeValue.parseTimeValue(gcDeleteSetting.getStringRep(), new TimeValue(1, TimeUnit.DAYS), IndexSettings.INDEX_GC_DELETES_SETTING.getKey()).getMillis(), is(settings.getGcDeletesInMillis()));
    TimeValue newGCDeleteSetting = new TimeValue(Math.abs(randomInt()), TimeUnit.MILLISECONDS);
    settings.updateIndexMetadata(newIndexMeta("index", Settings.builder().put(IndexSettings.INDEX_GC_DELETES_SETTING.getKey(), newGCDeleteSetting.getStringRep()).build()));
    assertThat(TimeValue.parseTimeValue(newGCDeleteSetting.getStringRep(), new TimeValue(1, TimeUnit.DAYS), IndexSettings.INDEX_GC_DELETES_SETTING.getKey()).getMillis(), is(settings.getGcDeletesInMillis()));
    settings.updateIndexMetadata(newIndexMeta("index", Settings.builder().put(IndexSettings.INDEX_GC_DELETES_SETTING.getKey(), (randomBoolean() ? -1 : new TimeValue(-1, TimeUnit.MILLISECONDS)).toString()).build()));
    assertThat(settings.getGcDeletesInMillis(), is(-1L));
}
Also used : IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) TimeValue(io.crate.common.unit.TimeValue) Test(org.junit.Test)

Example 25 with TimeValue

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

the class IndexSettingsTests method testRefreshInterval.

@Test
public void testRefreshInterval() {
    String refreshInterval = getRandomTimeString();
    IndexMetadata metaData = newIndexMeta("index", Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), refreshInterval).build());
    IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
    assertThat(TimeValue.parseTimeValue(refreshInterval, new TimeValue(1, TimeUnit.DAYS), IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey()), is(settings.getRefreshInterval()));
    String newRefreshInterval = getRandomTimeString();
    settings.updateIndexMetadata(newIndexMeta("index", Settings.builder().put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), newRefreshInterval).build()));
    assertThat(TimeValue.parseTimeValue(newRefreshInterval, new TimeValue(1, TimeUnit.DAYS), IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey()), is(settings.getRefreshInterval()));
}
Also used : StringContains.containsString(org.hamcrest.core.StringContains.containsString) HasToString.hasToString(org.hamcrest.object.HasToString.hasToString) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) TimeValue(io.crate.common.unit.TimeValue) Test(org.junit.Test)

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