Search in sources :

Example 11 with StopWatch

use of org.elasticsearch.common.StopWatch in project crate by crate.

the class RecoverySourceHandler method prepareTargetForTranslog.

void prepareTargetForTranslog(int totalTranslogOps, ActionListener<TimeValue> listener) {
    StopWatch stopWatch = new StopWatch().start();
    final ActionListener<Void> wrappedListener = ActionListener.wrap(nullVal -> {
        stopWatch.stop();
        final TimeValue tookTime = stopWatch.totalTime();
        logger.trace("recovery [phase1]: remote engine start took [{}]", tookTime);
        listener.onResponse(tookTime);
    }, e -> listener.onFailure(new RecoveryEngineException(shard.shardId(), 1, "prepare target for translog failed", e)));
    // Send a request preparing the new shard's translog to receive operations. This ensures the shard engine is started and disables
    // garbage collection (not the JVM's GC!) of tombstone deletes.
    logger.trace("recovery [phase1]: prepare remote engine for translog");
    cancellableThreads.checkForCancel();
    recoveryTarget.prepareForTranslogOperations(totalTranslogOps, wrappedListener);
}
Also used : RecoveryEngineException(org.elasticsearch.index.engine.RecoveryEngineException) TimeValue(io.crate.common.unit.TimeValue) StopWatch(org.elasticsearch.common.StopWatch)

Example 12 with StopWatch

use of org.elasticsearch.common.StopWatch in project elasticsearch-opennlp-plugin by spinscale.

the class SimpleNlpTest method loadFinders.

public void loadFinders() throws Exception {
    finders = new NameFinderME[names.length];
    StopWatch sw = new StopWatch("Loading models").start();
    for (int mi = 0; mi < names.length; mi++) {
        finders[mi] = new NameFinderME(new PooledTokenNameFinderModel(new FileInputStream(new File("src/test/resources/models", "en-ner-" + names[mi] + ".bin"))));
    }
    sw.stop();
}
Also used : NameFinderME(opennlp.tools.namefind.NameFinderME) File(java.io.File) FileInputStream(java.io.FileInputStream) StopWatch(org.elasticsearch.common.StopWatch) PooledTokenNameFinderModel(org.elasticsearch.service.opennlp.models.PooledTokenNameFinderModel)

Example 13 with StopWatch

use of org.elasticsearch.common.StopWatch in project elasticsearch by elastic.

the class RecoverySourceHandler method finalizeRecovery.

/*
     * finalizes the recovery process
     */
public void finalizeRecovery() {
    if (shard.state() == IndexShardState.CLOSED) {
        throw new IndexShardClosedException(request.shardId());
    }
    cancellableThreads.checkForCancel();
    StopWatch stopWatch = new StopWatch().start();
    logger.trace("finalizing recovery");
    cancellableThreads.execute(() -> {
        shard.markAllocationIdAsInSync(recoveryTarget.getTargetAllocationId());
        recoveryTarget.finalizeRecovery(shard.getGlobalCheckpoint());
    });
    if (request.isPrimaryRelocation()) {
        // state. This means that no new recovery can be completed based on information of a newer cluster state than the current one.
        try (Releasable ignored = delayNewRecoveries.apply("primary relocation hand-off in progress or completed for " + shardId)) {
            final long currentClusterStateVersion = currentClusterStateVersionSupplier.get();
            logger.trace("waiting on remote node to have cluster state with version [{}]", currentClusterStateVersion);
            cancellableThreads.execute(() -> recoveryTarget.ensureClusterStateVersion(currentClusterStateVersion));
            logger.trace("performing relocation hand-off");
            cancellableThreads.execute(() -> shard.relocated("to " + request.targetNode()));
        }
    /*
             * if the recovery process fails after setting the shard state to RELOCATED, both relocation source and
             * target are failed (see {@link IndexShard#updateRoutingEntry}).
             */
    }
    stopWatch.stop();
    logger.trace("finalizing recovery took [{}]", stopWatch.totalTime());
}
Also used : IndexShardClosedException(org.elasticsearch.index.shard.IndexShardClosedException) Releasable(org.elasticsearch.common.lease.Releasable) StopWatch(org.elasticsearch.common.StopWatch)

Example 14 with StopWatch

use of org.elasticsearch.common.StopWatch in project elasticsearch by elastic.

the class RecoverySourceHandler method prepareTargetForTranslog.

