Search in sources :

Example 1 with RestoreSnapshotResponse

use of org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse in project OpenSearch by opensearch-project.

the class ClusterShardLimitIT method testRestoreSnapshotOverLimit.

public void testRestoreSnapshotOverLimit() {
    Client client = client();
    logger.info("-->  creating repository");
    Settings.Builder repoSettings = Settings.builder();
    repoSettings.put("location", randomRepoPath());
    repoSettings.put("compress", randomBoolean());
    repoSettings.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES);
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(repoSettings.build()));
    int dataNodes = client().admin().cluster().prepareState().get().getState().getNodes().getDataNodes().size();
    ShardCounts counts = ShardCounts.forDataNodeCount(dataNodes);
    createIndex("snapshot-index", Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_SHARDS, counts.getFailingIndexShards()).put(SETTING_NUMBER_OF_REPLICAS, counts.getFailingIndexReplicas()).build());
    ensureGreen();
    logger.info("--> snapshot");
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("snapshot-index").get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
    List<SnapshotInfo> snapshotInfos = client.admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").get().getSnapshots();
    assertThat(snapshotInfos.size(), equalTo(1));
    SnapshotInfo snapshotInfo = snapshotInfos.get(0);
    assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
    assertThat(snapshotInfo.version(), equalTo(Version.CURRENT));
    // Test restore after index deletion
    logger.info("--> delete indices");
    cluster().wipeIndices("snapshot-index");
    // Reduce the shard limit and fill it up
    setShardsPerNode(counts.getShardsPerNode());
    createIndex("test-fill", Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_SHARDS, counts.getFirstIndexShards()).put(SETTING_NUMBER_OF_REPLICAS, counts.getFirstIndexReplicas()).build());
    logger.info("--> restore one index after deletion");
    try {
        RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("snapshot-index").execute().actionGet();
        fail("Should not have been able to restore snapshot in full cluster");
    } catch (IllegalArgumentException e) {
        verifyException(dataNodes, counts, e);
    }
    ensureGreen();
    ClusterState clusterState = client.admin().cluster().prepareState().get().getState();
    assertFalse(clusterState.getMetadata().hasIndex("snapshot-index"));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) SnapshotInfo(org.opensearch.snapshots.SnapshotInfo) CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) Client(org.opensearch.client.Client) Settings(org.opensearch.common.settings.Settings) RestoreSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 2 with RestoreSnapshotResponse

use of org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse in project OpenSearch by opensearch-project.

the class AbortedRestoreIT method testAbortedRestoreAlsoAbortFileRestores.

public void testAbortedRestoreAlsoAbortFileRestores() throws Exception {
    internalCluster().startMasterOnlyNode();
    final String dataNode = internalCluster().startDataOnlyNode();
    final String indexName = "test-abort-restore";
    createIndex(indexName, indexSettingsNoReplicas(1).build());
    indexRandomDocs(indexName, scaledRandomIntBetween(10, 1_000));
    ensureGreen();
    forceMerge();
    final String repositoryName = "repository";
    createRepository(repositoryName, "mock");
    final String snapshotName = "snapshot";
    createFullSnapshot(repositoryName, snapshotName);
    assertAcked(client().admin().indices().prepareDelete(indexName));
    logger.info("--> blocking all data nodes for repository [{}]", repositoryName);
    blockAllDataNodes(repositoryName);
    failReadsAllDataNodes(repositoryName);
    logger.info("--> starting restore");
    final ActionFuture<RestoreSnapshotResponse> future = client().admin().cluster().prepareRestoreSnapshot(repositoryName, snapshotName).setWaitForCompletion(true).setIndices(indexName).execute();
    assertBusy(() -> {
        final RecoveryResponse recoveries = client().admin().indices().prepareRecoveries(indexName).setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN).setActiveOnly(true).get();
        assertThat(recoveries.hasRecoveries(), is(true));
        final List<RecoveryState> shardRecoveries = recoveries.shardRecoveryStates().get(indexName);
        assertThat(shardRecoveries, hasSize(1));
        assertThat(future.isDone(), is(false));
        for (RecoveryState shardRecovery : shardRecoveries) {
            assertThat(shardRecovery.getRecoverySource().getType(), equalTo(RecoverySource.Type.SNAPSHOT));
            assertThat(shardRecovery.getStage(), equalTo(RecoveryState.Stage.INDEX));
        }
    });
    final ThreadPool.Info snapshotThreadPoolInfo = threadPool(dataNode).info(ThreadPool.Names.SNAPSHOT);
    assertThat(snapshotThreadPoolInfo.getMax(), greaterThan(0));
    logger.info("--> waiting for snapshot thread [max={}] pool to be full", snapshotThreadPoolInfo.getMax());
    waitForMaxActiveSnapshotThreads(dataNode, equalTo(snapshotThreadPoolInfo.getMax()));
    logger.info("--> aborting restore by deleting the index");
    assertAcked(client().admin().indices().prepareDelete(indexName));
    logger.info("--> unblocking repository [{}]", repositoryName);
    unblockAllDataNodes(repositoryName);
    logger.info("--> restore should have failed");
    final RestoreSnapshotResponse restoreSnapshotResponse = future.get();
    assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), equalTo(1));
    assertThat(restoreSnapshotResponse.getRestoreInfo().successfulShards(), equalTo(0));
    logger.info("--> waiting for snapshot thread pool to be empty");
    waitForMaxActiveSnapshotThreads(dataNode, equalTo(0));
}
Also used : ThreadPool(org.opensearch.threadpool.ThreadPool) RecoveryState(org.opensearch.indices.recovery.RecoveryState) RestoreSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse) RecoveryResponse(org.opensearch.action.admin.indices.recovery.RecoveryResponse)

