Search in sources :

Example 6 with StoreErrorCodes

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
}
Also used : MockPartitionId(com.github.ambry.clustermap.MockPartitionId) PartitionId(com.github.ambry.clustermap.PartitionId) StoreErrorCodes(com.github.ambry.store.StoreErrorCodes) ReplicaId(com.github.ambry.clustermap.ReplicaId) MockReplicaId(com.github.ambry.clustermap.MockReplicaId) IdUndeletedStoreException(com.github.ambry.store.IdUndeletedStoreException) StoreException(com.github.ambry.store.StoreException)

Example 7 with StoreErrorCodes

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);
    }
}
Also used : StoreErrorCodes(com.github.ambry.store.StoreErrorCodes) BlobId(com.github.ambry.commons.BlobId) MessageInfo(com.github.ambry.store.MessageInfo) StoreException(com.github.ambry.store.StoreException)

Example 8 with StoreErrorCodes

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);
    }
}
Also used : StoreErrorCodes(com.github.ambry.store.StoreErrorCodes) BlobId(com.github.ambry.commons.BlobId) MessageInfo(com.github.ambry.store.MessageInfo) StoreException(com.github.ambry.store.StoreException)

Example 9 with StoreErrorCodes

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();
}
Also used : IOException(java.io.IOException) StoreErrorCodes(com.github.ambry.store.StoreErrorCodes) StoreException(com.github.ambry.store.StoreException)

Example 10 with StoreErrorCodes

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);
    }
}
Also used : StoreErrorCodes(com.github.ambry.store.StoreErrorCodes) StoreException(com.github.ambry.store.StoreException)

Aggregations

StoreErrorCodes (com.github.ambry.store.StoreErrorCodes)10 StoreException (com.github.ambry.store.StoreException)10 BlobId (com.github.ambry.commons.BlobId)3 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)2 MockReplicaId (com.github.ambry.clustermap.MockReplicaId)2 PartitionId (com.github.ambry.clustermap.PartitionId)2 ReplicaId (com.github.ambry.clustermap.ReplicaId)2 IdUndeletedStoreException (com.github.ambry.store.IdUndeletedStoreException)2 MessageInfo (com.github.ambry.store.MessageInfo)2 IOException (java.io.IOException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1