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));
}
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations