Search in sources :

Example 1 with BlobPath

use of org.elasticsearch.common.blobstore.BlobPath in project elasticsearch by elastic.

the class ESBlobStoreContainerTestCase method testDeleteBlob.

public void testDeleteBlob() throws IOException {
    try (BlobStore store = newBlobStore()) {
        final String blobName = "foobar";
        final BlobContainer container = store.blobContainer(new BlobPath());
        expectThrows(IOException.class, () -> container.deleteBlob(blobName));
        byte[] data = randomBytes(randomIntBetween(10, scaledRandomIntBetween(1024, 1 << 16)));
        final BytesArray bytesArray = new BytesArray(data);
        writeBlob(container, blobName, bytesArray);
        // should not raise
        container.deleteBlob(blobName);
        // blob deleted, so should raise again
        expectThrows(IOException.class, () -> container.deleteBlob(blobName));
    }
}
Also used : BlobPath(org.elasticsearch.common.blobstore.BlobPath) BytesArray(org.elasticsearch.common.bytes.BytesArray) BlobContainer(org.elasticsearch.common.blobstore.BlobContainer) BlobStore(org.elasticsearch.common.blobstore.BlobStore)

Example 2 with BlobPath

use of org.elasticsearch.common.blobstore.BlobPath in project elasticsearch by elastic.

the class ESBlobStoreContainerTestCase method testVerifyOverwriteFails.

public void testVerifyOverwriteFails() throws IOException {
    try (BlobStore store = newBlobStore()) {
        final String blobName = "foobar";
        final BlobContainer container = store.blobContainer(new BlobPath());
        byte[] data = randomBytes(randomIntBetween(10, scaledRandomIntBetween(1024, 1 << 16)));
        final BytesArray bytesArray = new BytesArray(data);
        writeBlob(container, blobName, bytesArray);
        // should not be able to overwrite existing blob
        expectThrows(IOException.class, () -> writeBlob(container, blobName, bytesArray));
        container.deleteBlob(blobName);
        // after deleting the previous blob, we should be able to write to it again
        writeBlob(container, blobName, bytesArray);
    }
}
Also used : BlobPath(org.elasticsearch.common.blobstore.BlobPath) BytesArray(org.elasticsearch.common.bytes.BytesArray) BlobContainer(org.elasticsearch.common.blobstore.BlobContainer) BlobStore(org.elasticsearch.common.blobstore.BlobStore)

Example 3 with BlobPath

use of org.elasticsearch.common.blobstore.BlobPath in project elasticsearch by elastic.

the class BlobStoreRepository method initializeSnapshot.

@Override
public void initializeSnapshot(SnapshotId snapshotId, List<IndexId> indices, MetaData clusterMetaData) {
    if (isReadOnly()) {
        throw new RepositoryException(metadata.name(), "cannot create snapshot in a readonly repository");
    }
    try {
        final String snapshotName = snapshotId.getName();
        // check if the snapshot name already exists in the repository
        final RepositoryData repositoryData = getRepositoryData();
        if (repositoryData.getAllSnapshotIds().stream().anyMatch(s -> s.getName().equals(snapshotName))) {
            throw new InvalidSnapshotNameException(metadata.name(), snapshotId.getName(), "snapshot with the same name already exists");
        }
        if (snapshotFormat.exists(snapshotsBlobContainer, snapshotId.getUUID())) {
            throw new InvalidSnapshotNameException(metadata.name(), snapshotId.getName(), "snapshot with the same name already exists");
        }
        // Write Global MetaData
        globalMetaDataFormat.write(clusterMetaData, snapshotsBlobContainer, snapshotId.getUUID());
        // write the index metadata for each index in the snapshot
        for (IndexId index : indices) {
            final IndexMetaData indexMetaData = clusterMetaData.index(index.getName());
            final BlobPath indexPath = basePath().add("indices").add(index.getId());
            final BlobContainer indexMetaDataBlobContainer = blobStore().blobContainer(indexPath);
            indexMetaDataFormat.write(indexMetaData, indexMetaDataBlobContainer, snapshotId.getUUID());
        }
    } catch (IOException ex) {
        throw new SnapshotCreationException(metadata.name(), snapshotId, ex);
    }
}
Also used : IndexId(org.elasticsearch.repositories.IndexId) BlobPath(org.elasticsearch.common.blobstore.BlobPath) BlobContainer(org.elasticsearch.common.blobstore.BlobContainer) SnapshotCreationException(org.elasticsearch.snapshots.SnapshotCreationException) RepositoryException(org.elasticsearch.repositories.RepositoryException) IOException(java.io.IOException) InvalidSnapshotNameException(org.elasticsearch.snapshots.InvalidSnapshotNameException) RepositoryData(org.elasticsearch.repositories.RepositoryData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 4 with BlobPath

use of org.elasticsearch.common.blobstore.BlobPath in project elasticsearch by elastic.

the class FsBlobStore method buildPath.

private Path buildPath(BlobPath path) {
    String[] paths = path.toArray();
    if (paths.length == 0) {
        return path();
    }
    Path blobPath = this.path.resolve(paths[0]);
    if (paths.length > 1) {
        for (int i = 1; i < paths.length; i++) {
            blobPath = blobPath.resolve(paths[i]);
        }
    }
    return blobPath;
}
Also used : BlobPath(org.elasticsearch.common.blobstore.BlobPath) Path(java.nio.file.Path)

Example 5 with BlobPath

use of org.elasticsearch.common.blobstore.BlobPath in project elasticsearch by elastic.

the class FsBlobStore method buildAndCreate.

private synchronized Path buildAndCreate(BlobPath path) throws IOException {
    Path f = buildPath(path);
    Files.createDirectories(f);
    return f;
}
Also used : BlobPath(org.elasticsearch.common.blobstore.BlobPath) Path(java.nio.file.Path)

Aggregations

BlobPath (org.elasticsearch.common.blobstore.BlobPath)10 BlobContainer (org.elasticsearch.common.blobstore.BlobContainer)8 BlobStore (org.elasticsearch.common.blobstore.BlobStore)5 BytesArray (org.elasticsearch.common.bytes.BytesArray)4 IOException (java.io.IOException)3 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)3 BlobMetaData (org.elasticsearch.common.blobstore.BlobMetaData)3 IndexId (org.elasticsearch.repositories.IndexId)3 Path (java.nio.file.Path)2 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)2 Supplier (org.apache.logging.log4j.util.Supplier)2 ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)2 MetaData (org.elasticsearch.cluster.metadata.MetaData)2 RepositoryMetaData (org.elasticsearch.cluster.metadata.RepositoryMetaData)2 IndexShardSnapshotException (org.elasticsearch.index.snapshots.IndexShardSnapshotException)2 StoreFileMetaData (org.elasticsearch.index.store.StoreFileMetaData)2 RepositoryData (org.elasticsearch.repositories.RepositoryData)2 RepositoryException (org.elasticsearch.repositories.RepositoryException)2 SnapshotException (org.elasticsearch.snapshots.SnapshotException)2 SnapshotMissingException (org.elasticsearch.snapshots.SnapshotMissingException)2