Search in sources :

Example 1 with BlobStoreRepository

use of org.elasticsearch.repositories.blobstore.BlobStoreRepository in project crate by crate.

the class MockEventuallyConsistentRepositoryTests method testOverwriteShardSnapBlobFails.

public void testOverwriteShardSnapBlobFails() throws IOException {
    MockEventuallyConsistentRepository.Context blobStoreContext = new MockEventuallyConsistentRepository.Context();
    try (BlobStoreRepository repository = new MockEventuallyConsistentRepository(new RepositoryMetadata("testRepo", "mockEventuallyConsistent", Settings.EMPTY), xContentRegistry(), BlobStoreTestUtil.mockClusterService(), blobStoreContext, random())) {
        repository.start();
        final BlobContainer container = repository.blobStore().blobContainer(repository.basePath().add("indices").add("someindex").add("0"));
        final String blobName = BlobStoreRepository.SNAPSHOT_PREFIX + UUIDs.randomBase64UUID();
        final int lengthWritten = randomIntBetween(1, 100);
        final byte[] blobData = randomByteArrayOfLength(lengthWritten);
        container.writeBlob(blobName, new ByteArrayInputStream(blobData), lengthWritten, false);
        final AssertionError assertionError = expectThrows(AssertionError.class, () -> container.writeBlob(blobName, new ByteArrayInputStream(blobData), lengthWritten, false));
        assertThat(assertionError.getMessage(), equalTo("Shard level snap-{uuid} blobs should never be overwritten"));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BlobStoreRepository(org.elasticsearch.repositories.blobstore.BlobStoreRepository) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) BlobContainer(org.elasticsearch.common.blobstore.BlobContainer)

Example 2 with BlobStoreRepository

use of org.elasticsearch.repositories.blobstore.BlobStoreRepository in project crate by crate.

the class MockEventuallyConsistentRepositoryTests method testOverwriteSnapshotInfoBlob.

public void testOverwriteSnapshotInfoBlob() {
    MockEventuallyConsistentRepository.Context blobStoreContext = new MockEventuallyConsistentRepository.Context();
    final RepositoryMetadata metaData = new RepositoryMetadata("testRepo", "mockEventuallyConsistent", Settings.EMPTY);
    final ClusterService clusterService = BlobStoreTestUtil.mockClusterService(metaData);
    try (BlobStoreRepository repository = new MockEventuallyConsistentRepository(metaData, xContentRegistry(), clusterService, blobStoreContext, random())) {
        clusterService.addStateApplier(event -> repository.updateState(event.state()));
        // Apply state once to initialize repo properly like RepositoriesService would
        repository.updateState(clusterService.state());
        repository.start();
        // We create a snap- blob for snapshot "foo" in the first generation
        final PlainActionFuture<SnapshotInfo> future = PlainActionFuture.newFuture();
        final SnapshotId snapshotId = new SnapshotId("foo", UUIDs.randomBase64UUID());
        // We try to write another snap- blob for "foo" in the next generation. It fails because the content differs.
        repository.finalizeSnapshot(snapshotId, ShardGenerations.EMPTY, 1L, null, 5, Collections.emptyList(), -1L, false, Metadata.EMPTY_METADATA, true, future);
        future.actionGet();
        // We try to write another snap- blob for "foo" in the next generation. It fails because the content differs.
        final AssertionError assertionError = expectThrows(AssertionError.class, () -> {
            final PlainActionFuture<SnapshotInfo> fut = PlainActionFuture.newFuture();
            repository.finalizeSnapshot(snapshotId, ShardGenerations.EMPTY, 1L, null, 6, Collections.emptyList(), 0, false, Metadata.EMPTY_METADATA, true, fut);
            fut.actionGet();
        });
        assertThat(assertionError.getMessage(), equalTo("\nExpected: <6>\n     but: was <5>"));
        // We try to write yet another snap- blob for "foo" in the next generation.
        // It passes cleanly because the content of the blob except for the timestamps.
        final PlainActionFuture<SnapshotInfo> future2 = PlainActionFuture.newFuture();
        repository.finalizeSnapshot(snapshotId, ShardGenerations.EMPTY, 1L, null, 5, Collections.emptyList(), 0, false, Metadata.EMPTY_METADATA, true, future2);
        future2.actionGet();
    }
}
Also used : SnapshotId(org.elasticsearch.snapshots.SnapshotId) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) ClusterService(org.elasticsearch.cluster.service.ClusterService) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) BlobStoreRepository(org.elasticsearch.repositories.blobstore.BlobStoreRepository)

Example 3 with BlobStoreRepository

use of org.elasticsearch.repositories.blobstore.BlobStoreRepository in project crate by crate.

the class MockEventuallyConsistentRepositoryTests method testOverwriteRandomBlobFails.

