Search in sources :

Example 1 with RestoreSnapshotResponse

use of org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse in project elasticsearch by elastic.

the class SharedClusterSnapshotRestoreIT method testRestoreWithDifferentMappingsAndSettings.

public void testRestoreWithDifferentMappingsAndSettings() throws Exception {
    Client client = client();
    logger.info("-->  creating repository");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", randomRepoPath()).put("compress", randomBoolean()).put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
    logger.info("--> create index with foo type");
    assertAcked(prepareCreate("test-idx", 2, Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_REPLICAS, between(0, 1)).put("refresh_interval", 10, TimeUnit.SECONDS)));
    NumShards numShards = getNumShards("test-idx");
    assertAcked(client().admin().indices().preparePutMapping("test-idx").setType("foo").setSource("baz", "type=text"));
    ensureGreen();
    logger.info("--> snapshot it");
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
    logger.info("--> delete the index and recreate it with bar type");
    cluster().wipeIndices("test-idx");
    assertAcked(prepareCreate("test-idx", 2, Settings.builder().put(SETTING_NUMBER_OF_SHARDS, numShards.numPrimaries).put(SETTING_NUMBER_OF_REPLICAS, between(0, 1)).put("refresh_interval", 5, TimeUnit.SECONDS)));
    assertAcked(client().admin().indices().preparePutMapping("test-idx").setType("bar").setSource("baz", "type=text"));
    ensureGreen();
    logger.info("--> close index");
    client.admin().indices().prepareClose("test-idx").get();
    logger.info("--> restore all indices from the snapshot");
    RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    logger.info("--> assert that old mapping is restored");
    ImmutableOpenMap<String, MappingMetaData> mappings = client().admin().cluster().prepareState().get().getState().getMetaData().getIndices().get("test-idx").getMappings();
    assertThat(mappings.get("foo"), notNullValue());
    assertThat(mappings.get("bar"), nullValue());
    logger.info("--> assert that old settings are restored");
    GetSettingsResponse getSettingsResponse = client.admin().indices().prepareGetSettings("test-idx").execute().actionGet();
    assertThat(getSettingsResponse.getSetting("test-idx", "index.refresh_interval"), equalTo("10000ms"));
}
Also used : CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Client(org.elasticsearch.client.Client) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 2 with RestoreSnapshotResponse

use of org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse in project elasticsearch by elastic.

the class SharedClusterSnapshotRestoreIT method testDeleteRepositoryWhileSnapshotting.

public void testDeleteRepositoryWhileSnapshotting() throws Exception {
    Client client = client();
    Path repositoryLocation = randomRepoPath();
    logger.info("-->  creating repository");
    PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo").setType("mock").setSettings(Settings.builder().put("location", repositoryLocation).put("random", randomAsciiOfLength(10)).put("wait_after_unblock", 200)).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    // 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)));
    logger.info("--> indexing some data");
    for (int i = 0; i < 100; i++) {
        index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
    }
    refresh();
    assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
    // 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 [{}], trying to delete repository", blockedNode);
    try {
        client.admin().cluster().prepareDeleteRepository("test-repo").execute().get();
        fail("shouldn't be able to delete in-use repository");
    } catch (Exception ex) {
        logger.info("--> in-use repository deletion failed");
    }
    logger.info("--> trying to move repository to another location");
    try {
        client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", repositoryLocation.resolve("test"))).get();
        fail("shouldn't be able to replace in-use repository");
    } catch (Exception ex) {
        logger.info("--> in-use repository replacement failed");
    }
    logger.info("--> trying to create a repository with different name");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo-2").setType("fs").setSettings(Settings.builder().put("location", repositoryLocation.resolve("test"))));
    logger.info("--> unblocking blocked node");
    unblockNode("test-repo", blockedNode);
    logger.info("--> waiting for completion");
    SnapshotInfo snapshotInfo = waitForCompletion("test-repo", "test-snap", TimeValue.timeValueSeconds(600));
    logger.info("Number of failed shards [{}]", snapshotInfo.shardFailures().size());
    logger.info("--> done");
    List<SnapshotInfo> snapshotInfos = client().admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").get().getSnapshots();
    assertThat(snapshotInfos.size(), equalTo(1));
    assertThat(snapshotInfos.get(0).state(), equalTo(SnapshotState.SUCCESS));
    assertThat(snapshotInfos.get(0).shardFailures().size(), equalTo(0));
    logger.info("--> delete index");
    cluster().wipeIndices("test-idx");
    logger.info("--> replace mock repository with real one at the same location");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", 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));
    assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
}
Also used : Path(java.nio.file.Path) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Client(org.elasticsearch.client.Client) InvalidIndexNameException(org.elasticsearch.indices.InvalidIndexNameException) ExecutionException(java.util.concurrent.ExecutionException) RepositoryException(org.elasticsearch.repositories.RepositoryException) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 3 with RestoreSnapshotResponse

