Search in sources :

Example 6 with DeleteSnapshotResponse

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

the class MinThreadsSnapshotRestoreIT method testSnapshottingWithInProgressDeletionNotAllowed.

public void testSnapshottingWithInProgressDeletionNotAllowed() 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();
    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, snapshot1).execute();
    logger.info("--> waiting for block to kick in on node [{}]", blockedNode);
    waitForBlock(blockedNode, repo, TimeValue.timeValueSeconds(10));
    logger.info("--> try creating a second snapshot, should fail because the deletion is in progress");
    final String snapshot2 = "test-snap2";
    try {
        client().admin().cluster().prepareCreateSnapshot(repo, snapshot2).setWaitForCompletion(true).get();
        fail("should not be able to create a snapshot while another is being deleted");
    } catch (ConcurrentSnapshotExecutionException e) {
        assertThat(e.getMessage(), containsString("cannot 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("--> creating second snapshot, which should now work");
    client().admin().cluster().prepareCreateSnapshot(repo, snapshot2).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 7 with DeleteSnapshotResponse

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

the class DedicatedClusterSnapshotRestoreIT method testSnapshotWithStuckNode.

public void testSnapshotWithStuckNode() throws Exception {
    logger.info("--> start 2 nodes");
    ArrayList<String> nodes = new ArrayList<>();
    nodes.add(internalCluster().startNode());
    nodes.add(internalCluster().startNode());
    Client client = client();
    assertAcked(prepareCreate("test-idx", 2, Settings.builder().put("number_of_shards", 2).put("number_of_replicas", 0)));
    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("--> creating repository");
    Path repo = randomRepoPath();
    PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo").setType("mock").setSettings(Settings.builder().put("location", repo).put("random", randomAsciiOfLength(10)).put("wait_after_unblock", 200)).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    // Pick one node and block it
    String blockedNode = blockNodeWithIndex("test-repo", "test-idx");
    // Remove it from the list of available nodes
    nodes.remove(blockedNode);
    int numberOfFilesBeforeSnapshot = numberOfFiles(repo);
    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 [{}], aborting snapshot", blockedNode);
    ListenableActionFuture<DeleteSnapshotResponse> deleteSnapshotResponseFuture = internalCluster().client(nodes.get(0)).admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap").execute();
    // Make sure that abort makes some progress
    Thread.sleep(100);
    unblockNode("test-repo", blockedNode);
    logger.info("--> stopping node [{}]", blockedNode);
    stopNode(blockedNode);
    try {
        DeleteSnapshotResponse deleteSnapshotResponse = deleteSnapshotResponseFuture.actionGet();
        assertThat(deleteSnapshotResponse.isAcknowledged(), equalTo(true));
    } catch (SnapshotMissingException ex) {
    // When master node is closed during this test, it sometime manages to delete the snapshot files before
    // completely stopping. In this case the retried delete snapshot operation on the new master can fail
    // with SnapshotMissingException
    }
    logger.info("--> making sure that snapshot no longer exists");
    assertThrows(client().admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").execute(), SnapshotMissingException.class);
    // Subtract three files that will remain in the repository:
    //   (1) index-1
    //   (2) index-0 (because we keep the previous version) and
    //   (3) index-latest
    assertThat("not all files were deleted during snapshot cancellation", numberOfFilesBeforeSnapshot, equalTo(numberOfFiles(repo) - 3));
    logger.info("--> done");
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) NodeClient(org.elasticsearch.client.node.NodeClient) Client(org.elasticsearch.client.Client) 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