use of com.github.ambry.store.StoreErrorCodes in project ambry by linkedin.
the class AmbryServerRequestsTest method miscTtlUpdateFailuresTest.
/**
* Exercises various failure paths for TTL updates
* @throws InterruptedException
* @throws IOException
*/
private void miscTtlUpdateFailuresTest() throws InterruptedException, IOException {
PartitionId id = clusterMap.getWritablePartitionIds(DEFAULT_PARTITION_CLASS).get(0);
// store exceptions
for (StoreErrorCodes code : StoreErrorCodes.values()) {
MockStorageManager.storeException = new StoreException("expected", code);
ServerErrorCode expectedErrorCode = ErrorMapping.getStoreErrorMapping(code);
sendAndVerifyOperationRequest(RequestOrResponseType.TtlUpdateRequest, Collections.singletonList(id), expectedErrorCode, true, null);
MockStorageManager.storeException = null;
}
// runtime exception
MockStorageManager.runtimeException = new RuntimeException("expected");
sendAndVerifyOperationRequest(RequestOrResponseType.TtlUpdateRequest, Collections.singletonList(id), ServerErrorCode.Unknown_Error, true, null);
MockStorageManager.runtimeException = null;
// store is not started/is stopped/otherwise unavailable - Replica_Unavailable
storageManager.returnNullStore = true;
sendAndVerifyOperationRequest(RequestOrResponseType.TtlUpdateRequest, Collections.singletonList(id), ServerErrorCode.Replica_Unavailable, false, null);
storageManager.returnNullStore = false;
// PartitionUnknown is hard to simulate without betraying knowledge of the internals of MockClusterMap.
// disk down
ReplicaId replicaId = findReplica(id);
clusterMap.onReplicaEvent(replicaId, ReplicaEventType.Disk_Error);
sendAndVerifyOperationRequest(RequestOrResponseType.TtlUpdateRequest, Collections.singletonList(id), ServerErrorCode.Disk_Unavailable, false, null);
clusterMap.onReplicaEvent(replicaId, ReplicaEventType.Disk_Ok);
// request disabled is checked in request control tests
}
use of com.github.ambry.store.StoreErrorCodes in project ambry by linkedin.
the class CloudBlobStore method updateTtl.
/**
* {@inheritDoc}
* Currently, the only supported operation is to set the TTL to infinite (i.e. no arbitrary increase or decrease)
* @param infos The list of messages that need to be updated.
* @throws StoreException
*/
@Override
public void updateTtl(List<MessageInfo> infos) throws StoreException {
checkStarted();
// Note: We skipped uploading the blob on PUT record if the TTL was below threshold (threshold should be 0 for non DR cases).
try {
for (MessageInfo msgInfo : infos) {
if (msgInfo.getExpirationTimeInMs() != Utils.Infinite_Time) {
throw new StoreException("CloudBlobStore only supports removing the expiration time", StoreErrorCodes.Update_Not_Allowed);
}
if (msgInfo.isTtlUpdated()) {
BlobId blobId = (BlobId) msgInfo.getStoreKey();
requestAgent.doWithRetries(() -> updateTtlIfNeeded(blobId), "UpdateTtl", partitionId.toPathString());
} else {
logger.error("updateTtl() is called but msgInfo.isTtlUpdated is not set. msgInfo: {}", msgInfo);
vcrMetrics.updateTtlNotSetError.inc();
}
}
} catch (CloudStorageException ex) {
if (ex.getCause() instanceof StoreException) {
throw (StoreException) ex.getCause();
}
StoreErrorCodes errorCode = (ex.getStatusCode() == STATUS_NOT_FOUND) ? StoreErrorCodes.ID_Not_Found : StoreErrorCodes.IOError;
throw new StoreException(ex, errorCode);
}
}
use of com.github.ambry.store.StoreErrorCodes in project ambry by linkedin.
the class CloudBlobStore method delete.
@Override
public void delete(List<MessageInfo> infos) throws StoreException {
checkStarted();
checkDuplicates(infos);
try {
for (MessageInfo msgInfo : infos) {
BlobId blobId = (BlobId) msgInfo.getStoreKey();
// If the cache has been updated by another thread, retry may be avoided
requestAgent.doWithRetries(() -> deleteIfNeeded(blobId, msgInfo.getOperationTimeMs(), msgInfo.getLifeVersion()), "Delete", partitionId.toPathString());
}
} catch (CloudStorageException ex) {
if (ex.getCause() instanceof StoreException) {
throw (StoreException) ex.getCause();
}
StoreErrorCodes errorCode = (ex.getStatusCode() == STATUS_NOT_FOUND) ? StoreErrorCodes.ID_Not_Found : StoreErrorCodes.IOError;
throw new StoreException(ex, errorCode);
}
}
use of com.github.ambry.store.StoreErrorCodes 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();
}
use of com.github.ambry.store.StoreErrorCodes in project ambry by linkedin.
the class LatchBasedInMemoryCloudDestination method undeleteBlob.
@Override
public short undeleteBlob(BlobId blobId, short lifeVersion, CloudUpdateValidator cloudUpdateValidator) throws CloudStorageException {
StoreErrorCodes serverError = hardError != null ? hardError : serverErrors.size() > 0 ? serverErrors.poll() : null;
if (serverError != null) {
throw new CloudStorageException("undeleteBlob simulated error", new StoreException("undeleteBlob simulated error", serverError));
}
if (map.containsKey(blobId)) {
if (!MessageInfo.hasLifeVersion((lifeVersion))) {
lifeVersion = map.get(blobId).getFirst().getLifeVersion();
lifeVersion++;
}
map.get(blobId).getFirst().setLifeVersion(lifeVersion);
map.get(blobId).getFirst().setDeletionTime(Utils.Infinite_Time);
map.get(blobId).getFirst().setLastUpdateTime(System.currentTimeMillis());
changeFeed.add(blobId);
return map.get(blobId).getFirst().getLifeVersion();
} else {
throw new CloudStorageException(String.format("Cannot update lifeversion as blob %s is not found.", blobId.getID()), null, CloudBlobStore.STATUS_NOT_FOUND, false, null);
}
}
Aggregations