Search in sources :

Example 1 with CreateSnapshotResponse

use of org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse in project OpenSearch by opensearch-project.

the class SnapshotIT method testCreateSnapshot.

public void testCreateSnapshot() throws Exception {
    String repository = "test_repository";
    assertTrue(createTestRepository(repository, FsRepository.TYPE, "{\"location\": \".\"}").isAcknowledged());
    String snapshot = "test_snapshot";
    CreateSnapshotRequest request = new CreateSnapshotRequest(repository, snapshot);
    boolean waitForCompletion = randomBoolean();
    request.waitForCompletion(waitForCompletion);
    if (randomBoolean()) {
        request.userMetadata(randomUserMetadata());
    }
    request.partial(randomBoolean());
    request.includeGlobalState(randomBoolean());
    CreateSnapshotResponse response = createTestSnapshot(request);
    assertEquals(waitForCompletion ? RestStatus.OK : RestStatus.ACCEPTED, response.status());
    if (waitForCompletion == false) {
        // If we don't wait for the snapshot to complete we have to cancel it to not leak the snapshot task
        AcknowledgedResponse deleteResponse = execute(new DeleteSnapshotRequest(repository, snapshot), highLevelClient().snapshot()::delete, highLevelClient().snapshot()::deleteAsync);
        assertTrue(deleteResponse.isAcknowledged());
    }
}
Also used : CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) CreateSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) DeleteSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest)

Example 2 with CreateSnapshotResponse

use of org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse 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 3 with CreateSnapshotResponse

use of org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse in project OpenSearch by opensearch-project.

the class ConcurrentSnapshotsIT method testAssertMultipleSnapshotsAndPrimaryFailOver.

public void testAssertMultipleSnapshotsAndPrimaryFailOver() throws Exception {
    internalCluster().startMasterOnlyNode();
    final String dataNode = internalCluster().startDataOnlyNode();
    final String repoName = "test-repo";
    createRepository(repoName, "mock");
    final String testIndex = "index-one";
    createIndex(testIndex, Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 1).build());
    ensureYellow(testIndex);
    index(testIndex, "_doc", "some_id", "foo", "bar");
    blockDataNode(repoName, dataNode);
    final ActionFuture<CreateSnapshotResponse> firstSnapshotResponse = startFullSnapshotFromMasterClient(repoName, "snapshot-one");
    waitForBlock(dataNode, repoName, TimeValue.timeValueSeconds(30L));
    internalCluster().startDataOnlyNode();
    ensureStableCluster(3);
    ensureGreen(testIndex);
    final String secondSnapshot = "snapshot-two";
    final ActionFuture<CreateSnapshotResponse> secondSnapshotResponse = startFullSnapshotFromMasterClient(repoName, secondSnapshot);
    // make sure second snapshot is in progress before restarting data node
    waitUntilInprogress(repoName, secondSnapshot, TimeValue.timeValueSeconds(5L));
    internalCluster().restartNode(dataNode, InternalTestCluster.EMPTY_CALLBACK);
    assertThat(firstSnapshotResponse.get().getSnapshotInfo().state(), is(SnapshotState.PARTIAL));
    assertThat(secondSnapshotResponse.get().getSnapshotInfo().state(), is(SnapshotState.PARTIAL));
}
Also used : CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 4 with CreateSnapshotResponse

use of org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse in project OpenSearch by opensearch-project.

the class ConcurrentSnapshotsIT method testAbortOneOfMultipleSnapshots.

