Search in sources :

Example 1 with MockRepository

use of org.opensearch.snapshots.mockstore.MockRepository in project OpenSearch by opensearch-project.

the class RepositoriesIT method testResidualStaleIndicesAreDeletedByConsecutiveDelete.

public void testResidualStaleIndicesAreDeletedByConsecutiveDelete() throws Exception {
    Client client = client();
    Path repositoryPath = randomRepoPath();
    final String repositoryName = "test-repo";
    final String snapshotToBeDeletedLastName = "test-snapshot-to-be-deleted-last";
    final String bulkSnapshotsPattern = "test-snap-*";
    logger.info("-->  creating repository at {}", repositoryPath.toAbsolutePath());
    createRepository(repositoryName, "mock", repositoryPath);
    int numberOfFiles = numberOfFiles(repositoryPath);
    logger.info("--> creating index-0 and ingest data");
    createIndex("test-idx-0");
    ensureGreen();
    for (int j = 0; j < 10; j++) {
        index("test-idx-0", "_doc", Integer.toString(10 + j), "foo", "bar" + 10 + j);
    }
    refresh();
    logger.info("--> creating first snapshot");
    createFullSnapshot(repositoryName, snapshotToBeDeletedLastName);
    // Create more snapshots to be deleted in bulk
    int maxThreadsForSnapshotDeletion = internalCluster().getMasterNodeInstance(ThreadPool.class).info(ThreadPool.Names.SNAPSHOT).getMax();
    for (int i = 1; i <= maxThreadsForSnapshotDeletion + 1; i++) {
        String snapshotName = "test-snap-" + i;
        String testIndexName = "test-idx-" + i;
        logger.info("--> creating index-" + i + " and ingest data");
        createIndex(testIndexName);
        ensureGreen();
        for (int j = 0; j < 10; j++) {
            index(testIndexName, "_doc", Integer.toString(10 + j), "foo", "bar" + 10 + j);
        }
        refresh();
        logger.info("--> creating snapshot: {}", snapshotName);
        createFullSnapshot(repositoryName, snapshotName);
    }
    // Make repository to throw exception when trying to delete stale indices
    // This will make sure stale indices stays in repository after snapshot delete
    String masterNode = internalCluster().getMasterName();
    ((MockRepository) internalCluster().getInstance(RepositoriesService.class, masterNode).repository("test-repo")).setThrowExceptionWhileDelete(true);
    logger.info("--> delete the bulk of the snapshots");
    client.admin().cluster().prepareDeleteSnapshot(repositoryName, bulkSnapshotsPattern).get();
    // Make repository to work normally
    ((MockRepository) internalCluster().getInstance(RepositoriesService.class, masterNode).repository("test-repo")).setThrowExceptionWhileDelete(false);
    // This snapshot should delete last snapshot's residual stale indices as well
    logger.info("--> delete first snapshot");
    client.admin().cluster().prepareDeleteSnapshot(repositoryName, snapshotToBeDeletedLastName).get();
    logger.info("--> make sure that number of files is back to what it was when the first snapshot was made");
    assertFileCount(repositoryPath, numberOfFiles + 2);
    logger.info("--> done");
}
Also used : Path(java.nio.file.Path) MockRepository(org.opensearch.snapshots.mockstore.MockRepository) Matchers.containsString(org.hamcrest.Matchers.containsString) Client(org.opensearch.client.Client)

Example 2 with MockRepository

use of org.opensearch.snapshots.mockstore.MockRepository in project OpenSearch by opensearch-project.

the class AbstractSnapshotIntegTestCase method waitForBlock.

public void waitForBlock(String node, String repository, TimeValue timeout) throws InterruptedException {
    logger.info("--> waiting for [{}] to be blocked on node [{}]", repository, node);
    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 waiting for node [" + node + "] to be blocked");
}
Also used : MockRepository(org.opensearch.snapshots.mockstore.MockRepository) RepositoriesService(org.opensearch.repositories.RepositoriesService)

