Search in sources :

Example 1 with FsBlobStore

use of org.opensearch.common.blobstore.fs.FsBlobStore in project OpenSearch by opensearch-project.

the class FsBlobStoreRepositoryIT method testReadOnly.

public void testReadOnly() throws Exception {
    Path tempDir = createTempDir();
    Path path = tempDir.resolve("bar");
    try (FsBlobStore store = new FsBlobStore(randomIntBetween(1, 8) * 1024, path, true)) {
        assertFalse(Files.exists(path));
        BlobPath blobPath = BlobPath.cleanPath().add("foo");
        store.blobContainer(blobPath);
        Path storePath = store.path();
        for (String d : blobPath) {
            storePath = storePath.resolve(d);
        }
        assertFalse(Files.exists(storePath));
    }
    try (FsBlobStore store = new FsBlobStore(randomIntBetween(1, 8) * 1024, path, false)) {
        assertTrue(Files.exists(path));
        BlobPath blobPath = BlobPath.cleanPath().add("foo");
        BlobContainer container = store.blobContainer(blobPath);
        Path storePath = store.path();
        for (String d : blobPath) {
            storePath = storePath.resolve(d);
        }
        assertTrue(Files.exists(storePath));
        assertTrue(Files.isDirectory(storePath));
        byte[] data = randomBytes(randomIntBetween(10, scaledRandomIntBetween(1024, 1 << 16)));
        writeBlob(container, "test", new BytesArray(data));
        assertArrayEquals(readBlobFully(container, "test", data.length), data);
        assertTrue(container.blobExists("test"));
    }
}
Also used : BlobPath(org.opensearch.common.blobstore.BlobPath) Path(java.nio.file.Path) BlobPath(org.opensearch.common.blobstore.BlobPath) BytesArray(org.opensearch.common.bytes.BytesArray) FsBlobStore(org.opensearch.common.blobstore.fs.FsBlobStore) BlobContainer(org.opensearch.common.blobstore.BlobContainer)

Example 2 with FsBlobStore

use of org.opensearch.common.blobstore.fs.FsBlobStore in project OpenSearch by opensearch-project.

the class FsRepository method createBlobStore.

@Override
protected BlobStore createBlobStore() throws Exception {
    final String location = REPOSITORIES_LOCATION_SETTING.get(getMetadata().settings());
    final Path locationFile = environment.resolveRepoFile(location);
    return new FsBlobStore(bufferSize, locationFile, isReadOnly());
}
Also used : BlobPath(org.opensearch.common.blobstore.BlobPath) Path(java.nio.file.Path) FsBlobStore(org.opensearch.common.blobstore.fs.FsBlobStore)

Aggregations

Path (java.nio.file.Path)2 BlobPath (org.opensearch.common.blobstore.BlobPath)2 FsBlobStore (org.opensearch.common.blobstore.fs.FsBlobStore)2 BlobContainer (org.opensearch.common.blobstore.BlobContainer)1 BytesArray (org.opensearch.common.bytes.BytesArray)1