Search in sources :

Example 81 with Releasable

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

the class OpenSearchIndexLevelReplicationTestCase method executeResyncOnReplica.

private void executeResyncOnReplica(IndexShard replica, ResyncReplicationRequest request, long operationPrimaryTerm, long globalCheckpointOnPrimary, long maxSeqNoOfUpdatesOrDeletes) throws Exception {
    final Translog.Location location;
    final PlainActionFuture<Releasable> acquirePermitFuture = new PlainActionFuture<>();
    replica.acquireReplicaOperationPermit(operationPrimaryTerm, globalCheckpointOnPrimary, maxSeqNoOfUpdatesOrDeletes, acquirePermitFuture, ThreadPool.Names.SAME, request);
    try (Releasable ignored = acquirePermitFuture.actionGet()) {
        location = TransportResyncReplicationAction.performOnReplica(request, replica);
    }
    TransportWriteActionTestHelper.performPostWriteActions(replica, request, location, logger);
}
Also used : PlainActionFuture(org.opensearch.action.support.PlainActionFuture) Releasable(org.opensearch.common.lease.Releasable) Translog(org.opensearch.index.translog.Translog)

Example 82 with Releasable

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

the class OpenSearchIndexLevelReplicationTestCase method executeShardBulkOnReplica.

private void executeShardBulkOnReplica(BulkShardRequest request, IndexShard replica, long operationPrimaryTerm, long globalCheckpointOnPrimary, long maxSeqNoOfUpdatesOrDeletes) throws Exception {
    final PlainActionFuture<Releasable> permitAcquiredFuture = new PlainActionFuture<>();
    replica.acquireReplicaOperationPermit(operationPrimaryTerm, globalCheckpointOnPrimary, maxSeqNoOfUpdatesOrDeletes, permitAcquiredFuture, ThreadPool.Names.SAME, request);
    final Translog.Location location;
    try (Releasable ignored = permitAcquiredFuture.actionGet()) {
        location = TransportShardBulkAction.performOnReplica(request, replica);
    }
    TransportWriteActionTestHelper.performPostWriteActions(replica, request, location, logger);
}
Also used : PlainActionFuture(org.opensearch.action.support.PlainActionFuture) Releasable(org.opensearch.common.lease.Releasable) Translog(org.opensearch.index.translog.Translog)

Example 83 with Releasable

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

the class TransportBulkAction method doExecute.

@Override
protected void doExecute(Task task, BulkRequest bulkRequest, ActionListener<BulkResponse> listener) {
    final boolean isOnlySystem = isOnlySystem(bulkRequest, clusterService.state().metadata().getIndicesLookup(), systemIndices);
    final Releasable releasable = indexingPressureService.markCoordinatingOperationStarted(bulkRequest::ramBytesUsed, isOnlySystem);
    final ActionListener<BulkResponse> releasingListener = ActionListener.runBefore(listener, releasable::close);
    final String executorName = isOnlySystem ? Names.SYSTEM_WRITE : Names.WRITE;
    try {
        doInternalExecute(task, bulkRequest, executorName, releasingListener);
    } catch (Exception e) {
        releasingListener.onFailure(e);
    }
}
Also used : Releasable(org.opensearch.common.lease.Releasable) NodeClosedException(org.opensearch.node.NodeClosedException) OpenSearchParseException(org.opensearch.OpenSearchParseException) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) ResourceAlreadyExistsException(org.opensearch.ResourceAlreadyExistsException) RoutingMissingException(org.opensearch.action.RoutingMissingException) IndexClosedException(org.opensearch.indices.IndexClosedException) IndexNotFoundException(org.opensearch.index.IndexNotFoundException)

Example 84 with Releasable

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

the class ReopenWhileClosingIT method testReopenDuringClose.

public void testReopenDuringClose() throws Exception {
    List<String> dataOnlyNodes = internalCluster().startDataOnlyNodes(randomIntBetween(2, 3));
    final String indexName = "test";
    createIndexWithDocs(indexName, dataOnlyNodes);
    ensureYellowAndNoInitializingShards(indexName);
    final CountDownLatch block = new CountDownLatch(1);
    final Releasable releaseBlock = interceptVerifyShardBeforeCloseActions(indexName, block::countDown);
    ActionFuture<CloseIndexResponse> closeIndexResponse = client().admin().indices().prepareClose(indexName).execute();
    assertTrue("Waiting for index to have a closing blocked", block.await(60, TimeUnit.SECONDS));
    assertIndexIsBlocked(indexName);
    assertFalse(closeIndexResponse.isDone());
    assertAcked(client().admin().indices().prepareOpen(indexName));
    releaseBlock.close();
    assertFalse(closeIndexResponse.get().isAcknowledged());
    assertIndexIsOpened(indexName);
}
Also used : CloseIndexResponse(org.opensearch.action.admin.indices.close.CloseIndexResponse) Releasable(org.opensearch.common.lease.Releasable) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 85 with Releasable

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

the class ShardIndexingPressureIT method testWritesRejectedForSinglePrimaryShardDueToNodeLevelLimitBreach.

