/** * Clears pages from a page blob. * <p> * Calling <code>clearPages</code> releases the storage space used by the specified pages. Pages that have been * cleared are no longer tracked as part of the page blob, and no longer incur a charge against the storage account. * * @param offset * The offset, in bytes, at which to begin clearing pages. This value must be a multiple of 512. * @param length * The length, in bytes, of the data range to be cleared. This value must be a multiple of 512. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public void clearPages(final long offset, final long length) throws StorageException { this.clearPages(offset, length, null /* accessCondition */, null /* options */, null /* opContext */); }
/** * Clears pages from a page blob. * <p> * Calling <code>clearPages</code> releases the storage space used by the specified pages. Pages that have been * cleared are no longer tracked as part of the page blob, and no longer incur a charge against the storage account. * * @param offset * The offset, in bytes, at which to begin clearing pages. This value must be a multiple of 512. * @param length * The length, in bytes, of the data range to be cleared. This value must be a multiple of 512. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public void clearPages(final long offset, final long length) throws StorageException { this.clearPages(offset, length, null /* accessCondition */, null /* options */, null /* opContext */); }
private void clearPageBlob(Exchange exchange) throws Exception { LOG.trace("Clearing a page blob [{}] from exchange [{}]...", getConfiguration().getBlobName(), exchange); CloudPageBlob client = BlobServiceUtil.createPageBlobClient(getConfiguration()); BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange); Long blobOffset = getConfiguration().getBlobOffset(); Long blobDataLength = getConfiguration().getDataLength(); PageRange range = exchange.getIn().getHeader(BlobServiceConstants.PAGE_BLOB_RANGE, PageRange.class); if (range != null) { blobOffset = range.getStartOffset(); blobDataLength = range.getEndOffset() - range.getStartOffset(); } if (blobDataLength == null) { blobDataLength = blobOffset == 0 ? getPageBlobSize(exchange) : 512L; } client.clearPages(blobOffset, blobDataLength, opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext()); }
@Test public void testDownloadPageRangeDiff() throws StorageException, URISyntaxException, IOException { final CloudPageBlob blobRef = setUpPageRanges(); final CloudPageBlob snapshot = (CloudPageBlob) blobRef.createSnapshot(); // Add page 1 InputStream inputStream = new ByteArrayInputStream(BlobTestHelper.getRandomBuffer(512)); inputStream = new ByteArrayInputStream(BlobTestHelper.getRandomBuffer(512)); blobRef.uploadPages(inputStream, 0, 512); // Clear page 6 blobRef.clearPages(6 * 512, 512); List<PageRangeDiff> actualPageRanges = blobRef.downloadPageRangesDiff(snapshot.getSnapshotID()); List<PageRangeDiff> expectedPageRanges = new ArrayList<PageRangeDiff>(); expectedPageRanges.add(new PageRangeDiff(0, 512 - 1, false)); expectedPageRanges.add(new PageRangeDiff(6 * 512, 7 * 512 - 1, true)); assertEquals(expectedPageRanges.size(), actualPageRanges.size()); for (int i = 0; i < expectedPageRanges.size(); i++) { assertEquals(expectedPageRanges.get(i).getStartOffset(), actualPageRanges.get(i).getStartOffset()); assertEquals(expectedPageRanges.get(i).getEndOffset(), actualPageRanges.get(i).getEndOffset()); assertEquals(expectedPageRanges.get(i).isCleared(), actualPageRanges.get(i).isCleared()); } }
blobRef.clearPages(0, 256); fail("Did not throw expected exception on non-512-byte-aligned length"); blobRef.clearPages(3 * 256, 3 * 512); fail("Did not throw expected exception on non-512-byte-aligned offset"); blobRef.clearPages(3 * 512, 2 * 512); assertNotNull(blobRef.getProperties().getPageBlobSequenceNumber());