Example 3 with RestoreSnapshotResponse

use of org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse in project OpenSearch by opensearch-project.

the class SnapshotBlocksIT method testRestoreSnapshotWithBlocks.

public void testRestoreSnapshotWithBlocks() {
    assertAcked(client().admin().indices().prepareDelete(INDEX_NAME, OTHER_INDEX_NAME));
    assertFalse(client().admin().indices().prepareExists(INDEX_NAME, OTHER_INDEX_NAME).get().isExists());
    logger.info("-->  restoring a snapshot is blocked when the cluster is read only");
    try {
        setClusterReadOnly(true);
        assertBlocked(client().admin().cluster().prepareRestoreSnapshot(REPOSITORY_NAME, SNAPSHOT_NAME), Metadata.CLUSTER_READ_ONLY_BLOCK);
    } finally {
        setClusterReadOnly(false);
    }
    logger.info("-->  creating a snapshot is allowed when the cluster is not read only");
    RestoreSnapshotResponse response = client().admin().cluster().prepareRestoreSnapshot(REPOSITORY_NAME, SNAPSHOT_NAME).setWaitForCompletion(true).execute().actionGet();
    assertThat(response.status(), equalTo(RestStatus.OK));
    assertTrue(client().admin().indices().prepareExists(INDEX_NAME).get().isExists());
    assertTrue(client().admin().indices().prepareExists(OTHER_INDEX_NAME).get().isExists());
}
Also used : RestoreSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 4 with RestoreSnapshotResponse

use of org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse in project OpenSearch by opensearch-project.

the class IndexRecoveryIT method testSnapshotRecovery.

public void testSnapshotRecovery() throws Exception {
    logger.info("--> start node A");
    String nodeA = internalCluster().startNode();
    logger.info("--> create repository");
    assertAcked(client().admin().cluster().preparePutRepository(REPO_NAME).setType("fs").setSettings(Settings.builder().put("location", randomRepoPath()).put("compress", false)).get());
    ensureGreen();
    logger.info("--> create index on node: {}", nodeA);
    createAndPopulateIndex(INDEX_NAME, 1, SHARD_COUNT, REPLICA_COUNT);
    logger.info("--> snapshot");
    CreateSnapshotResponse createSnapshotResponse = client().admin().cluster().prepareCreateSnapshot(REPO_NAME, SNAP_NAME).setWaitForCompletion(true).setIndices(INDEX_NAME).get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
    assertThat(client().admin().cluster().prepareGetSnapshots(REPO_NAME).setSnapshots(SNAP_NAME).get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS));
    client().admin().indices().prepareClose(INDEX_NAME).execute().actionGet();
    logger.info("--> restore");
    RestoreSnapshotResponse restoreSnapshotResponse = client().admin().cluster().prepareRestoreSnapshot(REPO_NAME, SNAP_NAME).setWaitForCompletion(true).execute().actionGet();
    int totalShards = restoreSnapshotResponse.getRestoreInfo().totalShards();
    assertThat(totalShards, greaterThan(0));
    ensureGreen();
    logger.info("--> request recoveries");
    RecoveryResponse response = client().admin().indices().prepareRecoveries(INDEX_NAME).execute().actionGet();
    Repository repository = internalCluster().getMasterNodeInstance(RepositoriesService.class).repository(REPO_NAME);
    final RepositoryData repositoryData = PlainActionFuture.get(repository::getRepositoryData);
    for (Map.Entry<String, List<RecoveryState>> indexRecoveryStates : response.shardRecoveryStates().entrySet()) {
        assertThat(indexRecoveryStates.getKey(), equalTo(INDEX_NAME));
        List<RecoveryState> recoveryStates = indexRecoveryStates.getValue();
        assertThat(recoveryStates.size(), equalTo(totalShards));
        for (RecoveryState recoveryState : recoveryStates) {
            SnapshotRecoverySource recoverySource = new SnapshotRecoverySource(((SnapshotRecoverySource) recoveryState.getRecoverySource()).restoreUUID(), new Snapshot(REPO_NAME, createSnapshotResponse.getSnapshotInfo().snapshotId()), Version.CURRENT, repositoryData.resolveIndexId(INDEX_NAME));
            assertRecoveryState(recoveryState, 0, recoverySource, true, Stage.DONE, null, nodeA);
            validateIndexRecoveryState(recoveryState.getIndex());
        }
    }
}
Also used : RestoreSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse) RecoveryResponse(org.opensearch.action.admin.indices.recovery.RecoveryResponse) RepositoryData(org.opensearch.repositories.RepositoryData) Snapshot(org.opensearch.snapshots.Snapshot) Repository(org.opensearch.repositories.Repository) SnapshotRecoverySource(org.opensearch.cluster.routing.RecoverySource.SnapshotRecoverySource) CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) RepositoriesService(org.opensearch.repositories.RepositoriesService) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap)

