/** * Deletes a blob with giving name, ignoring if the blob does not exist. * * @param blobName * The name of the blob to delete. * @throws IOException if the blob exists but could not be deleted. */ default void deleteBlobIgnoringIfNotExists(String blobName) throws IOException { try { deleteBlob(blobName); } catch (final NoSuchFileException ignored) { // This exception is ignored } }
/** * Deletes obj in the blob container */ public void delete(BlobContainer blobContainer, String name) throws IOException { blobContainer.deleteBlob(blobName(name)); }
/** * Deletes a blob with giving name, ignoring if the blob does not exist. * * @param blobName * The name of the blob to delete. * @throws IOException if the blob exists but could not be deleted. */ default void deleteBlobIgnoringIfNotExists(String blobName) throws IOException { try { deleteBlob(blobName); } catch (final NoSuchFileException ignored) { // This exception is ignored } }
/** * Deletes a blob with giving name, ignoring if the blob does not exist. * * @param blobName * The name of the blob to delete. * @throws IOException if the blob exists but could not be deleted. */ default void deleteBlobIgnoringIfNotExists(String blobName) throws IOException { try { deleteBlob(blobName); } catch (final NoSuchFileException ignored) { // This exception is ignored } }
for (final IndexId indexId : indicesToCleanUp) { try { indicesBlobContainer.deleteBlob(indexId.getId()); } catch (DirectoryNotEmptyException dnee) {
/** * Deletes obj in the blob container */ public void delete(BlobContainer blobContainer, String name) throws IOException { blobContainer.deleteBlob(blobName(name)); }
/** * Deletes obj in the blob container */ public void delete(BlobContainer blobContainer, String name) throws IOException { blobContainer.deleteBlob(blobName(name)); }
/** * Deletes obj in the blob container */ public void delete(BlobContainer blobContainer, String name) throws IOException { blobContainer.deleteBlob(blobName(name)); }
/** * Deletes obj in the blob container */ public void delete(BlobContainer blobContainer, String name) throws IOException { blobContainer.deleteBlob(blobName(name)); }
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); container.deleteBlob(blobName); // should not raise // blob deleted, so should raise again expectThrows(IOException.class, () -> container.deleteBlob(blobName)); } }
if (indexShardSnapshotsFormat.isTempBlobName(blobName) || blobName.startsWith(SNAPSHOT_INDEX_PREFIX)) { try { blobContainer.deleteBlob(blobName); } catch (IOException e) { if (newSnapshots.findNameFile(BlobStoreIndexShardSnapshot.FileInfo.canonicalName(blobName)) == null) { try { blobContainer.deleteBlob(blobName); } catch (IOException e) {
/** * Writes blob in atomic manner with resolving the blob name using {@link #blobName} and {@link #tempBlobName} methods. * <p> * The blob will be compressed and checksum will be written if required. * * Atomic move might be very inefficient on some repositories. It also cannot override existing files. * * @param obj object to be serialized * @param blobContainer blob container * @param name blob name */ public void writeAtomic(T obj, BlobContainer blobContainer, String name) throws IOException { String blobName = blobName(name); String tempBlobName = tempBlobName(name); writeBlob(obj, blobContainer, tempBlobName); try { blobContainer.move(tempBlobName, blobName); } catch (IOException ex) { // Move failed - try cleaning up blobContainer.deleteBlob(tempBlobName); throw ex; } }
/** * Writes blob in atomic manner with resolving the blob name using {@link #blobName} and {@link #tempBlobName} methods. * <p> * The blob will be compressed and checksum will be written if required. * * Atomic move might be very inefficient on some repositories. It also cannot override existing files. * * @param obj object to be serialized * @param blobContainer blob container * @param name blob name */ public void writeAtomic(T obj, BlobContainer blobContainer, String name) throws IOException { String blobName = blobName(name); String tempBlobName = tempBlobName(name); writeBlob(obj, blobContainer, tempBlobName); try { blobContainer.move(tempBlobName, blobName); } catch (IOException ex) { // Move failed - try cleaning up blobContainer.deleteBlob(tempBlobName); throw ex; } }
private void writeAtomic(final String blobName, final BytesReference bytesRef) throws IOException { final String tempBlobName = "pending-" + blobName + "-" + UUIDs.randomBase64UUID(); try (InputStream stream = bytesRef.streamInput()) { snapshotsBlobContainer.writeBlob(tempBlobName, stream, bytesRef.length()); snapshotsBlobContainer.move(tempBlobName, blobName); } catch (IOException ex) { // temporary blob creation or move failed - try cleaning up try { snapshotsBlobContainer.deleteBlob(tempBlobName); } catch (IOException e) { ex.addSuppressed(e); } throw ex; } }
/** * Writes snapshot index file * <p> * This file can be used by read-only repositories that are unable to list files in the repository * * @param snapshots list of snapshot ids * @throws IOException I/O errors */ protected void writeSnapshotList(List<SnapshotId> snapshots) throws IOException { final BytesReference bRef; try(BytesStreamOutput bStream = new BytesStreamOutput()) { try(StreamOutput stream = new OutputStreamStreamOutput(bStream)) { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON, stream); builder.startObject(); builder.startArray("snapshots"); for (SnapshotId snapshot : snapshots) { builder.value(snapshot.getSnapshot()); } builder.endArray(); builder.endObject(); builder.close(); } bRef = bStream.bytes(); } if (snapshotsBlobContainer.blobExists(SNAPSHOTS_FILE)) { snapshotsBlobContainer.deleteBlob(SNAPSHOTS_FILE); } snapshotsBlobContainer.writeBlob(SNAPSHOTS_FILE, bRef); }
final String oldSnapshotIndexFile = INDEX_FILE_PREFIX + Long.toString(newGen - 2); if (snapshotsBlobContainer.blobExists(oldSnapshotIndexFile)) { snapshotsBlobContainer.deleteBlob(oldSnapshotIndexFile); snapshotsBlobContainer.deleteBlob(INDEX_LATEST_BLOB);
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); writeBlob(container, blobName, bytesArray); // after deleting the previous blob, we should be able to write to it again } }
/** * Writes the incompatible snapshot ids list to the `incompatible-snapshots` blob in the repository. * * Package private for testing. */ void writeIncompatibleSnapshots(RepositoryData repositoryData) throws IOException { assert isReadOnly() == false; // can not write to a read only repository final BytesReference bytes; try (BytesStreamOutput bStream = new BytesStreamOutput()) { try (StreamOutput stream = new OutputStreamStreamOutput(bStream)) { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON, stream); repositoryData.incompatibleSnapshotsToXContent(builder, ToXContent.EMPTY_PARAMS); builder.close(); } bytes = bStream.bytes(); } if (snapshotsBlobContainer.blobExists(INCOMPATIBLE_SNAPSHOTS_BLOB)) { snapshotsBlobContainer.deleteBlob(INCOMPATIBLE_SNAPSHOTS_BLOB); } // write the incompatible snapshots blob writeAtomic(INCOMPATIBLE_SNAPSHOTS_BLOB, bytes); }
for (final IndexId indexId : indicesToCleanUp) { try { indicesBlobContainer.deleteBlob(indexId.getId()); } catch (DirectoryNotEmptyException dnee) {
for (final IndexId indexId : indicesToCleanUp) { try { indicesBlobContainer.deleteBlob(indexId.getId()); } catch (DirectoryNotEmptyException dnee) {