Search in sources :

Example 1 with MockRepository

use of org.elasticsearch.snapshots.mockstore.MockRepository in project elasticsearch by elastic.

the class AbstractSnapshotIntegTestCase method getFailureCount.

public static long getFailureCount(String repository) {
    long failureCount = 0;
    for (RepositoriesService repositoriesService : internalCluster().getDataOrMasterNodeInstances(RepositoriesService.class)) {
        MockRepository mockRepository = (MockRepository) repositoriesService.repository(repository);
        failureCount += mockRepository.getFailureCount();
    }
    return failureCount;
}
Also used : MockRepository(org.elasticsearch.snapshots.mockstore.MockRepository) RepositoriesService(org.elasticsearch.repositories.RepositoriesService)

Example 2 with MockRepository

use of org.elasticsearch.snapshots.mockstore.MockRepository in project elasticsearch by elastic.

the class AbstractSnapshotIntegTestCase method waitForBlock.

public void waitForBlock(String node, String repository, TimeValue timeout) throws InterruptedException {
    long start = System.currentTimeMillis();
    RepositoriesService repositoriesService = internalCluster().getInstance(RepositoriesService.class, node);
    MockRepository mockRepository = (MockRepository) repositoriesService.repository(repository);
    while (System.currentTimeMillis() - start < timeout.millis()) {
        if (mockRepository.blocked()) {
            return;
        }
        Thread.sleep(100);
    }
    fail("Timeout!!!");
}
Also used : MockRepository(org.elasticsearch.snapshots.mockstore.MockRepository) RepositoriesService(org.elasticsearch.repositories.RepositoriesService)

Example 3 with MockRepository

use of org.elasticsearch.snapshots.mockstore.MockRepository 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 4 with MockRepository

use of org.elasticsearch.snapshots.mockstore.MockRepository 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)

Example 5 with MockRepository

use of org.elasticsearch.snapshots.mockstore.MockRepository 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)

Aggregations

MockRepository (org.elasticsearch.snapshots.mockstore.MockRepository)5 DeleteSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 RepositoriesService (org.elasticsearch.repositories.RepositoriesService)2