Search in sources :

Example 91 with Releasable

use of org.opensearch.common.lease.Releasable in project OpenSearch by opensearch-project.

the class TransportReplicationAction method handlePrimaryRequest.

protected void handlePrimaryRequest(final ConcreteShardRequest<Request> request, final TransportChannel channel, final Task task) {
    Releasable releasable = checkPrimaryLimits(request.getRequest(), request.sentFromLocalReroute(), request.localRerouteInitiatedByNodeClient());
    ActionListener<Response> listener = ActionListener.runBefore(new ChannelActionListener<>(channel, transportPrimaryAction, request), releasable::close);
    try {
        new AsyncPrimaryAction(request, listener, (ReplicationTask) task).run();
    } catch (RuntimeException e) {
        listener.onFailure(e);
    }
}
Also used : ActionResponse(org.opensearch.action.ActionResponse) Releasable(org.opensearch.common.lease.Releasable)

Example 92 with Releasable

use of org.opensearch.common.lease.Releasable in project OpenSearch by opensearch-project.

the class TransportReplicationAction method handleOperationRequest.

private void handleOperationRequest(final Request request, final TransportChannel channel, Task task) {
    Releasable releasable = checkOperationLimits(request);
    ActionListener<Response> listener = ActionListener.runBefore(new ChannelActionListener<>(channel, actionName, request), releasable::close);
    runReroutePhase(task, request, listener, false);
}
Also used : ActionResponse(org.opensearch.action.ActionResponse) Releasable(org.opensearch.common.lease.Releasable)

Example 93 with Releasable

use of org.opensearch.common.lease.Releasable in project OpenSearch by opensearch-project.

the class TransportReplicationAction method handleReplicaRequest.

protected void handleReplicaRequest(final ConcreteReplicaRequest<ReplicaRequest> replicaRequest, final TransportChannel channel, final Task task) {
    Releasable releasable = checkReplicaLimits(replicaRequest.getRequest());
    ActionListener<ReplicaResponse> listener = ActionListener.runBefore(new ChannelActionListener<>(channel, transportReplicaAction, replicaRequest), releasable::close);
    try {
        new AsyncReplicaAction(replicaRequest, listener, (ReplicationTask) task).run();
    } catch (RuntimeException e) {
        listener.onFailure(e);
    }
}
Also used : Releasable(org.opensearch.common.lease.Releasable)

Example 94 with Releasable

use of org.opensearch.common.lease.Releasable in project OpenSearch by opensearch-project.

the class TransportAction method execute.

/**
 * Execute the transport action on the local node, returning the {@link Task} used to track its execution and accepting a
 * {@link TaskListener} which listens for the completion of the action.
 */
public final Task execute(Request request, TaskListener<Response> listener) {
    final Releasable unregisterChildNode = registerChildNode(request.getParentTask());
    final Task task;
    try {
        task = taskManager.register("transport", actionName, request);
    } catch (TaskCancelledException e) {
        unregisterChildNode.close();
        throw e;
    }
    execute(task, request, new ActionListener<Response>() {

        @Override
        public void onResponse(Response response) {
            try {
                Releasables.close(unregisterChildNode, () -> taskManager.unregister(task));
            } finally {
                listener.onResponse(task, response);
            }
        }

        @Override
        public void onFailure(Exception e) {
            try {
                Releasables.close(unregisterChildNode, () -> taskManager.unregister(task));
            } finally {
                listener.onFailure(task, e);
            }
        }
    });
    return task;
}
Also used : ActionResponse(org.opensearch.action.ActionResponse) Task(org.opensearch.tasks.Task) Releasable(org.opensearch.common.lease.Releasable) TaskCancelledException(org.opensearch.tasks.TaskCancelledException) ActionRequestValidationException(org.opensearch.action.ActionRequestValidationException) TaskCancelledException(org.opensearch.tasks.TaskCancelledException)

Example 95 with Releasable

use of org.opensearch.common.lease.Releasable in project OpenSearch by opensearch-project.

the class TcpReadWriteHandler method consumeReads.

@Override
public int consumeReads(InboundChannelBuffer channelBuffer) throws IOException {
    Page[] pages = channelBuffer.sliceAndRetainPagesTo(channelBuffer.getIndex());
    BytesReference[] references = new BytesReference[pages.length];
    for (int i = 0; i < pages.length; ++i) {
        references[i] = BytesReference.fromByteBuffer(pages[i].byteBuffer());
    }
    Releasable releasable = () -> IOUtils.closeWhileHandlingException(pages);
    try (ReleasableBytesReference reference = new ReleasableBytesReference(CompositeBytesReference.of(references), releasable)) {
        pipeline.handleBytes(channel, reference);
        return reference.length();
    }
}
Also used : BytesReference(org.opensearch.common.bytes.BytesReference) CompositeBytesReference(org.opensearch.common.bytes.CompositeBytesReference) ReleasableBytesReference(org.opensearch.common.bytes.ReleasableBytesReference) ReleasableBytesReference(org.opensearch.common.bytes.ReleasableBytesReference) Page(org.opensearch.nio.Page) Releasable(org.opensearch.common.lease.Releasable)

Aggregations

Releasable (org.opensearch.common.lease.Releasable)161 ShardId (org.opensearch.index.shard.ShardId)50 IOException (java.io.IOException)45 CountDownLatch (java.util.concurrent.CountDownLatch)36 Settings (org.opensearch.common.settings.Settings)35 IndexingPressurePerShardStats (org.opensearch.index.stats.IndexingPressurePerShardStats)32 ExecutionException (java.util.concurrent.ExecutionException)30 ArrayList (java.util.ArrayList)28 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)28 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)27 OpenSearchException (org.opensearch.OpenSearchException)25 ThreadPool (org.opensearch.threadpool.ThreadPool)25 PlainActionFuture (org.opensearch.action.support.PlainActionFuture)24 ActionListener (org.opensearch.action.ActionListener)23 IndexRequest (org.opensearch.action.index.IndexRequest)22 ShardRouting (org.opensearch.cluster.routing.ShardRouting)22 IndexingPressureStats (org.opensearch.index.stats.IndexingPressureStats)22 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)21 List (java.util.List)20 Translog (org.opensearch.index.translog.Translog)19