Search in sources :

Example 1 with RepositoriesService

use of org.elasticsearch.repositories.RepositoriesService in project elasticsearch by elastic.

the class BlobStoreRepositoryTests method setupRepo.

private BlobStoreRepository setupRepo() {
    final Client client = client();
    final Path location = ESIntegTestCase.randomRepoPath(node().settings());
    final String repositoryName = "test-repo";
    PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository(repositoryName).setType("fs").setSettings(Settings.builder().put(node().settings()).put("location", location)).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    final RepositoriesService repositoriesService = getInstanceFromNode(RepositoriesService.class);
    @SuppressWarnings("unchecked") final BlobStoreRepository repository = (BlobStoreRepository) repositoriesService.repository(repositoryName);
    return repository;
}
Also used : Path(java.nio.file.Path) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) Client(org.elasticsearch.client.Client)

Example 2 with RepositoriesService

use of org.elasticsearch.repositories.RepositoriesService 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 3 with RepositoriesService

use of org.elasticsearch.repositories.RepositoriesService in project elasticsearch by elastic.

the class SharedClusterSnapshotRestoreIT method testDeleteOrphanSnapshot.

public void testDeleteOrphanSnapshot() throws Exception {
    Client client = client();
    logger.info("-->  creating repository");
    final String repositoryName = "test-repo";
    assertAcked(client.admin().cluster().preparePutRepository(repositoryName).setType("mock").setSettings(Settings.builder().put("location", randomRepoPath()).put("compress", randomBoolean()).put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
    logger.info("--> create the index");
    final String idxName = "test-idx";
    createIndex(idxName);
    ensureGreen();
    ClusterService clusterService = internalCluster().getInstance(ClusterService.class, internalCluster().getMasterName());
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    logger.info("--> snapshot");
    final String snapshotName = "test-snap";
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot(repositoryName, snapshotName).setWaitForCompletion(true).setIndices(idxName).get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
    logger.info("--> emulate an orphan snapshot");
    RepositoriesService repositoriesService = internalCluster().getInstance(RepositoriesService.class, internalCluster().getMasterName());
    final RepositoryData repositoryData = repositoriesService.repository(repositoryName).getRepositoryData();
    final IndexId indexId = repositoryData.resolveIndexId(idxName);
    clusterService.submitStateUpdateTask("orphan snapshot test", new ClusterStateUpdateTask() {

        @Override
        public ClusterState execute(ClusterState currentState) {
            // Simulate orphan snapshot
            ImmutableOpenMap.Builder<ShardId, ShardSnapshotStatus> shards = ImmutableOpenMap.builder();
            shards.put(new ShardId(idxName, "_na_", 0), new ShardSnapshotStatus("unknown-node", State.ABORTED));
            shards.put(new ShardId(idxName, "_na_", 1), new ShardSnapshotStatus("unknown-node", State.ABORTED));
            shards.put(new ShardId(idxName, "_na_", 2), new ShardSnapshotStatus("unknown-node", State.ABORTED));
            List<Entry> entries = new ArrayList<>();
            entries.add(new Entry(new Snapshot(repositoryName, createSnapshotResponse.getSnapshotInfo().snapshotId()), true, false, State.ABORTED, Collections.singletonList(indexId), System.currentTimeMillis(), repositoryData.getGenId(), shards.build()));
            return ClusterState.builder(currentState).putCustom(SnapshotsInProgress.TYPE, new SnapshotsInProgress(Collections.unmodifiableList(entries))).build();
        }

        @Override
        public void onFailure(String source, Exception e) {
            fail();
        }

        @Override
        public void clusterStateProcessed(String source, ClusterState oldState, final ClusterState newState) {
            countDownLatch.countDown();
        }
    });
    countDownLatch.await();
    logger.info("--> try deleting the orphan snapshot");
    assertAcked(client.admin().cluster().prepareDeleteSnapshot(repositoryName, snapshotName).get("10s"));
}
Also used : IndexId(org.elasticsearch.repositories.IndexId) ClusterState(org.elasticsearch.cluster.ClusterState) XContentFactory.jsonBuilder(org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) ClusterStateUpdateTask(org.elasticsearch.cluster.ClusterStateUpdateTask) Matchers.containsString(org.hamcrest.Matchers.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) InvalidIndexNameException(org.elasticsearch.indices.InvalidIndexNameException) ExecutionException(java.util.concurrent.ExecutionException) RepositoryException(org.elasticsearch.repositories.RepositoryException) RepositoryData(org.elasticsearch.repositories.RepositoryData) ShardId(org.elasticsearch.index.shard.ShardId) Entry(org.elasticsearch.cluster.SnapshotsInProgress.Entry) ClusterService(org.elasticsearch.cluster.service.ClusterService) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) SnapshotsInProgress(org.elasticsearch.cluster.SnapshotsInProgress) ShardSnapshotStatus(org.elasticsearch.cluster.SnapshotsInProgress.ShardSnapshotStatus) ArrayList(java.util.ArrayList) List(java.util.List) Client(org.elasticsearch.client.Client)

Example 4 with RepositoriesService

use of org.elasticsearch.repositories.RepositoriesService 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 5 with RepositoriesService

use of org.elasticsearch.repositories.RepositoriesService 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)

Aggregations

RepositoriesService (org.elasticsearch.repositories.RepositoriesService)14 Client (org.elasticsearch.client.Client)5 CreateSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)4 RepositoryData (org.elasticsearch.repositories.RepositoryData)4 MockRepository (org.elasticsearch.snapshots.mockstore.MockRepository)4 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Settings (org.elasticsearch.common.settings.Settings)3 IndexId (org.elasticsearch.repositories.IndexId)3 ThreadPool (org.elasticsearch.threadpool.ThreadPool)3 IOException (java.io.IOException)2 Collections (java.util.Collections)2 Collectors (java.util.stream.Collectors)2 SetOnce (org.apache.lucene.util.SetOnce)2 PeerRecoveryTargetService (org.elasticsearch.indices.recovery.PeerRecoveryTargetService)2 Repository (org.elasticsearch.repositories.Repository)2 ObjectLongMap (com.carrotsearch.hppc.ObjectLongMap)1 Booleans (io.crate.common.Booleans)1