Search in sources :

Example 1 with TransportMessageListener

use of org.opensearch.transport.TransportMessageListener in project OpenSearch by opensearch-project.

the class DedicatedClusterSnapshotRestoreIT method testAbortWaitsOnDataNode.

public void testAbortWaitsOnDataNode() throws Exception {
    internalCluster().startMasterOnlyNode();
    final String dataNodeName = internalCluster().startDataOnlyNode();
    final String indexName = "test-index";
    createIndex(indexName);
    index(indexName, "_doc", "some_id", "foo", "bar");
    final String otherDataNode = internalCluster().startDataOnlyNode();
    final String repoName = "test-repo";
    createRepository(repoName, "mock");
    blockAllDataNodes(repoName);
    final String snapshotName = "test-snap";
    final ActionFuture<CreateSnapshotResponse> snapshotResponse = startFullSnapshot(repoName, snapshotName);
    waitForBlock(dataNodeName, repoName, TimeValue.timeValueSeconds(30L));
    final AtomicBoolean blocked = new AtomicBoolean(true);
    final TransportService transportService = internalCluster().getInstance(TransportService.class, otherDataNode);
    transportService.addMessageListener(new TransportMessageListener() {

        @Override
        public void onRequestSent(DiscoveryNode node, long requestId, String action, TransportRequest request, TransportRequestOptions finalOptions) {
            if (blocked.get() && action.equals(SnapshotsService.UPDATE_SNAPSHOT_STATUS_ACTION_NAME)) {
                throw new AssertionError("Node had no assigned shard snapshots so it shouldn't send out shard state updates");
            }
        }
    });
    logger.info("--> abort snapshot");
    final ActionFuture<AcknowledgedResponse> deleteResponse = startDeleteSnapshot(repoName, snapshotName);
    awaitClusterState(otherDataNode, state -> state.custom(SnapshotsInProgress.TYPE, SnapshotsInProgress.EMPTY).entries().stream().anyMatch(entry -> entry.state() == SnapshotsInProgress.State.ABORTED));
    assertFalse("delete should not be able to finish until data node is unblocked", deleteResponse.isDone());
    blocked.set(false);
    unblockAllDataNodes(repoName);
    assertAcked(deleteResponse.get());
    assertThat(snapshotResponse.get().getSnapshotInfo().state(), is(SnapshotState.FAILED));
}
Also used : RepositoryMissingException(org.opensearch.repositories.RepositoryMissingException) Arrays(java.util.Arrays) Metadata(org.opensearch.cluster.metadata.Metadata) CheckedFunction(org.opensearch.common.CheckedFunction) Matchers.not(org.hamcrest.Matchers.not) ClusterScope(org.opensearch.test.OpenSearchIntegTestCase.ClusterScope) Version(org.opensearch.Version) SnapshotsStatusResponse(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse) Strings(org.opensearch.common.Strings) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) RecoveryState(org.opensearch.indices.recovery.RecoveryState) SnapshotStatus(org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Path(java.nio.file.Path) EnumSet(java.util.EnumSet) OpenSearchAssertions.assertRequestBuilderThrows(org.opensearch.test.hamcrest.OpenSearchAssertions.assertRequestBuilderThrows) Client(org.opensearch.client.Client) TimeValue(org.opensearch.common.unit.TimeValue) NodeClient(org.opensearch.client.node.NodeClient) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.allOf(org.hamcrest.Matchers.allOf) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) Settings(org.opensearch.common.settings.Settings) TestCustomMetadata(org.opensearch.test.TestCustomMetadata) Scope(org.opensearch.test.OpenSearchIntegTestCase.Scope) TransportService(org.opensearch.transport.TransportService) RetentionLeaseActions(org.opensearch.index.seqno.RetentionLeaseActions) UncheckedIOException(java.io.UncheckedIOException) FileVisitResult(java.nio.file.FileVisitResult) CountDownLatch(java.util.concurrent.CountDownLatch) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Priority(org.opensearch.common.Priority) Node(org.opensearch.node.Node) ParseField(org.opensearch.common.ParseField) Writeable(org.opensearch.common.io.stream.Writeable) MockTransportService(org.opensearch.test.transport.MockTransportService) ArrayList(java.util.ArrayList) RestoreSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse) ClusterState(org.opensearch.cluster.ClusterState) BusyMasterServiceDisruption(org.opensearch.test.disruption.BusyMasterServiceDisruption) Matchers.lessThan(org.hamcrest.Matchers.lessThan) Matchers.hasSize(org.hamcrest.Matchers.hasSize) AbstractRestChannel(org.opensearch.rest.AbstractRestChannel) Environment(org.opensearch.env.Environment) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Files(java.nio.file.Files) RETAIN_ALL(org.opensearch.index.seqno.RetentionLeaseActions.RETAIN_ALL) IOException(java.io.IOException) TransportMessageListener(org.opensearch.transport.TransportMessageListener) Plugin(org.opensearch.plugins.Plugin) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) RetentionLeases(org.opensearch.index.seqno.RetentionLeases) ClusterService(org.opensearch.cluster.service.ClusterService) ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) IndexRequestBuilder(org.opensearch.action.index.IndexRequestBuilder) BlobStoreRepository(org.opensearch.repositories.blobstore.BlobStoreRepository) NodeRoles.nonMasterNode(org.opensearch.test.NodeRoles.nonMasterNode) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) XContentParser(org.opensearch.common.xcontent.XContentParser) FakeRestRequest(org.opensearch.test.rest.FakeRestRequest) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Locale(java.util.Locale) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) Collection(java.util.Collection) RestStatus(org.opensearch.rest.RestStatus) ServiceDisruptionScheme(org.opensearch.test.disruption.ServiceDisruptionScheme) MockRepository(org.opensearch.snapshots.mockstore.MockRepository) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) SnapshotStats(org.opensearch.action.admin.cluster.snapshots.status.SnapshotStats) RestGetRepositoriesAction(org.opensearch.rest.action.admin.cluster.RestGetRepositoriesAction) SnapshotsInProgress(org.opensearch.cluster.SnapshotsInProgress) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InternalTestCluster(org.opensearch.test.InternalTestCluster) AtomicReference(java.util.concurrent.atomic.AtomicReference) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) PeerRecoveryTargetService(org.opensearch.indices.recovery.PeerRecoveryTargetService) StreamInput(org.opensearch.common.io.stream.StreamInput) SettingsFilter(org.opensearch.common.settings.SettingsFilter) OpenSearchAssertions.assertAcked(org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked) CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) Setting(org.opensearch.common.settings.Setting) TransportRequest(org.opensearch.transport.TransportRequest) RestRequest(org.opensearch.rest.RestRequest) IntHashSet(com.carrotsearch.hppc.IntHashSet) IntSet(com.carrotsearch.hppc.IntSet) RestClusterStateAction(org.opensearch.rest.action.admin.cluster.RestClusterStateAction) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) OpenSearchAssertions.assertFutureThrows(org.opensearch.test.hamcrest.OpenSearchAssertions.assertFutureThrows) RestResponse(org.opensearch.rest.RestResponse) ActionFuture(org.opensearch.action.ActionFuture) ActiveShardCount(org.opensearch.action.support.ActiveShardCount) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) ShardId(org.opensearch.index.shard.ShardId) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Sets(org.opensearch.common.util.set.Sets) CreateSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) GetSnapshotsResponse(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) NamedDiff(org.opensearch.cluster.NamedDiff) Collections(java.util.Collections) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) TransportRequest(org.opensearch.transport.TransportRequest) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) TransportService(org.opensearch.transport.TransportService) MockTransportService(org.opensearch.test.transport.MockTransportService) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) TransportMessageListener(org.opensearch.transport.TransportMessageListener)

