Search in sources :

Example 6 with RestoreSnapshotResponse

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

the class SharedClusterSnapshotRestoreIT method testSnapshotWithMissingShardLevelIndexFile.

public void testSnapshotWithMissingShardLevelIndexFile() throws Exception {
    Path repo = randomRepoPath();
    logger.info("-->  creating repository at {}", repo.toAbsolutePath());
    assertAcked(client().admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", repo).put("compress", false)));
    createIndex("test-idx-1", "test-idx-2");
    logger.info("--> indexing some data");
    indexRandom(true, client().prepareIndex("test-idx-1", "doc").setSource("foo", "bar"), client().prepareIndex("test-idx-2", "doc").setSource("foo", "bar"));
    logger.info("--> creating snapshot");
    client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-1").setWaitForCompletion(true).setIndices("test-idx-*").get();
    logger.info("--> deleting shard level index file");
    try (Stream<Path> files = Files.list(repo.resolve("indices"))) {
        files.forEach(indexPath -> IOUtils.deleteFilesIgnoringExceptions(indexPath.resolve("0").resolve("index-0")));
    }
    logger.info("--> creating another snapshot");
    CreateSnapshotResponse createSnapshotResponse = client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-2").setWaitForCompletion(true).setIndices("test-idx-1").get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertEquals(createSnapshotResponse.getSnapshotInfo().successfulShards(), createSnapshotResponse.getSnapshotInfo().totalShards());
    logger.info("--> restoring the first snapshot, the repository should not have lost any shard data despite deleting index-N, " + "because it should have iterated over the snap-*.data files as backup");
    client().admin().indices().prepareDelete("test-idx-1", "test-idx-2").get();
    RestoreSnapshotResponse restoreSnapshotResponse = client().admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap-1").setWaitForCompletion(true).get();
    assertEquals(0, restoreSnapshotResponse.getRestoreInfo().failedShards());
}
Also used : Path(java.nio.file.Path) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 7 with RestoreSnapshotResponse

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

the class SharedClusterSnapshotRestoreIT method testRestoreAliases.

public void testRestoreAliases() throws Exception {
    Client client = client();
    logger.info("-->  creating repository");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", randomRepoPath())));
    logger.info("--> create test indices");
    createIndex("test-idx-1", "test-idx-2", "test-idx-3");
    ensureGreen();
    logger.info("--> create aliases");
    assertAcked(client.admin().indices().prepareAliases().addAlias("test-idx-1", "alias-123").addAlias("test-idx-2", "alias-123").addAlias("test-idx-3", "alias-123").addAlias("test-idx-1", "alias-1").get());
    assertAliasesExist(client.admin().indices().prepareAliasesExist("alias-123").get());
    logger.info("--> snapshot");
    assertThat(client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setIndices().setWaitForCompletion(true).get().getSnapshotInfo().state(), equalTo(SnapshotState.SUCCESS));
    logger.info("-->  delete all indices");
    cluster().wipeIndices("test-idx-1", "test-idx-2", "test-idx-3");
    assertAliasesMissing(client.admin().indices().prepareAliasesExist("alias-123", "alias-1").get());
    logger.info("--> restore snapshot with aliases");
    RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setRestoreGlobalState(true).execute().actionGet();
    // We don't restore any indices here
    assertThat(restoreSnapshotResponse.getRestoreInfo().successfulShards(), allOf(greaterThan(0), equalTo(restoreSnapshotResponse.getRestoreInfo().totalShards())));
    logger.info("--> check that aliases are restored");
    assertAliasesExist(client.admin().indices().prepareAliasesExist("alias-123", "alias-1").get());
    logger.info("-->  update aliases");
    assertAcked(client.admin().indices().prepareAliases().removeAlias("test-idx-3", "alias-123"));
    assertAcked(client.admin().indices().prepareAliases().addAlias("test-idx-3", "alias-3"));
    logger.info("-->  delete and close indices");
    cluster().wipeIndices("test-idx-1", "test-idx-2");
    assertAcked(client.admin().indices().prepareClose("test-idx-3"));
    assertAliasesMissing(client.admin().indices().prepareAliasesExist("alias-123", "alias-1").get());
    logger.info("--> restore snapshot without aliases");
    restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setRestoreGlobalState(true).setIncludeAliases(false).execute().actionGet();
    // We don't restore any indices here
    assertThat(restoreSnapshotResponse.getRestoreInfo().successfulShards(), allOf(greaterThan(0), equalTo(restoreSnapshotResponse.getRestoreInfo().totalShards())));
    logger.info("--> check that aliases are not restored and existing aliases still exist");
    assertAliasesMissing(client.admin().indices().prepareAliasesExist("alias-123", "alias-1").get());
    assertAliasesExist(client.admin().indices().prepareAliasesExist("alias-3").get());
}
Also used : Client(org.elasticsearch.client.Client) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 8 with RestoreSnapshotResponse

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

the class SharedClusterSnapshotRestoreIT method testReadonlyRepository.

// this fails every now and then: https://github.com/elastic/elasticsearch/issues/18121 but without
@TestLogging("_root:DEBUG")
public // more logs we cannot find out why
void testReadonlyRepository() throws Exception {
    Client client = client();
    logger.info("-->  creating repository");
    Path repositoryLocation = randomRepoPath();
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", repositoryLocation).put("compress", randomBoolean()).put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
    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();
    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()));
    assertThat(client.admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS));
    logger.info("--> delete index");
    cluster().wipeIndices("test-idx");
    logger.info("--> create read-only URL repository");
    assertAcked(client.admin().cluster().preparePutRepository("readonly-repo").setType("fs").setSettings(Settings.builder().put("location", repositoryLocation).put("compress", randomBoolean()).put("readonly", true).put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
    logger.info("--> restore index after deletion");
    RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("readonly-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
    logger.info("--> list available shapshots");
    GetSnapshotsResponse getSnapshotsResponse = client.admin().cluster().prepareGetSnapshots("readonly-repo").get();
    assertThat(getSnapshotsResponse.getSnapshots(), notNullValue());
    assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(1));
    logger.info("--> try deleting snapshot");
    assertThrows(client.admin().cluster().prepareDeleteSnapshot("readonly-repo", "test-snap"), RepositoryException.class, "cannot delete snapshot from a readonly repository");
    logger.info("--> try making another snapshot");
    assertThrows(client.admin().cluster().prepareCreateSnapshot("readonly-repo", "test-snap-2").setWaitForCompletion(true).setIndices("test-idx"), RepositoryException.class, "cannot create snapshot in a readonly repository");
}
Also used : Path(java.nio.file.Path) GetSnapshotsResponse(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) Client(org.elasticsearch.client.Client) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse) TestLogging(org.elasticsearch.test.junit.annotations.TestLogging)

