Search in sources :

Example 1 with IndexShardRelocatedException

use of org.opensearch.index.shard.IndexShardRelocatedException in project OpenSearch by opensearch-project.

the class RecoverySourceHandler method runUnderPrimaryPermit.

static void runUnderPrimaryPermit(CancellableThreads.Interruptible runnable, String reason, IndexShard primary, CancellableThreads cancellableThreads, Logger logger) {
    cancellableThreads.execute(() -> {
        CompletableFuture<Releasable> permit = new CompletableFuture<>();
        final ActionListener<Releasable> onAcquired = new ActionListener<Releasable>() {

            @Override
            public void onResponse(Releasable releasable) {
                if (permit.complete(releasable) == false) {
                    releasable.close();
                }
            }

            @Override
            public void onFailure(Exception e) {
                permit.completeExceptionally(e);
            }
        };
        primary.acquirePrimaryOperationPermit(onAcquired, ThreadPool.Names.SAME, reason);
        try (Releasable ignored = FutureUtils.get(permit)) {
            // races, as IndexShard will switch its authority only when it holds all operation permits, see IndexShard.relocated()
            if (primary.isRelocatedPrimary()) {
                throw new IndexShardRelocatedException(primary.shardId());
            }
            runnable.run();
        } finally {
            // just in case we got an exception (likely interrupted) while waiting for the get
            permit.whenComplete((r, e) -> {
                if (r != null) {
                    r.close();
                }
                if (e != null) {
                    logger.trace("suppressing exception on completion (it was already bubbled up or the operation was aborted)", e);
                }
            });
        }
    });
}
Also used : IndexShardRelocatedException(org.opensearch.index.shard.IndexShardRelocatedException) CompletableFuture(java.util.concurrent.CompletableFuture) ActionListener(org.opensearch.action.ActionListener) ThreadedActionListener(org.opensearch.action.support.ThreadedActionListener) Releasable(org.opensearch.common.lease.Releasable) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) RecoveryEngineException(org.opensearch.index.engine.RecoveryEngineException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) RemoteTransportException(org.opensearch.transport.RemoteTransportException) IndexShardClosedException(org.opensearch.index.shard.IndexShardClosedException) IOException(java.io.IOException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) IndexShardRelocatedException(org.opensearch.index.shard.IndexShardRelocatedException) RetentionLeaseNotFoundException(org.opensearch.index.seqno.RetentionLeaseNotFoundException)

Aggregations

IOException (java.io.IOException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)1 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)1 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)1 ActionListener (org.opensearch.action.ActionListener)1 ThreadedActionListener (org.opensearch.action.support.ThreadedActionListener)1 Releasable (org.opensearch.common.lease.Releasable)1 RecoveryEngineException (org.opensearch.index.engine.RecoveryEngineException)1 RetentionLeaseNotFoundException (org.opensearch.index.seqno.RetentionLeaseNotFoundException)1 IndexShardClosedException (org.opensearch.index.shard.IndexShardClosedException)1 IndexShardRelocatedException (org.opensearch.index.shard.IndexShardRelocatedException)1 RemoteTransportException (org.opensearch.transport.RemoteTransportException)1