void prepareTargetForTranslog(final int totalTranslogOps, final long maxUnsafeAutoIdTimestamp) throws IOException {
    StopWatch stopWatch = new StopWatch().start();
    logger.trace("recovery [phase1]: prepare remote engine for translog");
    final long startEngineStart = stopWatch.totalTime().millis();
    // Send a request preparing the new shard's translog to receive operations. This ensures the shard engine is started and disables
    // garbage collection (not the JVM's GC!) of tombstone deletes.
    cancellableThreads.executeIO(() -> recoveryTarget.prepareForTranslogOperations(totalTranslogOps, maxUnsafeAutoIdTimestamp));
    stopWatch.stop();
    response.startTime = stopWatch.totalTime().millis() - startEngineStart;
    logger.trace("recovery [phase1]: remote engine start took [{}]", stopWatch.totalTime());
}
Also used : StopWatch(org.elasticsearch.common.StopWatch)

Example 15 with StopWatch

use of org.elasticsearch.common.StopWatch in project elasticsearch by elastic.

the class Node method close.

// During concurrent close() calls we want to make sure that all of them return after the node has completed it's shutdown cycle.
// If not, the hook that is added in Bootstrap#setup() will be useless: close() might not be executed, in case another (for example api) call
// to close() has already set some lifecycles to stopped. In this case the process will be terminated even if the first call to close() has not finished yet.
@Override
public synchronized void close() throws IOException {
    if (lifecycle.started()) {
        stop();
    }
    if (!lifecycle.moveToClosed()) {
        return;
    }
    Logger logger = Loggers.getLogger(Node.class, NODE_NAME_SETTING.get(settings));
    logger.info("closing ...");
    List<Closeable> toClose = new ArrayList<>();
    StopWatch stopWatch = new StopWatch("node_close");
    toClose.add(() -> stopWatch.start("tribe"));
    toClose.add(injector.getInstance(TribeService.class));
    toClose.add(() -> stopWatch.stop().start("node_service"));
    toClose.add(injector.getInstance(NodeService.class));
    toClose.add(() -> stopWatch.stop().start("http"));
    if (NetworkModule.HTTP_ENABLED.get(settings)) {
        toClose.add(injector.getInstance(HttpServerTransport.class));
    }
    toClose.add(() -> stopWatch.stop().start("snapshot_service"));
    toClose.add(injector.getInstance(SnapshotsService.class));
    toClose.add(injector.getInstance(SnapshotShardsService.class));
    toClose.add(() -> stopWatch.stop().start("client"));
    Releasables.close(injector.getInstance(Client.class));
    toClose.add(() -> stopWatch.stop().start("indices_cluster"));
    toClose.add(injector.getInstance(IndicesClusterStateService.class));
    toClose.add(() -> stopWatch.stop().start("indices"));
    toClose.add(injector.getInstance(IndicesService.class));
    // close filter/fielddata caches after indices
    toClose.add(injector.getInstance(IndicesStore.class));
    toClose.add(() -> stopWatch.stop().start("routing"));
    toClose.add(injector.getInstance(RoutingService.class));
    toClose.add(() -> stopWatch.stop().start("cluster"));
    toClose.add(injector.getInstance(ClusterService.class));
    toClose.add(() -> stopWatch.stop().start("node_connections_service"));
    toClose.add(injector.getInstance(NodeConnectionsService.class));
    toClose.add(() -> stopWatch.stop().start("discovery"));
    toClose.add(injector.getInstance(Discovery.class));
    toClose.add(() -> stopWatch.stop().start("monitor"));
    toClose.add(injector.getInstance(MonitorService.class));
    toClose.add(() -> stopWatch.stop().start("gateway"));
    toClose.add(injector.getInstance(GatewayService.class));
    toClose.add(() -> stopWatch.stop().start("search"));
    toClose.add(injector.getInstance(SearchService.class));
    toClose.add(() -> stopWatch.stop().start("transport"));
    toClose.add(injector.getInstance(TransportService.class));
    toClose.add(() -> stopWatch.stop().start("search_transport_service"));
    toClose.add(injector.getInstance(SearchTransportService.class));
    for (LifecycleComponent plugin : pluginLifecycleComponents) {
        toClose.add(() -> stopWatch.stop().start("plugin(" + plugin.getClass().getName() + ")"));
        toClose.add(plugin);
    }
    toClose.addAll(pluginsService.filterPlugins(Plugin.class));
    toClose.add(() -> stopWatch.stop().start("script"));
    toClose.add(injector.getInstance(ScriptService.class));
    toClose.add(() -> stopWatch.stop().start("thread_pool"));
    // TODO this should really use ThreadPool.terminate()
    toClose.add(() -> injector.getInstance(ThreadPool.class).shutdown());
    toClose.add(() -> {
        try {
            injector.getInstance(ThreadPool.class).awaitTermination(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
        // ignore
        }
    });
    toClose.add(() -> stopWatch.stop().start("thread_pool_force_shutdown"));
    toClose.add(() -> injector.getInstance(ThreadPool.class).shutdownNow());
    toClose.add(() -> stopWatch.stop());
    toClose.add(injector.getInstance(NodeEnvironment.class));
    toClose.add(injector.getInstance(BigArrays.class));
    if (logger.isTraceEnabled()) {
        logger.trace("Close times for each service:\n{}", stopWatch.prettyPrint());
    }
    IOUtils.close(toClose);
    logger.info("closed");
}
Also used : TribeService(org.elasticsearch.tribe.TribeService) SnapshotsService(org.elasticsearch.snapshots.SnapshotsService) SnapshotShardsService(org.elasticsearch.snapshots.SnapshotShardsService) NodeConnectionsService(org.elasticsearch.cluster.NodeConnectionsService) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) MonitorService(org.elasticsearch.monitor.MonitorService) Closeable(java.io.Closeable) IndicesStore(org.elasticsearch.indices.store.IndicesStore) ArrayList(java.util.ArrayList) ThreadPool(org.elasticsearch.threadpool.ThreadPool) Logger(org.apache.logging.log4j.Logger) DeprecationLogger(org.elasticsearch.common.logging.DeprecationLogger) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) ScriptService(org.elasticsearch.script.ScriptService) IndicesClusterStateService(org.elasticsearch.indices.cluster.IndicesClusterStateService) LifecycleComponent(org.elasticsearch.common.component.LifecycleComponent) SearchService(org.elasticsearch.search.SearchService) SearchTransportService(org.elasticsearch.action.search.SearchTransportService) Client(org.elasticsearch.client.Client) NodeClient(org.elasticsearch.client.node.NodeClient) RoutingService(org.elasticsearch.cluster.routing.RoutingService) Discovery(org.elasticsearch.discovery.Discovery) IndicesService(org.elasticsearch.indices.IndicesService) StopWatch(org.elasticsearch.common.StopWatch) GatewayService(org.elasticsearch.gateway.GatewayService) BigArrays(org.elasticsearch.common.util.BigArrays) ClusterService(org.elasticsearch.cluster.service.ClusterService) SearchTransportService(org.elasticsearch.action.search.SearchTransportService) TransportService(org.elasticsearch.transport.TransportService) ClusterPlugin(org.elasticsearch.plugins.ClusterPlugin) SearchPlugin(org.elasticsearch.plugins.SearchPlugin) RepositoryPlugin(org.elasticsearch.plugins.RepositoryPlugin) AnalysisPlugin(org.elasticsearch.plugins.AnalysisPlugin) IngestPlugin(org.elasticsearch.plugins.IngestPlugin) ScriptPlugin(org.elasticsearch.plugins.ScriptPlugin) NetworkPlugin(org.elasticsearch.plugins.NetworkPlugin) DiscoveryPlugin(org.elasticsearch.plugins.DiscoveryPlugin) MapperPlugin(org.elasticsearch.plugins.MapperPlugin) ActionPlugin(org.elasticsearch.plugins.ActionPlugin) Plugin(org.elasticsearch.plugins.Plugin)

Aggregations

StopWatch (org.elasticsearch.common.StopWatch)21 IndexShardClosedException (org.elasticsearch.index.shard.IndexShardClosedException)11 TimeValue (io.crate.common.unit.TimeValue)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Interruptable (org.elasticsearch.common.util.CancellableThreads.Interruptable)3 Closeable (java.io.Closeable)2 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)2 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)2 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)2 IndexInput (org.apache.lucene.store.IndexInput)2 RateLimiter (org.apache.lucene.store.RateLimiter)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 StepListener (org.elasticsearch.action.StepListener)2 Client (org.elasticsearch.client.Client)2 NodeClient (org.elasticsearch.client.node.NodeClient)2 NodeConnectionsService (org.elasticsearch.cluster.NodeConnectionsService)2 ClusterService (org.elasticsearch.cluster.service.ClusterService)2 BytesArray (org.elasticsearch.common.bytes.BytesArray)2