Java Code Examples for org.elasticsearch.common.unit.TimeValue#millis()

The following examples show how to use org.elasticsearch.common.unit.TimeValue#millis() . 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: DiscoverySettings.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void onRefreshSettings(Settings settings) {
    TimeValue newPublishTimeout = settings.getAsTime(PUBLISH_TIMEOUT,
            DiscoverySettings.this.settings.getAsTime(PUBLISH_TIMEOUT, DEFAULT_PUBLISH_TIMEOUT));
    if (newPublishTimeout.millis() != publishTimeout.millis()) {
        logger.info("updating [{}] from [{}] to [{}]", PUBLISH_TIMEOUT, publishTimeout, newPublishTimeout);
        publishTimeout = newPublishTimeout;
    }
    String newNoMasterBlockValue = settings.get(NO_MASTER_BLOCK);
    if (newNoMasterBlockValue != null) {
        ClusterBlock newNoMasterBlock = parseNoMasterBlock(newNoMasterBlockValue);
        if (newNoMasterBlock != noMasterBlock) {
            noMasterBlock = newNoMasterBlock;
        }
    }
    Boolean newPublishDiff = settings.getAsBoolean(PUBLISH_DIFF_ENABLE,
            DiscoverySettings.this.settings.getAsBoolean(PUBLISH_DIFF_ENABLE, DEFAULT_PUBLISH_DIFF_ENABLE));
    if (newPublishDiff != publishDiff) {
        logger.info("updating [{}] from [{}] to [{}]", PUBLISH_DIFF_ENABLE, publishDiff, newPublishDiff);
        publishDiff = newPublishDiff;
    }
}
 
Example 2
Source File: DefaultSearchContext.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public DefaultSearchContext(long id, ShardSearchRequest request, SearchShardTarget shardTarget,
                            Engine.Searcher engineSearcher, IndexService indexService, IndexShard indexShard,
                            ScriptService scriptService, PageCacheRecycler pageCacheRecycler,
                            BigArrays bigArrays, Counter timeEstimateCounter, ParseFieldMatcher parseFieldMatcher,
                            TimeValue timeout
) {
    super(parseFieldMatcher, request);
    this.id = id;
    this.request = request;
    this.searchType = request.searchType();
    this.shardTarget = shardTarget;
    this.engineSearcher = engineSearcher;
    this.scriptService = scriptService;
    this.pageCacheRecycler = pageCacheRecycler;
    // SearchContexts use a BigArrays that can circuit break
    this.bigArrays = bigArrays.withCircuitBreaking();
    this.dfsResult = new DfsSearchResult(id, shardTarget);
    this.queryResult = new QuerySearchResult(id, shardTarget);
    this.fetchResult = new FetchSearchResult(id, shardTarget);
    this.indexShard = indexShard;
    this.indexService = indexService;
    this.searcher = new ContextIndexSearcher(engineSearcher, indexService.cache().query(), indexShard.getQueryCachingPolicy());
    this.timeEstimateCounter = timeEstimateCounter;
    this.timeoutInMillis = timeout.millis();
}
 
Example 3
Source File: DynamicRanker.java    From elasticsearch-dynarank with Apache License 2.0 6 votes vote down vote up
@Inject
public DynamicRanker(final Settings settings, final Client client, final ClusterService clusterService,
        final ScriptService scriptService, final ThreadPool threadPool, final ActionFilters filters,
        final NamedWriteableRegistry namedWriteableRegistry) {
    this.client = client;
    this.clusterService = clusterService;
    this.scriptService = scriptService;
    this.threadPool = threadPool;
    this.namedWriteableRegistry = namedWriteableRegistry;

    logger.info("Initializing DynamicRanker");

    final TimeValue expire = SETTING_DYNARANK_CACHE_EXPIRE.get(settings);
    cleanInterval = SETTING_DYNARANK_CACHE_CLEAN_INTERVAL.get(settings);

    final CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().concurrencyLevel(16);
    if (expire.millis() >= 0) {
        builder.expireAfterAccess(expire.millis(), TimeUnit.MILLISECONDS);
    }
    scriptInfoCache = builder.build();
}
 
Example 4
Source File: OsService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public OsService(Settings settings, OsProbe probe) {
    super(settings);
    this.probe = probe;

    TimeValue refreshInterval = settings.getAsTime("monitor.os.refresh_interval", TimeValue.timeValueSeconds(1));

    this.info = probe.osInfo();
    this.info.refreshInterval = refreshInterval.millis();
    this.info.allocatedProcessors = EsExecutors.boundedNumberOfProcessors(settings);

    osStatsCache = new OsStatsCache(refreshInterval, probe.osStats());
    logger.debug("Using probe [{}] with refresh_interval [{}]", probe, refreshInterval);
}
 
Example 5
Source File: ProcessService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public ProcessService(Settings settings, ProcessProbe probe) {
    super(settings);
    this.probe = probe;

    final TimeValue refreshInterval = settings.getAsTime("monitor.process.refresh_interval", TimeValue.timeValueSeconds(1));
    processStatsCache = new ProcessStatsCache(refreshInterval, probe.processStats());
    this.info = probe.processInfo();
    this.info.refreshInterval = refreshInterval.millis();
    logger.debug("Using probe [{}] with refresh_interval [{}]", probe, refreshInterval);
}
 