Example 2 with TransportMessageListener

use of org.opensearch.transport.TransportMessageListener in project OpenSearch by opensearch-project.

the class IndicesStoreIntegrationIT method relocateAndBlockCompletion.

/**
 * relocate a shard and block cluster state processing on the relocation target node to activate the shard
 */
public static BlockClusterStateProcessing relocateAndBlockCompletion(Logger logger, String index, int shard, String nodeFrom, String nodeTo) throws InterruptedException {
    BlockClusterStateProcessing disruption = new BlockClusterStateProcessing(nodeTo, random());
    internalCluster().setDisruptionScheme(disruption);
    MockTransportService transportService = (MockTransportService) internalCluster().getInstance(TransportService.class, nodeTo);
    CountDownLatch beginRelocationLatch = new CountDownLatch(1);
    CountDownLatch receivedShardExistsRequestLatch = new CountDownLatch(1);
    // use a tracer on the target node to track relocation start and end
    transportService.addMessageListener(new TransportMessageListener() {

        @Override
        public void onRequestReceived(long requestId, String action) {
            if (action.equals(PeerRecoveryTargetService.Actions.FILES_INFO)) {
                logger.info("received: {}, relocation starts", action);
                beginRelocationLatch.countDown();
            } else if (action.equals(IndicesStore.ACTION_SHARD_EXISTS)) {
                // Whenever a node deletes a shard because it was relocated somewhere else, it first
                // checks if enough other copies are started somewhere else. The node sends a ShardActiveRequest
                // to the other nodes that should have a copy according to cluster state.
                receivedShardExistsRequestLatch.countDown();
                logger.info("received: {}, relocation done", action);
            }
        }
    });
    internalCluster().client().admin().cluster().prepareReroute().add(new MoveAllocationCommand(index, shard, nodeFrom, nodeTo)).get();
    logger.info("--> waiting for relocation to start");
    beginRelocationLatch.await();
    logger.info("--> starting disruption");
    disruption.startDisrupting();
    logger.info("--> waiting for relocation to finish");
    receivedShardExistsRequestLatch.await();
    logger.info("--> relocation completed (but cluster state processing block still in place)");
    return disruption;
}
Also used : BlockClusterStateProcessing(org.opensearch.test.disruption.BlockClusterStateProcessing) MockTransportService(org.opensearch.test.transport.MockTransportService) TransportService(org.opensearch.transport.TransportService) MockTransportService(org.opensearch.test.transport.MockTransportService) MoveAllocationCommand(org.opensearch.cluster.routing.allocation.command.MoveAllocationCommand) CountDownLatch(java.util.concurrent.CountDownLatch) TransportMessageListener(org.opensearch.transport.TransportMessageListener)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntSet (com.carrotsearch.hppc.IntSet)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 FileVisitResult (java.nio.file.FileVisitResult)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 SimpleFileVisitor (java.nio.file.SimpleFileVisitor)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Locale (java.util.Locale)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1