Search in sources :

Example 1 with DeleteSnapshotResponse

use of org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse in project crate by crate.

the class SnapshotRestoreDDLDispatcher method dispatch.

public CompletableFuture<Long> dispatch(final DropSnapshotAnalyzedStatement statement) {
    final CompletableFuture<Long> future = new CompletableFuture<>();
    final String repositoryName = statement.repository();
    final String snapshotName = statement.snapshot();
    transportActionProvider.transportDeleteSnapshotAction().execute(new DeleteSnapshotRequest(repositoryName, snapshotName), new ActionListener<DeleteSnapshotResponse>() {

        @Override
        public void onResponse(DeleteSnapshotResponse response) {
            if (!response.isAcknowledged()) {
                LOGGER.info("delete snapshot '{}.{}' not acknowledged", repositoryName, snapshotName);
            }
            future.complete(1L);
        }

        @Override
        public void onFailure(Throwable e) {
            future.completeExceptionally(e);
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) DeleteSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest) DeleteSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse)

Example 2 with DeleteSnapshotResponse

use of org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse in project elasticsearch by elastic.

the class MinThreadsSnapshotRestoreIT method testRestoreWithInProgressDeletionsNotAllowed.

public void testRestoreWithInProgressDeletionsNotAllowed() throws Exception {
    logger.info("--> creating repository");
    final String repo = "test-repo";
    assertAcked(client().admin().cluster().preparePutRepository(repo).setType("mock").setSettings(Settings.builder().put("location", randomRepoPath()).put("random", randomAsciiOfLength(10)).put("wait_after_unblock", 200)).get());
    logger.info("--> snapshot");
    final String index = "test-idx";
    assertAcked(prepareCreate(index, 1, Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0)));
    for (int i = 0; i < 10; i++) {
        index(index, "doc", Integer.toString(i), "foo", "bar" + i);
    }
    refresh();
    final String snapshot1 = "test-snap1";
    client().admin().cluster().prepareCreateSnapshot(repo, snapshot1).setWaitForCompletion(true).get();
    final String index2 = "test-idx2";
    assertAcked(prepareCreate(index2, 1, Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0)));
    for (int i = 0; i < 10; i++) {
        index(index2, "doc", Integer.toString(i), "foo", "bar" + i);
    }
    refresh();
    final String snapshot2 = "test-snap2";
    client().admin().cluster().prepareCreateSnapshot(repo, snapshot2).setWaitForCompletion(true).get();
    client().admin().indices().prepareClose(index, index2).get();
    String blockedNode = internalCluster().getMasterName();
    ((MockRepository) internalCluster().getInstance(RepositoriesService.class, blockedNode).repository(repo)).blockOnDataFiles(true);
    logger.info("--> start deletion of snapshot");
    ListenableActionFuture<DeleteSnapshotResponse> future = client().admin().cluster().prepareDeleteSnapshot(repo, snapshot2).execute();
    logger.info("--> waiting for block to kick in on node [{}]", blockedNode);
    waitForBlock(blockedNode, repo, TimeValue.timeValueSeconds(10));
    logger.info("--> try restoring the other snapshot, should fail because the deletion is in progress");
    try {
        client().admin().cluster().prepareRestoreSnapshot(repo, snapshot1).setWaitForCompletion(true).get();
        fail("should not be able to restore a snapshot while another is being deleted");
    } catch (ConcurrentSnapshotExecutionException e) {
        assertThat(e.getMessage(), containsString("cannot restore a snapshot while a snapshot deletion is in-progress"));
    }
    logger.info("--> unblocking blocked node [{}]", blockedNode);
    unblockNode(repo, blockedNode);
    logger.info("--> wait until snapshot deletion is finished");
    assertAcked(future.actionGet());
    logger.info("--> restoring snapshot, which should now work");
    client().admin().cluster().prepareRestoreSnapshot(repo, snapshot1).setWaitForCompletion(true).get();
    assertEquals(1, client().admin().cluster().prepareGetSnapshots(repo).setSnapshots("_all").get().getSnapshots().size());
}
Also used : MockRepository(org.elasticsearch.snapshots.mockstore.MockRepository) Matchers.containsString(org.hamcrest.Matchers.containsString) DeleteSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse)

Example 3 with DeleteSnapshotResponse

use of org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse in project elasticsearch by elastic.

the class URLSnapshotRestoreTests method testUrlRepository.