public void testAbortOneOfMultipleSnapshots() throws Exception {
    internalCluster().startMasterOnlyNode();
    final String dataNode = internalCluster().startDataOnlyNode();
    final String repoName = "test-repo";
    createRepository(repoName, "mock");
    final String firstIndex = "index-one";
    createIndexWithContent(firstIndex);
    final String firstSnapshot = "snapshot-one";
    final ActionFuture<CreateSnapshotResponse> firstSnapshotResponse = startFullSnapshotBlockedOnDataNode(firstSnapshot, repoName, dataNode);
    final String dataNode2 = internalCluster().startDataOnlyNode();
    ensureStableCluster(3);
    final String secondIndex = "index-two";
    createIndexWithContent(secondIndex, dataNode2, dataNode);
    final String secondSnapshot = "snapshot-two";
    final ActionFuture<CreateSnapshotResponse> secondSnapshotResponse = startFullSnapshot(repoName, secondSnapshot);
    logger.info("--> wait for snapshot on second data node to finish");
    awaitClusterState(state -> {
        final SnapshotsInProgress snapshotsInProgress = state.custom(SnapshotsInProgress.TYPE, SnapshotsInProgress.EMPTY);
        return snapshotsInProgress.entries().size() == 2 && snapshotHasCompletedShard(secondSnapshot, snapshotsInProgress);
    });
    final ActionFuture<AcknowledgedResponse> deleteSnapshotsResponse = startDeleteSnapshot(repoName, firstSnapshot);
    awaitNDeletionsInProgress(1);
    logger.info("--> start third snapshot");
    final ActionFuture<CreateSnapshotResponse> thirdSnapshotResponse = client().admin().cluster().prepareCreateSnapshot(repoName, "snapshot-three").setIndices(secondIndex).setWaitForCompletion(true).execute();
    assertThat(firstSnapshotResponse.isDone(), is(false));
    assertThat(secondSnapshotResponse.isDone(), is(false));
    unblockNode(repoName, dataNode);
    final SnapshotInfo firstSnapshotInfo = firstSnapshotResponse.get().getSnapshotInfo();
    assertThat(firstSnapshotInfo.state(), is(SnapshotState.FAILED));
    assertThat(firstSnapshotInfo.reason(), is("Snapshot was aborted by deletion"));
    final SnapshotInfo secondSnapshotInfo = assertSuccessful(secondSnapshotResponse);
    final SnapshotInfo thirdSnapshotInfo = assertSuccessful(thirdSnapshotResponse);
    assertThat(deleteSnapshotsResponse.get().isAcknowledged(), is(true));
    logger.info("--> verify that the first snapshot is gone");
    assertThat(client().admin().cluster().prepareGetSnapshots(repoName).get().getSnapshots(), containsInAnyOrder(secondSnapshotInfo, thirdSnapshotInfo));
}
Also used : CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) SnapshotsInProgress(org.opensearch.cluster.SnapshotsInProgress) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 5 with CreateSnapshotResponse

use of org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse in project OpenSearch by opensearch-project.

the class ConcurrentSnapshotsIT method testQueuedSnapshotOperationsAndBrokenRepoOnMasterFailOver2.

public void testQueuedSnapshotOperationsAndBrokenRepoOnMasterFailOver2() throws Exception {
    disableRepoConsistencyCheck("This test corrupts the repository on purpose");
    internalCluster().startMasterOnlyNodes(3);
    final String dataNode = internalCluster().startDataOnlyNode();
    final String repoName = "test-repo";
    final Path repoPath = randomRepoPath();
    createRepository(repoName, "mock", repoPath);
    createIndexWithContent("index-one");
    createNSnapshots(repoName, randomIntBetween(2, 5));
    final long generation = getRepositoryData(repoName).getGenId();
    final String masterNode = internalCluster().getMasterName();
    blockMasterFromFinalizingSnapshotOnIndexFile(repoName);
    final ActionFuture<CreateSnapshotResponse> snapshotThree = startFullSnapshotFromNonMasterClient(repoName, "snapshot-three");
    waitForBlock(masterNode, repoName, TimeValue.timeValueSeconds(30L));
    corruptIndexN(repoPath, generation);
    final ActionFuture<CreateSnapshotResponse> snapshotFour = startFullSnapshotFromNonMasterClient(repoName, "snapshot-four");
    awaitNumberOfSnapshotsInProgress(2);
    final NetworkDisruption networkDisruption = isolateMasterDisruption(NetworkDisruption.DISCONNECT);
    internalCluster().setDisruptionScheme(networkDisruption);
    networkDisruption.startDisrupting();
    ensureStableCluster(3, dataNode);
    unblockNode(repoName, masterNode);
    networkDisruption.stopDisrupting();
    awaitNoMoreRunningOperations();
    expectThrows(OpenSearchException.class, snapshotThree::actionGet);
    expectThrows(OpenSearchException.class, snapshotFour::actionGet);
}
Also used : Path(java.nio.file.Path) CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkDisruption(org.opensearch.test.disruption.NetworkDisruption)

Aggregations

CreateSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)110 Matchers.containsString (org.hamcrest.Matchers.containsString)53 AcknowledgedResponse (org.opensearch.action.support.master.AcknowledgedResponse)41 Path (java.nio.file.Path)32 RestoreSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)31 Client (org.opensearch.client.Client)27 RepositoryData (org.opensearch.repositories.RepositoryData)20 BlobStoreRepository (org.opensearch.repositories.blobstore.BlobStoreRepository)20 RepositoriesService (org.opensearch.repositories.RepositoriesService)18 Repository (org.opensearch.repositories.Repository)18 Settings (org.opensearch.common.settings.Settings)17 ClusterState (org.opensearch.cluster.ClusterState)16 SnapshotsInProgress (org.opensearch.cluster.SnapshotsInProgress)16 List (java.util.List)15 PlainActionFuture (org.opensearch.action.support.PlainActionFuture)15 Collections (java.util.Collections)14 Map (java.util.Map)14 IOException (java.io.IOException)13 Collectors (java.util.stream.Collectors)13 Matchers.is (org.hamcrest.Matchers.is)13