Search in sources :

Example 1 with GetSnapshotsResponse

use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse in project OpenSearch by opensearch-project.

the class SnapshotDisruptionIT method assertSnapshotExists.

private void assertSnapshotExists(String repository, String snapshot) {
    GetSnapshotsResponse snapshotsStatusResponse = dataNodeClient().admin().cluster().prepareGetSnapshots(repository).setSnapshots(snapshot).get();
    SnapshotInfo snapshotInfo = snapshotsStatusResponse.getSnapshots().get(0);
    assertEquals(SnapshotState.SUCCESS, snapshotInfo.state());
    assertEquals(snapshotInfo.totalShards(), snapshotInfo.successfulShards());
    assertEquals(0, snapshotInfo.failedShards());
    logger.info("--> done verifying, snapshot exists");
}
Also used : GetSnapshotsResponse(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) SnapshotInfo(org.opensearch.snapshots.SnapshotInfo)

Example 2 with GetSnapshotsResponse

use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse in project OpenSearch by opensearch-project.

the class DedicatedClusterSnapshotRestoreIT method testDataNodeRestartWithBusyMasterDuringSnapshot.

public void testDataNodeRestartWithBusyMasterDuringSnapshot() throws Exception {
    logger.info("-->  starting a master node and two data nodes");
    internalCluster().startMasterOnlyNode();
    internalCluster().startDataOnlyNodes(2);
    final Path repoPath = randomRepoPath();
    createRepository("test-repo", "mock", repoPath);
    maybeInitWithOldSnapshotVersion("test-repo", repoPath);
    assertAcked(prepareCreate("test-idx", 0, indexSettingsNoReplicas(5)));
    ensureGreen();
    indexRandomDocs("test-idx", randomIntBetween(50, 100));
    final String dataNode = blockNodeWithIndex("test-repo", "test-idx");
    logger.info("-->  snapshot");
    ServiceDisruptionScheme disruption = new BusyMasterServiceDisruption(random(), Priority.HIGH);
    setDisruptionScheme(disruption);
    client(internalCluster().getMasterName()).admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(false).setIndices("test-idx").get();
    disruption.startDisrupting();
    logger.info("-->  restarting data node, which should cause primary shards to be failed");
    internalCluster().restartNode(dataNode, InternalTestCluster.EMPTY_CALLBACK);
    logger.info("-->  wait for shard snapshots to show as failed");
    assertBusy(() -> assertThat(clusterAdmin().prepareSnapshotStatus("test-repo").setSnapshots("test-snap").get().getSnapshots().get(0).getShardsStats().getFailedShards(), greaterThanOrEqualTo(1)), 60L, TimeUnit.SECONDS);
    unblockNode("test-repo", dataNode);
    disruption.stopDisrupting();
    // check that snapshot completes
    assertBusy(() -> {
        GetSnapshotsResponse snapshotsStatusResponse = clusterAdmin().prepareGetSnapshots("test-repo").setSnapshots("test-snap").setIgnoreUnavailable(true).get();
        assertEquals(1, snapshotsStatusResponse.getSnapshots().size());
        SnapshotInfo snapshotInfo = snapshotsStatusResponse.getSnapshots().get(0);
        assertTrue(snapshotInfo.state().toString(), snapshotInfo.state().completed());
    }, 60L, TimeUnit.SECONDS);
}
Also used : Path(java.nio.file.Path) BusyMasterServiceDisruption(org.opensearch.test.disruption.BusyMasterServiceDisruption) GetSnapshotsResponse(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) ServiceDisruptionScheme(org.opensearch.test.disruption.ServiceDisruptionScheme) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 3 with GetSnapshotsResponse

use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse in project OpenSearch by opensearch-project.

the class DedicatedClusterSnapshotRestoreIT method testDataNodeRestartAfterShardSnapshotFailure.