public void testUrlRepository() throws Exception {
    Client client = client();
    logger.info("-->  creating repository");
    Path repositoryLocation = randomRepoPath();
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType(FsRepository.TYPE).setSettings(Settings.builder().put(FsRepository.LOCATION_SETTING.getKey(), repositoryLocation).put(FsRepository.COMPRESS_SETTING.getKey(), randomBoolean()).put(FsRepository.CHUNK_SIZE_SETTING.getKey(), 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();
    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));
    int actualTotalShards = createSnapshotResponse.getSnapshotInfo().totalShards();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(actualTotalShards));
    SnapshotState state = client.admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").get().getSnapshots().get(0).state();
    assertThat(state, equalTo(SnapshotState.SUCCESS));
    logger.info("--> delete index");
    cluster().wipeIndices("test-idx");
    logger.info("--> create read-only URL repository");
    assertAcked(client.admin().cluster().preparePutRepository("url-repo").setType(URLRepository.TYPE).setSettings(Settings.builder().put(URLRepository.URL_SETTING.getKey(), repositoryLocation.toUri().toURL()).put("list_directories", randomBoolean())));
    logger.info("--> restore index after deletion");
    RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("url-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("url-repo").get();
    assertThat(getSnapshotsResponse.getSnapshots(), notNullValue());
    assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(1));
    logger.info("--> delete snapshot");
    DeleteSnapshotResponse deleteSnapshotResponse = client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap").get();
    assertAcked(deleteSnapshotResponse);
    logger.info("--> list available shapshot again, no snapshots should be returned");
    getSnapshotsResponse = client.admin().cluster().prepareGetSnapshots("url-repo").get();
    assertThat(getSnapshotsResponse.getSnapshots(), notNullValue());
    assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(0));
}
Also used : Path(java.nio.file.Path) SnapshotState(org.elasticsearch.snapshots.SnapshotState) GetSnapshotsResponse(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) Client(org.elasticsearch.client.Client) DeleteSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 4 with DeleteSnapshotResponse

use of org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse in project crate by crate.

the class SysSnapshotsTest method deleteSnapshot.

private void deleteSnapshot(String name) {
    DeleteSnapshotResponse deleteSnapshotResponse = client().admin().cluster().prepareDeleteSnapshot(REPOSITORY_NAME, name).get();
    assertThat(deleteSnapshotResponse.isAcknowledged(), equalTo(true));
}
Also used : DeleteSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse)

Example 5 with DeleteSnapshotResponse

use of org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse in project elasticsearch by elastic.

the class MinThreadsSnapshotRestoreIT method testConcurrentSnapshotDeletionsNotAllowed.

public void testConcurrentSnapshotDeletionsNotAllowed() throws Exception {
    logger.info("--> creating repository");
    final String repo = "test-repo";
    assertAcked(client().admin().cluster().preparePutRepository(repo).setType("mock").setSettings(Settings.builder().put("location", randomRepoPath()).put("random", randomAsciiOfLength(10)).put("wait_after_unblock", 200)).get());
    logger.info("--> snapshot twice");
    final String index = "test-idx1";
    assertAcked(prepareCreate(index, 1, Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0)));
    for (int i = 0; i < 10; i++) {
        index(index, "doc", Integer.toString(i), "foo", "bar" + i);
    }
    refresh();
    final String snapshot1 = "test-snap1";
    client().admin().cluster().prepareCreateSnapshot(repo, snapshot1).setWaitForCompletion(true).get();
    final String index2 = "test-idx2";
    assertAcked(prepareCreate(index2, 1, Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0)));
    for (int i = 0; i < 10; i++) {
        index(index2, "doc", Integer.toString(i), "foo", "bar" + i);
    }
    refresh();
    final String snapshot2 = "test-snap2";
    client().admin().cluster().prepareCreateSnapshot(repo, snapshot2).setWaitForCompletion(true).get();
    String blockedNode = internalCluster().getMasterName();
    ((MockRepository) internalCluster().getInstance(RepositoriesService.class, blockedNode).repository(repo)).blockOnDataFiles(true);
    logger.info("--> start deletion of first snapshot");
    ListenableActionFuture<DeleteSnapshotResponse> future = client().admin().cluster().prepareDeleteSnapshot(repo, snapshot2).execute();
    logger.info("--> waiting for block to kick in on node [{}]", blockedNode);
    waitForBlock(blockedNode, repo, TimeValue.timeValueSeconds(10));
    logger.info("--> try deleting the second snapshot, should fail because the first deletion is in progress");
    try {
        client().admin().cluster().prepareDeleteSnapshot(repo, snapshot1).get();
        fail("should not be able to delete snapshots concurrently");
    } catch (ConcurrentSnapshotExecutionException e) {
        assertThat(e.getMessage(), containsString("cannot delete - another snapshot is currently being deleted"));
    }
    logger.info("--> unblocking blocked node [{}]", blockedNode);
    unblockNode(repo, blockedNode);
    logger.info("--> wait until first snapshot is finished");
    assertAcked(future.actionGet());
    logger.info("--> delete second snapshot, which should now work");
    client().admin().cluster().prepareDeleteSnapshot(repo, snapshot1).get();
    assertTrue(client().admin().cluster().prepareGetSnapshots(repo).setSnapshots("_all").get().getSnapshots().isEmpty());
}
Also used : MockRepository(org.elasticsearch.snapshots.mockstore.MockRepository) Matchers.containsString(org.hamcrest.Matchers.containsString) DeleteSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse)

Aggregations

DeleteSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse)7 Matchers.containsString (org.hamcrest.Matchers.containsString)4 MockRepository (org.elasticsearch.snapshots.mockstore.MockRepository)3 Path (java.nio.file.Path)2 Client (org.elasticsearch.client.Client)2 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 PutRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)1 CreateSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)1 DeleteSnapshotRequest (org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest)1 GetSnapshotsResponse (org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse)1 RestoreSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 SnapshotState (org.elasticsearch.snapshots.SnapshotState)1