use of org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse in project elasticsearch by elastic.

the class SharedClusterSnapshotRestoreIT method testThrottling.

public void testThrottling() throws Exception {
    Client client = client();
    logger.info("-->  creating repository");
    Path repositoryLocation = randomRepoPath();
    boolean throttleSnapshot = randomBoolean();
    boolean throttleRestore = randomBoolean();
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", repositoryLocation).put("compress", randomBoolean()).put("chunk_size", randomIntBetween(1000, 10000), ByteSizeUnit.BYTES).put("max_restore_bytes_per_sec", throttleRestore ? "10k" : "0").put("max_snapshot_bytes_per_sec", throttleSnapshot ? "10k" : "0")));
    createIndex("test-idx");
    ensureGreen();
    logger.info("--> indexing some data");
    for (int i = 0; i < 100; i++) {
        index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
    }
    refresh();
    assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
    logger.info("--> snapshot");
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
    logger.info("--> delete index");
    cluster().wipeIndices("test-idx");
    logger.info("--> restore index");
    RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
    long snapshotPause = 0L;
    long restorePause = 0L;
    for (RepositoriesService repositoriesService : internalCluster().getDataNodeInstances(RepositoriesService.class)) {
        snapshotPause += repositoriesService.repository("test-repo").getSnapshotThrottleTimeInNanos();
        restorePause += repositoriesService.repository("test-repo").getRestoreThrottleTimeInNanos();
    }
    if (throttleSnapshot) {
        assertThat(snapshotPause, greaterThan(0L));
    } else {
        assertThat(snapshotPause, equalTo(0L));
    }
    if (throttleRestore) {
        assertThat(restorePause, greaterThan(0L));
    } else {
        assertThat(restorePause, equalTo(0L));
    }
}
Also used : Path(java.nio.file.Path) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) Client(org.elasticsearch.client.Client) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 4 with RestoreSnapshotResponse

use of org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse in project elasticsearch by elastic.

the class SharedClusterSnapshotRestoreIT method testDeleteSnapshotWhileRestoringFails.

public void testDeleteSnapshotWhileRestoringFails() throws Exception {
    Client client = client();
    logger.info("-->  creating repository");
    final String repoName = "test-repo";
    assertAcked(client.admin().cluster().preparePutRepository(repoName).setType("mock").setSettings(Settings.builder().put("location", randomRepoPath())));
    logger.info("--> creating index");
    final String indexName = "test-idx";
    assertAcked(prepareCreate(indexName).setWaitForActiveShards(ActiveShardCount.ALL));
    logger.info("--> indexing some data");
    for (int i = 0; i < 100; i++) {
        index(indexName, "doc", Integer.toString(i), "foo", "bar" + i);
    }
    refresh();
    assertThat(client.prepareSearch(indexName).setSize(0).get().getHits().getTotalHits(), equalTo(100L));
    logger.info("--> take snapshots");
    final String snapshotName = "test-snap";
    assertThat(client.admin().cluster().prepareCreateSnapshot(repoName, snapshotName).setIndices(indexName).setWaitForCompletion(true).get().getSnapshotInfo().state(), equalTo(SnapshotState.SUCCESS));
    final String snapshotName2 = "test-snap-2";
    assertThat(client.admin().cluster().prepareCreateSnapshot(repoName, snapshotName2).setIndices(indexName).setWaitForCompletion(true).get().getSnapshotInfo().state(), equalTo(SnapshotState.SUCCESS));
    logger.info("--> delete index before restoring");
    assertAcked(client.admin().indices().prepareDelete(indexName).get());
    logger.info("--> execution will be blocked on all data nodes");
    blockAllDataNodes(repoName);
    final ListenableActionFuture<RestoreSnapshotResponse> restoreFut;
    try {
        logger.info("--> start restore");
        restoreFut = client.admin().cluster().prepareRestoreSnapshot(repoName, snapshotName).setWaitForCompletion(true).execute();
        logger.info("--> waiting for block to kick in");
        waitForBlockOnAnyDataNode(repoName, TimeValue.timeValueMinutes(1));
        logger.info("--> try deleting the snapshot while the restore is in progress (should throw an error)");
        ConcurrentSnapshotExecutionException e = expectThrows(ConcurrentSnapshotExecutionException.class, () -> client().admin().cluster().prepareDeleteSnapshot(repoName, snapshotName).get());
        assertEquals(repoName, e.getRepositoryName());
        assertEquals(snapshotName, e.getSnapshotName());
        assertThat(e.getMessage(), containsString("cannot delete snapshot during a restore"));
        logger.info("-- try deleting another snapshot while the restore is in progress (should throw an error)");
        e = expectThrows(ConcurrentSnapshotExecutionException.class, () -> client().admin().cluster().prepareDeleteSnapshot(repoName, snapshotName2).get());
        assertEquals(repoName, e.getRepositoryName());
        assertEquals(snapshotName2, e.getSnapshotName());
        assertThat(e.getMessage(), containsString("cannot delete snapshot during a restore"));
    } finally {
        // unblock even if the try block fails otherwise we will get bogus failures when we delete all indices in test teardown.
        logger.info("--> unblocking all data nodes");
        unblockAllDataNodes(repoName);
    }
    logger.info("--> wait for restore to finish");
    restoreFut.get();
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) Client(org.elasticsearch.client.Client) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 5 with RestoreSnapshotResponse