public void testOverwriteRandomBlobFails() throws IOException {
    MockEventuallyConsistentRepository.Context blobStoreContext = new MockEventuallyConsistentRepository.Context();
    try (BlobStoreRepository repository = new MockEventuallyConsistentRepository(new RepositoryMetadata("testRepo", "mockEventuallyConsistent", Settings.EMPTY), xContentRegistry(), BlobStoreTestUtil.mockClusterService(), blobStoreContext, random())) {
        repository.start();
        final BlobContainer container = repository.blobStore().blobContainer(repository.basePath());
        final String blobName = randomAlphaOfLength(10);
        final int lengthWritten = randomIntBetween(1, 100);
        final byte[] blobData = randomByteArrayOfLength(lengthWritten);
        container.writeBlob(blobName, new ByteArrayInputStream(blobData), lengthWritten, false);
        final AssertionError assertionError = expectThrows(AssertionError.class, () -> container.writeBlob(blobName, new ByteArrayInputStream(blobData), lengthWritten - 1, false));
        assertThat(assertionError.getMessage(), startsWith("Tried to overwrite blob [" + blobName + "]"));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BlobStoreRepository(org.elasticsearch.repositories.blobstore.BlobStoreRepository) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) BlobContainer(org.elasticsearch.common.blobstore.BlobContainer)

Example 4 with BlobStoreRepository

use of org.elasticsearch.repositories.blobstore.BlobStoreRepository in project crate by crate.

the class MockEventuallyConsistentRepositoryTests method testReadAfterWriteAfterReadThrows.

public void testReadAfterWriteAfterReadThrows() throws IOException {
    MockEventuallyConsistentRepository.Context blobStoreContext = new MockEventuallyConsistentRepository.Context();
    try (BlobStoreRepository repository = new MockEventuallyConsistentRepository(new RepositoryMetadata("testRepo", "mockEventuallyConsistent", Settings.EMPTY), xContentRegistry(), BlobStoreTestUtil.mockClusterService(), blobStoreContext, random())) {
        repository.start();
        final BlobContainer blobContainer = repository.blobStore().blobContainer(repository.basePath());
        final String blobName = randomAlphaOfLength(10);
        final int lengthWritten = randomIntBetween(1, 100);
        final byte[] blobData = randomByteArrayOfLength(lengthWritten);
        expectThrows(NoSuchFileException.class, () -> blobContainer.readBlob(blobName));
        blobContainer.writeBlob(blobName, new ByteArrayInputStream(blobData), lengthWritten, true);
        assertThrowsOnInconsistentRead(blobContainer, blobName);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BlobStoreRepository(org.elasticsearch.repositories.blobstore.BlobStoreRepository) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) BlobContainer(org.elasticsearch.common.blobstore.BlobContainer)

Example 5 with BlobStoreRepository

use of org.elasticsearch.repositories.blobstore.BlobStoreRepository in project crate by crate.

the class MockEventuallyConsistentRepositoryTests method testReadAfterDeleteAfterWriteThrows.

public void testReadAfterDeleteAfterWriteThrows() throws IOException {
    MockEventuallyConsistentRepository.Context blobStoreContext = new MockEventuallyConsistentRepository.Context();
    try (BlobStoreRepository repository = new MockEventuallyConsistentRepository(new RepositoryMetadata("testRepo", "mockEventuallyConsistent", Settings.EMPTY), xContentRegistry(), BlobStoreTestUtil.mockClusterService(), blobStoreContext, random())) {
        repository.start();
        final BlobContainer blobContainer = repository.blobStore().blobContainer(repository.basePath());
        final String blobName = randomAlphaOfLength(10);
        final int lengthWritten = randomIntBetween(1, 100);
        final byte[] blobData = randomByteArrayOfLength(lengthWritten);
        blobContainer.writeBlob(blobName, new ByteArrayInputStream(blobData), lengthWritten, true);
        blobContainer.deleteBlobsIgnoringIfNotExists(Collections.singletonList(blobName));
        assertThrowsOnInconsistentRead(blobContainer, blobName);
        blobStoreContext.forceConsistent();
        expectThrows(NoSuchFileException.class, () -> blobContainer.readBlob(blobName));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BlobStoreRepository(org.elasticsearch.repositories.blobstore.BlobStoreRepository) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) BlobContainer(org.elasticsearch.common.blobstore.BlobContainer)

Aggregations

RepositoryMetadata (org.elasticsearch.cluster.metadata.RepositoryMetadata)6 BlobStoreRepository (org.elasticsearch.repositories.blobstore.BlobStoreRepository)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 BlobContainer (org.elasticsearch.common.blobstore.BlobContainer)5 InputStream (java.io.InputStream)1 ClusterService (org.elasticsearch.cluster.service.ClusterService)1 SnapshotId (org.elasticsearch.snapshots.SnapshotId)1 SnapshotInfo (org.elasticsearch.snapshots.SnapshotInfo)1