use of com.github.ambry.store.StoreException in project ambry by linkedin.
the class CloudMessageReadSet method doPrefetch.
@Override
public void doPrefetch(int index, long relativeOffset, long size) throws IOException {
BlobReadInfo blobReadInfo = blobReadInfoList.get(index);
try {
if (!blobReadInfo.isBlobDownloaded()) {
blobReadInfo.downloadBlob(blobStore);
}
ByteBuf byteBuf = blobReadInfoList.get(index).getBlobContent();
byteBuf.setIndex((int) (relativeOffset), (int) (relativeOffset + size));
} catch (StoreException ex) {
throw new IOException("Prefetch of cloud blob " + blobReadInfo.getBlobId().getID() + " failed", ex);
}
}
use of com.github.ambry.store.StoreException in project ambry by linkedin.
the class CloudMessageReadSet method writeTo.
@Override
public long writeTo(int index, WritableByteChannel channel, long relativeOffset, long maxSize) throws IOException {
validateIndex(index);
long written = 0;
BlobReadInfo blobReadInfo = blobReadInfoList.get(index);
String blobIdStr = blobReadInfo.getBlobId().getID();
try {
// or at least to prefetch only the header (requires CloudDestination enhancement)
if (!blobReadInfo.isBlobDownloaded()) {
blobReadInfo.downloadBlob(blobStore);
}
ByteBuf outputBuf = blobReadInfo.getBlobContent().duplicate();
long sizeToRead = Math.min(maxSize, blobReadInfo.getBlobSize() - relativeOffset);
outputBuf.setIndex((int) (relativeOffset), (int) (relativeOffset + sizeToRead));
written = channel.write(outputBuf.nioBuffer());
} catch (StoreException ex) {
throw new IOException("Write of cloud blob " + blobIdStr + " failed", ex);
}
logger.trace("Downloaded {} bytes to the write channel from the cloud blob : {}", written, blobIdStr);
return written;
}
use of com.github.ambry.store.StoreException in project ambry by linkedin.
the class CloudBlobStoreTest method testStoreUndeletes.
/**
* Test the CloudBlobStore undelete method.
*/
@Test
public void testStoreUndeletes() throws Exception {
setupCloudStore(false, true, defaultCacheLimit, true);
long now = System.currentTimeMillis();
MessageInfo messageInfo = new MessageInfo(getUniqueId(refAccountId, refContainerId, true, partitionId), SMALL_BLOB_SIZE, refAccountId, refContainerId, now, (short) 1);
when(dest.undeleteBlob(any(BlobId.class), anyShort(), any(CloudUpdateValidator.class))).thenReturn((short) 1);
store.undelete(messageInfo);
verify(dest, times(1)).undeleteBlob(any(BlobId.class), anyShort(), any(CloudUpdateValidator.class));
verifyCacheHits(1, 0);
// Call second time with same life version. If isVcr, should hit cache this time.
try {
store.undelete(messageInfo);
} catch (StoreException ex) {
assertEquals(ex.getErrorCode(), StoreErrorCodes.ID_Undeleted);
}
int expectedCount = isVcr ? 1 : 2;
verify(dest, times(expectedCount)).undeleteBlob(any(BlobId.class), eq((short) 1), any(CloudUpdateValidator.class));
verifyCacheHits(2, 1);
// Call again with a smaller life version.
when(dest.undeleteBlob(any(BlobId.class), anyShort(), any(CloudUpdateValidator.class))).thenReturn((short) 0);
messageInfo = new MessageInfo(messageInfo.getStoreKey(), SMALL_BLOB_SIZE, refAccountId, refContainerId, now, (short) 0);
try {
store.undelete(messageInfo);
} catch (StoreException ex) {
assertEquals(StoreErrorCodes.ID_Undeleted, ex.getErrorCode());
}
expectedCount = isVcr ? 1 : 3;
verify(dest, times(expectedCount)).undeleteBlob(any(BlobId.class), anyShort(), any(CloudUpdateValidator.class));
verifyCacheHits(3, 2);
// Call again with a higher life version. Should not hit cache this time.
when(dest.undeleteBlob(any(BlobId.class), anyShort(), any(CloudUpdateValidator.class))).thenReturn((short) 2);
messageInfo = new MessageInfo(messageInfo.getStoreKey(), SMALL_BLOB_SIZE, refAccountId, refContainerId, now, (short) 2);
store.undelete(messageInfo);
expectedCount = isVcr ? 2 : 4;
verify(dest, times(expectedCount)).undeleteBlob(any(BlobId.class), anyShort(), any(CloudUpdateValidator.class));
verifyCacheHits(4, 2);
// undelete for a non existent blob.
setupCloudStore(true, true, defaultCacheLimit, true);
try {
store.undelete(messageInfo);
fail("Undelete for a non existent blob should throw exception");
} catch (StoreException ex) {
assertSame(ex.getErrorCode(), StoreErrorCodes.ID_Not_Found);
}
// add blob and then undelete should pass
MockMessageWriteSet messageWriteSet = new MockMessageWriteSet();
ByteBuffer buffer = ByteBuffer.wrap(TestUtils.getRandomBytes(SMALL_BLOB_SIZE));
// currently messageInfo.lifeVersion = 2
messageWriteSet.add(messageInfo, buffer);
store.put(messageWriteSet);
assertEquals(store.undelete(messageInfo), 2);
}
use of com.github.ambry.store.StoreException in project ambry by linkedin.
the class CloudBlobStoreTest method testStoreNotStarted.
/**
* Test verifying behavior when store not started.
*/
@Test
public void testStoreNotStarted() throws Exception {
// Create store and don't start it.
setupCloudStore(false, true, defaultCacheLimit, false);
List<StoreKey> keys = Collections.singletonList(getUniqueId(refAccountId, refContainerId, false, partitionId));
MockMessageWriteSet messageWriteSet = new MockMessageWriteSet();
CloudTestUtil.addBlobToMessageSet(messageWriteSet, 10, Utils.Infinite_Time, refAccountId, refContainerId, true, false, partitionId, operationTime, isVcr);
try {
store.put(messageWriteSet);
fail("Store put should have failed.");
} catch (StoreException e) {
assertEquals(StoreErrorCodes.Store_Not_Started, e.getErrorCode());
}
try {
store.delete(messageWriteSet.getMessageSetInfo());
fail("Store delete should have failed.");
} catch (StoreException e) {
assertEquals(StoreErrorCodes.Store_Not_Started, e.getErrorCode());
}
try {
store.findMissingKeys(keys);
fail("Store findMissingKeys should have failed.");
} catch (StoreException e) {
assertEquals(StoreErrorCodes.Store_Not_Started, e.getErrorCode());
}
}
use of com.github.ambry.store.StoreException in project ambry by linkedin.
the class LatchBasedInMemoryCloudDestination method downloadBlob.
@Override
public void downloadBlob(BlobId blobId, OutputStream outputStream) throws CloudStorageException {
StoreErrorCodes serverError = hardError != null ? hardError : serverErrors.size() > 0 ? serverErrors.poll() : null;
if (serverError != null) {
throw new CloudStorageException("downloadBlob simulated error for blobid :" + blobId, new StoreException("downloadBlob simulated error for blobid :" + blobId, serverError));
}
try {
if (!map.containsKey(blobId)) {
throw new CloudStorageException("Blob with blobId " + blobId.getID() + " does not exist.");
}
byte[] blobData = map.get(blobId).getSecond();
outputStream.write(blobData);
} catch (IOException ex) {
throw new CloudStorageException("Could not download blob for blobid " + blobId.getID() + " due to " + ex.toString());
}
downloadLatch.countDown();
}
Aggregations