public void testDataNodeRestartAfterShardSnapshotFailure() throws Exception {
    logger.info("-->  starting a master node and two data nodes");
    internalCluster().startMasterOnlyNode();
    final List<String> dataNodes = internalCluster().startDataOnlyNodes(2);
    final Path repoPath = randomRepoPath();
    createRepository("test-repo", "mock", repoPath);
    maybeInitWithOldSnapshotVersion("test-repo", repoPath);
    assertAcked(prepareCreate("test-idx", 0, indexSettingsNoReplicas(2)));
    ensureGreen();
    indexRandomDocs("test-idx", randomIntBetween(50, 100));
    blockAllDataNodes("test-repo");
    logger.info("-->  snapshot");
    client(internalCluster().getMasterName()).admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(false).setIndices("test-idx").get();
    logger.info("-->  restarting first data node, which should cause the primary shard on it to be failed");
    internalCluster().restartNode(dataNodes.get(0), InternalTestCluster.EMPTY_CALLBACK);
    logger.info("-->  wait for shard snapshot of first primary to show as failed");
    assertBusy(() -> assertThat(clusterAdmin().prepareSnapshotStatus("test-repo").setSnapshots("test-snap").get().getSnapshots().get(0).getShardsStats().getFailedShards(), is(1)), 60L, TimeUnit.SECONDS);
    logger.info("-->  restarting second data node, which should cause the primary shard on it to be failed");
    internalCluster().restartNode(dataNodes.get(1), InternalTestCluster.EMPTY_CALLBACK);
    // check that snapshot completes with both failed shards being accounted for in the snapshot result
    assertBusy(() -> {
        GetSnapshotsResponse snapshotsStatusResponse = clusterAdmin().prepareGetSnapshots("test-repo").setSnapshots("test-snap").setIgnoreUnavailable(true).get();
        assertEquals(1, snapshotsStatusResponse.getSnapshots().size());
        SnapshotInfo snapshotInfo = snapshotsStatusResponse.getSnapshots().get(0);
        assertTrue(snapshotInfo.state().toString(), snapshotInfo.state().completed());
        assertThat(snapshotInfo.totalShards(), is(2));
        assertThat(snapshotInfo.shardFailures(), hasSize(2));
    }, 60L, TimeUnit.SECONDS);
}
Also used : Path(java.nio.file.Path) GetSnapshotsResponse(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 4 with GetSnapshotsResponse

use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse in project OpenSearch by opensearch-project.

the class SharedClusterSnapshotRestoreIT method testBulkDeleteWithOverlappingPatterns.

public void testBulkDeleteWithOverlappingPatterns() {
    final int numberOfSnapshots = between(5, 15);
    createRepository("test-repo", "fs");
    final String[] indices = { "test-idx-1", "test-idx-2", "test-idx-3" };
    createIndex(indices);
    ensureGreen();
    logger.info("--> creating {} snapshots ", numberOfSnapshots);
    for (int i = 0; i < numberOfSnapshots; i++) {
        for (int j = 0; j < 10; j++) {
            index(randomFrom(indices), "_doc", Integer.toString(i * 10 + j), "foo", "bar" + i * 10 + j);
        }
        refresh();
        logger.info("--> snapshot {}", i);
        CreateSnapshotResponse createSnapshotResponse = clusterAdmin().prepareCreateSnapshot("test-repo", "test-snap-" + i).setWaitForCompletion(true).get();
        assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
        assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
    }
    logger.info("--> deleting all snapshots");
    clusterAdmin().prepareDeleteSnapshot("test-repo", "test-snap-*", "*").get();
    final GetSnapshotsResponse getSnapshotsResponse = clusterAdmin().prepareGetSnapshots("test-repo").get();
    assertThat(getSnapshotsResponse.getSnapshots(), empty());
}
Also used : GetSnapshotsResponse(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 5 with GetSnapshotsResponse

use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse in project OpenSearch by opensearch-project.

the class SharedClusterSnapshotRestoreIT method testGetSnapshotsFromIndexBlobOnly.

public void testGetSnapshotsFromIndexBlobOnly() throws Exception {
    logger.info("--> creating repository");
    final Path repoPath = randomRepoPath();
    final Client client = client();
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setVerify(false).setSettings(Settings.builder().put("location", repoPath)));
    logger.info("--> creating random number of indices");
    final int numIndices = randomIntBetween(1, 10);
    for (int i = 0; i < numIndices; i++) {
        assertAcked(prepareCreate("test-idx-" + i).setSettings(indexSettingsNoReplicas(1)));
    }
    logger.info("--> creating random number of snapshots");
    final int numSnapshots = randomIntBetween(1, 10);
    final Map<String, List<String>> indicesPerSnapshot = new HashMap<>();
    for (int i = 0; i < numSnapshots; i++) {
        // index some additional docs (maybe) for each index
        for (int j = 0; j < numIndices; j++) {
            if (randomBoolean()) {
                final int numDocs = randomIntBetween(1, 5);
                for (int k = 0; k < numDocs; k++) {
                    index("test-idx-" + j, "_doc", Integer.toString(k), "foo", "bar" + k);
                }
                refresh();
            }
        }
        final boolean all = randomBoolean();
        boolean atLeastOne = false;
        List<String> indices = new ArrayList<>();
        for (int j = 0; j < numIndices; j++) {
            if (all || randomBoolean() || !atLeastOne) {
                indices.add("test-idx-" + j);
                atLeastOne = true;
            }
        }
        final String snapshotName = "test-snap-" + i;
        indicesPerSnapshot.put(snapshotName, indices);
        createSnapshot("test-repo", snapshotName, indices);
    }
    logger.info("--> verify _all returns snapshot info");
    GetSnapshotsResponse response = clusterAdmin().prepareGetSnapshots("test-repo").setSnapshots("_all").setVerbose(false).get();
    assertEquals(indicesPerSnapshot.size(), response.getSnapshots().size());
    verifySnapshotInfo(response, indicesPerSnapshot);
    logger.info("--> verify wildcard returns snapshot info");
    response = clusterAdmin().prepareGetSnapshots("test-repo").setSnapshots("test-snap-*").setVerbose(false).get();
    assertEquals(indicesPerSnapshot.size(), response.getSnapshots().size());
    verifySnapshotInfo(response, indicesPerSnapshot);
    logger.info("--> verify individual requests return snapshot info");
    for (int i = 0; i < numSnapshots; i++) {
        response = clusterAdmin().prepareGetSnapshots("test-repo").setSnapshots("test-snap-" + i).setVerbose(false).get();
        assertEquals(1, response.getSnapshots().size());
        verifySnapshotInfo(response, indicesPerSnapshot);
    }
}
Also used : Path(java.nio.file.Path) GetSnapshotsResponse(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) Client(org.opensearch.client.Client)

Aggregations

GetSnapshotsResponse (org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse)14 Path (java.nio.file.Path)6 Matchers.containsString (org.hamcrest.Matchers.containsString)5 CreateSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)5 Client (org.opensearch.client.Client)5 GetSnapshotsRequest (org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest)4 SnapshotInfo (org.opensearch.snapshots.SnapshotInfo)4 List (java.util.List)3 RestoreSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)3 SnapshotsStatusResponse (org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse)3 SnapshotState (org.opensearch.snapshots.SnapshotState)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 TimeUnit (java.util.concurrent.TimeUnit)2 SnapshotIndexShardStatus (org.opensearch.action.admin.cluster.snapshots.status.SnapshotIndexShardStatus)2 SnapshotStatus (org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus)2 AcknowledgedResponse (org.opensearch.action.support.master.AcknowledgedResponse)2 TimeValue (org.opensearch.common.unit.TimeValue)2 IOException (java.io.IOException)1 Instant (java.time.Instant)1