Example 5 with RestoreSnapshotResponse

use of org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse in project OpenSearch by opensearch-project.

the class SharedClusterSnapshotRestoreIT method testMoveShardWhileSnapshotting.

public void testMoveShardWhileSnapshotting() throws Exception {
    Client client = client();
    Path repositoryLocation = randomRepoPath();
    createRepository("test-repo", "mock", Settings.builder().put("location", repositoryLocation).put("random", randomAlphaOfLength(10)).put("wait_after_unblock", 200));
    // Create index on 2 nodes and make sure each node has a primary by setting no replicas
    assertAcked(prepareCreate("test-idx", 2, Settings.builder().put("number_of_replicas", 0)));
    indexRandomDocs("test-idx", 100);
    // Pick one node and block it
    String blockedNode = blockNodeWithIndex("test-repo", "test-idx");
    logger.info("--> snapshot");
    client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(false).setIndices("test-idx").get();
    logger.info("--> waiting for block to kick in");
    waitForBlock(blockedNode, "test-repo", TimeValue.timeValueSeconds(60));
    logger.info("--> execution was blocked on node [{}], moving shards away from this node", blockedNode);
    Settings.Builder excludeSettings = Settings.builder().put("index.routing.allocation.exclude._name", blockedNode);
    client().admin().indices().prepareUpdateSettings("test-idx").setSettings(excludeSettings).get();
    logger.info("--> unblocking blocked node");
    unblockNode("test-repo", blockedNode);
    logger.info("--> waiting for completion");
    logger.info("Number of failed shards [{}]", waitForCompletion("test-repo", "test-snap", TimeValue.timeValueSeconds(600)).shardFailures().size());
    logger.info("--> done");
    final SnapshotInfo snapshotInfo = getSnapshot("test-repo", "test-snap");
    assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
    assertThat(snapshotInfo.shardFailures(), empty());
    logger.info("--> delete index");
    cluster().wipeIndices("test-idx");
    logger.info("--> replace mock repository with real one at the same location");
    createRepository("test-repo", "fs", repositoryLocation);
    logger.info("--> restore index");
    RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    assertDocCount("test-idx", 100L);
}
Also used : Path(java.nio.file.Path) Matchers.containsString(org.hamcrest.Matchers.containsString) Client(org.opensearch.client.Client) Settings(org.opensearch.common.settings.Settings) RestoreSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Aggregations

RestoreSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)48 CreateSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)24 Client (org.opensearch.client.Client)23 Path (java.nio.file.Path)18 Matchers.containsString (org.hamcrest.Matchers.containsString)17 Settings (org.opensearch.common.settings.Settings)11 ClusterState (org.opensearch.cluster.ClusterState)8 RepositoriesService (org.opensearch.repositories.RepositoriesService)8 List (java.util.List)6 Map (java.util.Map)6 SnapshotsStatusResponse (org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse)6 AcknowledgedResponse (org.opensearch.action.support.master.AcknowledgedResponse)6 Collections (java.util.Collections)5 Matchers.is (org.hamcrest.Matchers.is)5 RestoreSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest)5 ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)5 IndexRequestBuilder (org.opensearch.action.index.IndexRequestBuilder)5 HashMap (java.util.HashMap)4 TimeUnit (java.util.concurrent.TimeUnit)4 IntStream (java.util.stream.IntStream)4