Example 3 with MockRepository

use of org.opensearch.snapshots.mockstore.MockRepository in project OpenSearch by opensearch-project.

the class AbstractSnapshotIntegTestCase method waitForBlockOnAnyDataNode.

public static void waitForBlockOnAnyDataNode(String repository, TimeValue timeout) throws InterruptedException {
    final boolean blocked = waitUntil(() -> {
        for (RepositoriesService repositoriesService : internalCluster().getDataNodeInstances(RepositoriesService.class)) {
            MockRepository mockRepository = (MockRepository) repositoriesService.repository(repository);
            if (mockRepository.blocked()) {
                return true;
            }
        }
        return false;
    }, timeout.millis(), TimeUnit.MILLISECONDS);
    assertTrue("No repository is blocked waiting on a data node", blocked);
}
Also used : MockRepository(org.opensearch.snapshots.mockstore.MockRepository) RepositoriesService(org.opensearch.repositories.RepositoriesService)

Example 4 with MockRepository

use of org.opensearch.snapshots.mockstore.MockRepository in project OpenSearch by opensearch-project.

the class SharedClusterSnapshotRestoreIT method testIndexLatestFailuresIgnored.

public void testIndexLatestFailuresIgnored() throws Exception {
    final String repoName = "test-repo";
    final Path repoPath = randomRepoPath();
    createRepository(repoName, "mock", repoPath);
    final MockRepository repository = (MockRepository) internalCluster().getCurrentMasterNodeInstance(RepositoriesService.class).repository(repoName);
    repository.setFailOnIndexLatest(true);
    createFullSnapshot(repoName, "snapshot-1");
    repository.setFailOnIndexLatest(false);
    createFullSnapshot(repoName, "snapshot-2");
    final long repoGenInIndexLatest = Numbers.bytesToLong(new BytesRef(Files.readAllBytes(repoPath.resolve(BlobStoreRepository.INDEX_LATEST_BLOB))));
    assertEquals(getRepositoryData(repoName).getGenId(), repoGenInIndexLatest);
    createRepository(repoName, "fs", Settings.builder().put("location", repoPath).put(BlobStoreRepository.SUPPORT_URL_REPO.getKey(), false));
    createFullSnapshot(repoName, "snapshot-3");
    final long repoGenInIndexLatest2 = Numbers.bytesToLong(new BytesRef(Files.readAllBytes(repoPath.resolve(BlobStoreRepository.INDEX_LATEST_BLOB))));
    assertEquals("index.latest should not have been written to", repoGenInIndexLatest, repoGenInIndexLatest2);
    createRepository(repoName, "fs", repoPath);
    createFullSnapshot(repoName, "snapshot-4");
    final long repoGenInIndexLatest3 = Numbers.bytesToLong(new BytesRef(Files.readAllBytes(repoPath.resolve(BlobStoreRepository.INDEX_LATEST_BLOB))));
    assertEquals(getRepositoryData(repoName).getGenId(), repoGenInIndexLatest3);
}
Also used : Path(java.nio.file.Path) MockRepository(org.opensearch.snapshots.mockstore.MockRepository) Matchers.containsString(org.hamcrest.Matchers.containsString) BytesRef(org.apache.lucene.util.BytesRef)

Example 5 with MockRepository

use of org.opensearch.snapshots.mockstore.MockRepository in project OpenSearch by opensearch-project.

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.opensearch.snapshots.mockstore.MockRepository) RepositoriesService(org.opensearch.repositories.RepositoriesService)

Aggregations

MockRepository (org.opensearch.snapshots.mockstore.MockRepository)6 RepositoriesService (org.opensearch.repositories.RepositoriesService)4 Path (java.nio.file.Path)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 BytesRef (org.apache.lucene.util.BytesRef)1 Client (org.opensearch.client.Client)1