use of org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse in project elasticsearch by elastic.

the class SharedClusterSnapshotRestoreIT method testFreshIndexUUID.

public void testFreshIndexUUID() {
    Client client = client();
    logger.info("-->  creating repository");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", randomRepoPath()).put("compress", randomBoolean()).put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
    createIndex("test");
    String originalIndexUUID = client().admin().indices().prepareGetSettings("test").get().getSetting("test", IndexMetaData.SETTING_INDEX_UUID);
    assertTrue(originalIndexUUID, originalIndexUUID != null);
    assertFalse(originalIndexUUID, originalIndexUUID.equals(IndexMetaData.INDEX_UUID_NA_VALUE));
    ensureGreen();
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test").get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
    NumShards numShards = getNumShards("test");
    cluster().wipeIndices("test");
    assertAcked(prepareCreate("test").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, numShards.numPrimaries)));
    ensureGreen();
    String newIndexUUID = client().admin().indices().prepareGetSettings("test").get().getSetting("test", IndexMetaData.SETTING_INDEX_UUID);
    assertTrue(newIndexUUID, newIndexUUID != null);
    assertFalse(newIndexUUID, newIndexUUID.equals(IndexMetaData.INDEX_UUID_NA_VALUE));
    assertFalse(newIndexUUID, newIndexUUID.equals(originalIndexUUID));
    logger.info("--> close index");
    client.admin().indices().prepareClose("test").get();
    logger.info("--> restore all indices from the snapshot");
    RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    ensureGreen();
    String newAfterRestoreIndexUUID = client().admin().indices().prepareGetSettings("test").get().getSetting("test", IndexMetaData.SETTING_INDEX_UUID);
    assertTrue("UUID has changed after restore: " + newIndexUUID + " vs. " + newAfterRestoreIndexUUID, newIndexUUID.equals(newAfterRestoreIndexUUID));
    logger.info("--> restore indices with different names");
    restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setRenamePattern("(.+)").setRenameReplacement("$1-copy").setWaitForCompletion(true).execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    String copyRestoreUUID = client().admin().indices().prepareGetSettings("test-copy").get().getSetting("test-copy", IndexMetaData.SETTING_INDEX_UUID);
    assertFalse("UUID has been reused on restore: " + copyRestoreUUID + " vs. " + originalIndexUUID, copyRestoreUUID.equals(originalIndexUUID));
}
Also used : CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Client(org.elasticsearch.client.Client) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Aggregations

RestoreSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)36 CreateSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)27 Client (org.elasticsearch.client.Client)27 Path (java.nio.file.Path)12 Matchers.containsString (org.hamcrest.Matchers.containsString)10 PutRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)8 ClusterState (org.elasticsearch.cluster.ClusterState)7 Settings (org.elasticsearch.common.settings.Settings)6 ClusterAdminClient (org.elasticsearch.client.ClusterAdminClient)5 ArrayList (java.util.ArrayList)4 GetSnapshotsResponse (org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse)4 SearchResponse (org.elasticsearch.action.search.SearchResponse)4 List (java.util.List)3 GetSettingsResponse (org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse)2 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)2 InvalidIndexNameException (org.elasticsearch.indices.InvalidIndexNameException)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)1 ImmutableList (com.google.common.collect.ImmutableList)1 FutureActionListener (io.crate.action.FutureActionListener)1