Search in sources :

Example 6 with CancellableTask

use of org.opensearch.tasks.CancellableTask in project OpenSearch by opensearch-project.

the class RequestHandlerRegistry method processMessageReceived.

public void processMessageReceived(Request request, TransportChannel channel) throws Exception {
    final Task task = taskManager.register(channel.getChannelType(), action, request);
    Releasable unregisterTask = () -> taskManager.unregister(task);
    try {
        if (channel instanceof TcpTransportChannel && task instanceof CancellableTask) {
            if (request instanceof ShardSearchRequest) {
                // on receiving request, update the inbound network time to reflect time spent in transit over the network
                ((ShardSearchRequest) request).setInboundNetworkTime(Math.max(0, System.currentTimeMillis() - ((ShardSearchRequest) request).getInboundNetworkTime()));
            }
            final TcpChannel tcpChannel = ((TcpTransportChannel) channel).getChannel();
            final Releasable stopTracking = taskManager.startTrackingCancellableChannelTask(tcpChannel, (CancellableTask) task);
            unregisterTask = Releasables.wrap(unregisterTask, stopTracking);
        }
        final TaskTransportChannel taskTransportChannel = new TaskTransportChannel(channel, unregisterTask);
        handler.messageReceived(request, taskTransportChannel, task);
        unregisterTask = null;
    } finally {
        Releasables.close(unregisterTask);
    }
}
Also used : Task(org.opensearch.tasks.Task) CancellableTask(org.opensearch.tasks.CancellableTask) CancellableTask(org.opensearch.tasks.CancellableTask) ShardSearchRequest(org.opensearch.search.internal.ShardSearchRequest) Releasable(org.opensearch.common.lease.Releasable)

Aggregations

CancellableTask (org.opensearch.tasks.CancellableTask)6 TaskId (org.opensearch.tasks.TaskId)3 TaskInfo (org.opensearch.tasks.TaskInfo)3 TaskManager (org.opensearch.tasks.TaskManager)3 TransportService (org.opensearch.transport.TransportService)3 ArrayList (java.util.ArrayList)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 SetOnce (org.apache.lucene.util.SetOnce)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 ActionListener (org.opensearch.action.ActionListener)2 NodeClient (org.opensearch.client.node.NodeClient)2 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)2 Task (org.opensearch.tasks.Task)2 ThreadPool (org.opensearch.threadpool.ThreadPool)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1