Example 6
Source File: PublishClusterStateAction.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
private void publish(final ClusterChangedEvent clusterChangedEvent, final Set<DiscoveryNode> nodesToPublishTo,
                     final BlockingClusterStatePublishResponseHandler publishResponseHandler) {

    Map<Version, BytesReference> serializedStates = Maps.newHashMap();
    Map<Version, BytesReference> serializedDiffs = Maps.newHashMap();

    final ClusterState clusterState = clusterChangedEvent.state();
    final ClusterState previousState = clusterChangedEvent.previousState();
    final AtomicBoolean timedOutWaitingForNodes = new AtomicBoolean(false);
    final TimeValue publishTimeout = discoverySettings.getPublishTimeout();
    final boolean sendFullVersion = !discoverySettings.getPublishDiff() || previousState == null;
    Diff<ClusterState> diff = null;

    for (final DiscoveryNode node : nodesToPublishTo) {

        // try and serialize the cluster state once (or per version), so we don't serialize it
        // per node when we send it over the wire, compress it while we are at it...
        // we don't send full version if node didn't exist in the previous version of cluster state
        if (sendFullVersion || !previousState.nodes().nodeExists(node.id())) {
            sendFullClusterState(clusterState, serializedStates, node, timedOutWaitingForNodes, publishTimeout, publishResponseHandler);
        } else {
            if (diff == null) {
                diff = clusterState.diff(previousState);
            }
            sendClusterStateDiff(clusterState, diff, serializedDiffs, node, timedOutWaitingForNodes, publishTimeout, publishResponseHandler);
        }
    }

    if (publishTimeout.millis() > 0) {
        // only wait if the publish timeout is configured...
        try {
            timedOutWaitingForNodes.set(!publishResponseHandler.awaitAllNodes(publishTimeout));
            if (timedOutWaitingForNodes.get()) {
                DiscoveryNode[] pendingNodes = publishResponseHandler.pendingNodes();
                // everyone may have just responded
                if (pendingNodes.length > 0) {
                    logger.warn("timed out waiting for all nodes to process published state [{}] (timeout [{}], pending nodes: {})", clusterState.version(), publishTimeout, pendingNodes);
                }
            }
        } catch (InterruptedException e) {
            // ignore & restore interrupt
            Thread.currentThread().interrupt();
        }
    }
}
 
Example 7
Source File: DiscoveryService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public boolean waitForInitialState(TimeValue timeValue) throws InterruptedException {
    if (timeValue.millis() > 0) {
        latch.await(timeValue.millis(), TimeUnit.MILLISECONDS);
    }
    return initialStateReceived;
}
 
Example 8
Source File: ClusterStateObserver.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Wait for the next cluster state which satisfies changePredicate
 *
 * @param listener        callback listener
 * @param changePredicate predicate to check whether cluster state changes are relevant and the callback should be called
 * @param timeOutValue    a timeout for waiting. If null the global observer timeout will be used.
 */
public void waitForNextChange(Listener listener, ChangePredicate changePredicate, @Nullable TimeValue timeOutValue) {

    if (observingContext.get() != null) {
        throw new ElasticsearchException("already waiting for a cluster state change");
    }

    Long timeoutTimeLeftMS;
    if (timeOutValue == null) {
        timeOutValue = this.timeOutValue;
        if (timeOutValue != null) {
            long timeSinceStartMS = TimeValue.nsecToMSec(System.nanoTime() - startTimeNS);
            timeoutTimeLeftMS = timeOutValue.millis() - timeSinceStartMS;
            if (timeoutTimeLeftMS <= 0l) {
                // things have timeout while we were busy -> notify
                logger.trace("observer timed out. notifying listener. timeout setting [{}], time since start [{}]", timeOutValue, new TimeValue(timeSinceStartMS));
                // update to latest, in case people want to retry
                timedOut = true;
                lastObservedState.set(new ObservedState(clusterService.state()));
                listener.onTimeout(timeOutValue);
                return;
            }
        } else {
            timeoutTimeLeftMS = null;
        }
    } else {
        this.startTimeNS = System.nanoTime();
        this.timeOutValue = timeOutValue;
        timeoutTimeLeftMS = timeOutValue.millis();
        timedOut = false;
    }

    // sample a new state
    ObservedState newState = new ObservedState(clusterService.state());
    ObservedState lastState = lastObservedState.get();
    if (changePredicate.apply(lastState.clusterState, lastState.status, newState.clusterState, newState.status)) {
        // good enough, let's go.
        logger.trace("observer: sampled state accepted by predicate ({})", newState);
        lastObservedState.set(newState);
        listener.onNewClusterState(newState.clusterState);
    } else {
        logger.trace("observer: sampled state rejected by predicate ({}). adding listener to ClusterService", newState);
        ObservingContext context = new ObservingContext(listener, changePredicate);
        if (!observingContext.compareAndSet(null, context)) {
            throw new ElasticsearchException("already waiting for a cluster state change");
        }
        clusterService.add(timeoutTimeLeftMS == null ? null : new TimeValue(timeoutTimeLeftMS), clusterStateListener);
    }
}
 
Example 9
Source File: TimeZoneRounding.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public Builder(TimeValue interval) {
    this.unit = null;
    if (interval.millis() < 1)
        throw new IllegalArgumentException("Zero or negative time interval not supported");
    this.interval = interval.millis();
}
 
Example 10
Source File: BackoffPolicy.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
private static TimeValue checkDelay(TimeValue delay) {
    if (delay.millis() > Integer.MAX_VALUE) {
        throw new IllegalArgumentException("delay must be <= " + Integer.MAX_VALUE + " ms");
    }
    return delay;
}