public void testWritesRejectedForSinglePrimaryShardDueToNodeLevelLimitBreach() throws Exception {
    final BulkRequest bulkRequest = new BulkRequest();
    int totalRequestSize = 0;
    for (int i = 0; i < 80; ++i) {
        IndexRequest request = new IndexRequest(INDEX_NAME).id(UUIDs.base64UUID()).source(Collections.singletonMap("key", randomAlphaOfLength(50)));
        totalRequestSize += request.ramBytesUsed();
        assertTrue(request.ramBytesUsed() > request.source().length());
        bulkRequest.add(request);
    }
    final long bulkShardRequestSize = totalRequestSize + (RamUsageEstimator.shallowSizeOfInstance(BulkItemRequest.class) * 80) + RamUsageEstimator.shallowSizeOfInstance(BulkShardRequest.class);
    restartCluster(Settings.builder().put(IndexingPressure.MAX_INDEXING_BYTES.getKey(), (long) (bulkShardRequestSize * 1.5) + "B").build());
    assertAcked(prepareCreate(INDEX_NAME, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1)));
    ensureGreen(INDEX_NAME);
    Tuple<String, String> primaryReplicaNodeNames = getPrimaryReplicaNodeNames(INDEX_NAME);
    String primaryName = primaryReplicaNodeNames.v1();
    String replicaName = primaryReplicaNodeNames.v2();
    String coordinatingOnlyNode = getCoordinatingOnlyNode();
    final ThreadPool replicaThreadPool = internalCluster().getInstance(ThreadPool.class, replicaName);
    try (Releasable replicaRelease = blockReplicas(replicaThreadPool)) {
        final ActionFuture<BulkResponse> successFuture = client(primaryName).bulk(bulkRequest);
        IndexService indexService = internalCluster().getInstance(IndicesService.class, primaryName).iterator().next();
        Index index = indexService.getIndexSettings().getIndex();
        ShardId shardId = new ShardId(index, 0);
        ShardIndexingPressureTracker primaryShardTracker = internalCluster().getInstance(IndexingPressureService.class, primaryName).getShardIndexingPressure().getShardIndexingPressureTracker(shardId);
        ShardIndexingPressureTracker replicaShardTracker = internalCluster().getInstance(IndexingPressureService.class, replicaName).getShardIndexingPressure().getShardIndexingPressureTracker(shardId);
        ShardIndexingPressureTracker coordinatingShardTracker = internalCluster().getInstance(IndexingPressureService.class, coordinatingOnlyNode).getShardIndexingPressure().getShardIndexingPressureTracker(shardId);
        assertBusy(() -> {
            assertEquals(bulkShardRequestSize, primaryShardTracker.getCommonOperationTracker().getCurrentCombinedCoordinatingAndPrimaryBytes());
            assertEquals(0, primaryShardTracker.getReplicaOperationTracker().getStatsTracker().getCurrentBytes());
            assertEquals(0, replicaShardTracker.getCommonOperationTracker().getCurrentCombinedCoordinatingAndPrimaryBytes());
            assertEquals(bulkShardRequestSize, replicaShardTracker.getReplicaOperationTracker().getStatsTracker().getCurrentBytes());
            assertEquals(0, coordinatingShardTracker.getCommonOperationTracker().getCurrentCombinedCoordinatingAndPrimaryBytes());
            assertEquals(0, coordinatingShardTracker.getReplicaOperationTracker().getStatsTracker().getCurrentBytes());
        });
        BulkResponse responses = client(coordinatingOnlyNode).bulk(bulkRequest).actionGet();
        assertTrue(responses.hasFailures());
        assertThat(responses.getItems()[0].getFailure().getCause().getCause(), instanceOf(OpenSearchRejectedExecutionException.class));
        replicaRelease.close();
        successFuture.actionGet();
        assertEquals(0, primaryShardTracker.getCommonOperationTracker().getCurrentCombinedCoordinatingAndPrimaryBytes());
        assertEquals(0, primaryShardTracker.getReplicaOperationTracker().getStatsTracker().getCurrentBytes());
        assertEquals(0, replicaShardTracker.getCommonOperationTracker().getCurrentCombinedCoordinatingAndPrimaryBytes());
        assertEquals(0, replicaShardTracker.getReplicaOperationTracker().getStatsTracker().getCurrentBytes());
        assertEquals(0, coordinatingShardTracker.getCommonOperationTracker().getCurrentCombinedCoordinatingAndPrimaryBytes());
        assertEquals(0, coordinatingShardTracker.getReplicaOperationTracker().getStatsTracker().getCurrentBytes());
        assertEquals(1, primaryShardTracker.getPrimaryOperationTracker().getRejectionTracker().getTotalRejections());
        assertEquals(0, coordinatingShardTracker.getCoordinatingOperationTracker().getRejectionTracker().getTotalRejections());
    }
}
Also used : BulkShardRequest(org.opensearch.action.bulk.BulkShardRequest) ThreadPool(org.opensearch.threadpool.ThreadPool) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) BulkResponse(org.opensearch.action.bulk.BulkResponse) IndexRequest(org.opensearch.action.index.IndexRequest) ShardId(org.opensearch.index.shard.ShardId) BulkRequest(org.opensearch.action.bulk.BulkRequest) 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