Example 9 with RestoreSnapshotResponse

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

the class SharedClusterSnapshotRestoreIT method testRecreateBlocksOnRestore.

public void testRecreateBlocksOnRestore() 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)));
    Settings.Builder indexSettings = Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_REPLICAS, between(0, 1)).put(INDEX_REFRESH_INTERVAL_SETTING.getKey(), "10s");
    logger.info("--> create index");
    assertAcked(prepareCreate("test-idx", 2, indexSettings));
    try {
        List<String> initialBlockSettings = randomSubsetOf(randomInt(3), IndexMetaData.SETTING_BLOCKS_WRITE, IndexMetaData.SETTING_BLOCKS_METADATA, IndexMetaData.SETTING_READ_ONLY);
        Settings.Builder initialSettingsBuilder = Settings.builder();
        for (String blockSetting : initialBlockSettings) {
            initialSettingsBuilder.put(blockSetting, true);
        }
        Settings initialSettings = initialSettingsBuilder.build();
        logger.info("--> using initial block settings {}", initialSettings.getAsMap());
        if (!initialSettings.isEmpty()) {
            logger.info("--> apply initial blocks to index");
            client().admin().indices().prepareUpdateSettings("test-idx").setSettings(initialSettingsBuilder).get();
        }
        logger.info("--> snapshot index");
        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("--> remove blocks and delete index");
        disableIndexBlock("test-idx", IndexMetaData.SETTING_BLOCKS_METADATA);
        disableIndexBlock("test-idx", IndexMetaData.SETTING_READ_ONLY);
        disableIndexBlock("test-idx", IndexMetaData.SETTING_BLOCKS_WRITE);
        disableIndexBlock("test-idx", IndexMetaData.SETTING_BLOCKS_READ);
        cluster().wipeIndices("test-idx");
        logger.info("--> restore index with additional block changes");
        List<String> changeBlockSettings = randomSubsetOf(randomInt(4), IndexMetaData.SETTING_BLOCKS_METADATA, IndexMetaData.SETTING_BLOCKS_WRITE, IndexMetaData.SETTING_READ_ONLY, IndexMetaData.SETTING_BLOCKS_READ);
        Settings.Builder changedSettingsBuilder = Settings.builder();
        for (String blockSetting : changeBlockSettings) {
            changedSettingsBuilder.put(blockSetting, randomBoolean());
        }
        Settings changedSettings = changedSettingsBuilder.build();
        logger.info("--> applying changed block settings {}", changedSettings.getAsMap());
        RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setIndexSettings(changedSettings).setWaitForCompletion(true).execute().actionGet();
        assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
        ClusterBlocks blocks = client.admin().cluster().prepareState().clear().setBlocks(true).get().getState().blocks();
        // compute current index settings (as we cannot query them if they contain SETTING_BLOCKS_METADATA)
        Settings mergedSettings = Settings.builder().put(initialSettings).put(changedSettings).build();
        logger.info("--> merged block settings {}", mergedSettings.getAsMap());
        logger.info("--> checking consistency between settings and blocks");
        assertThat(mergedSettings.getAsBoolean(IndexMetaData.SETTING_BLOCKS_METADATA, false), is(blocks.hasIndexBlock("test-idx", IndexMetaData.INDEX_METADATA_BLOCK)));
        assertThat(mergedSettings.getAsBoolean(IndexMetaData.SETTING_BLOCKS_READ, false), is(blocks.hasIndexBlock("test-idx", IndexMetaData.INDEX_READ_BLOCK)));
        assertThat(mergedSettings.getAsBoolean(IndexMetaData.SETTING_BLOCKS_WRITE, false), is(blocks.hasIndexBlock("test-idx", IndexMetaData.INDEX_WRITE_BLOCK)));
        assertThat(mergedSettings.getAsBoolean(IndexMetaData.SETTING_READ_ONLY, false), is(blocks.hasIndexBlock("test-idx", IndexMetaData.INDEX_READ_ONLY_BLOCK)));
    } finally {
        logger.info("--> cleaning up blocks");
        disableIndexBlock("test-idx", IndexMetaData.SETTING_BLOCKS_METADATA);
        disableIndexBlock("test-idx", IndexMetaData.SETTING_READ_ONLY);
        disableIndexBlock("test-idx", IndexMetaData.SETTING_BLOCKS_WRITE);
        disableIndexBlock("test-idx", IndexMetaData.SETTING_BLOCKS_READ);
    }
}
Also used : CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) Matchers.containsString(org.hamcrest.Matchers.containsString) Client(org.elasticsearch.client.Client) Settings(org.elasticsearch.common.settings.Settings) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 10 with RestoreSnapshotResponse

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

the class SharedClusterSnapshotRestoreIT method testDataFileCorruptionDuringRestore.

public void testDataFileCorruptionDuringRestore() throws Exception {
    Path repositoryLocation = randomRepoPath();
    Client client = client();
    logger.info("-->  creating repository");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", repositoryLocation)));
    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().state(), equalTo(SnapshotState.SUCCESS));
    assertThat(createSnapshotResponse.getSnapshotInfo().totalShards(), equalTo(createSnapshotResponse.getSnapshotInfo().successfulShards()));
    logger.info("-->  update repository with mock version");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("mock").setSettings(Settings.builder().put("location", repositoryLocation).put("random", randomAsciiOfLength(10)).put("use_lucene_corruption", true).put("max_failure_number", 10000000L).put("random_data_file_io_exception_rate", 1.0)));
    // Test restore after index deletion
    logger.info("--> delete index");
    cluster().wipeIndices("test-idx");
    logger.info("--> restore corrupt index");
    RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), equalTo(restoreSnapshotResponse.getRestoreInfo().totalShards()));
}
Also used : Path(java.nio.file.Path) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) 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