Search in sources :

Example 56 with MessageInfo

use of com.github.ambry.store.MessageInfo in project ambry by linkedin.

the class AmbryServerRequestsTest method verifyUndelete.

/**
 * Verifies that the UNDELETE request was delivered to the {@link Store} correctly.
 * @param blobId the {@link BlobId} that was updated
 * @param opTimeMs the op time (in ms)
 * @param messageWriteSet the {@link MessageWriteSet} received at the {@link Store}
 * @throws IOException
 * @throws MessageFormatException
 * @throws StoreException
 */
private void verifyUndelete(BlobId blobId, long opTimeMs, MessageWriteSet messageWriteSet) throws Exception {
    BlobId key = (BlobId) conversionMap.getOrDefault(blobId, blobId);
    assertEquals("There should be one message in the write set", 1, messageWriteSet.getMessageSetInfo().size());
    MessageInfo info = messageWriteSet.getMessageSetInfo().get(0);
    // verify stream
    ByteBuffer record = getDataInWriteSet(messageWriteSet, (int) info.getSize());
    int expectedSize = record.remaining();
    InputStream stream = new ByteBufferInputStream(record);
    // verify stream
    MessageFormatInputStreamTest.checkUndeleteMessage(stream, null, key, key.getAccountId(), key.getContainerId(), opTimeMs, storageManager.returnValueOfUndelete);
    // verify MessageInfo
    // since the record has been verified, the buffer size before verification is a good indicator of size
    MessageInfoTest.checkGetters(info, key, expectedSize, false, false, true, Utils.Infinite_Time, null, key.getAccountId(), key.getContainerId(), opTimeMs, storageManager.returnValueOfUndelete);
}
Also used : ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) ByteBufferDataInputStream(com.github.ambry.utils.ByteBufferDataInputStream) InputStream(java.io.InputStream) ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) BlobId(com.github.ambry.commons.BlobId) ByteBuffer(java.nio.ByteBuffer) MessageInfo(com.github.ambry.store.MessageInfo)

Example 57 with MessageInfo

use of com.github.ambry.store.MessageInfo in project ambry by linkedin.

the class AmbryServerRequestsTest method verifyTtlUpdate.

/**
 * Verifies that the TTL update request was delivered to the {@link Store} correctly.
 * @param blobId the {@link BlobId} that was updated
 * @param expiresAtMs the new expire time (in ms)
 * @param opTimeMs the op time (in ms)
 * @param messageWriteSet the {@link MessageWriteSet} received at the {@link Store}
 * @throws IOException
 * @throws MessageFormatException
 * @throws StoreException
 */
private void verifyTtlUpdate(BlobId blobId, long expiresAtMs, long opTimeMs, MessageWriteSet messageWriteSet) throws IOException, MessageFormatException, StoreException {
    BlobId key = (BlobId) conversionMap.getOrDefault(blobId, blobId);
    assertEquals("There should be one message in the write set", 1, messageWriteSet.getMessageSetInfo().size());
    MessageInfo info = messageWriteSet.getMessageSetInfo().get(0);
    // verify stream
    ByteBuffer record = getDataInWriteSet(messageWriteSet, (int) info.getSize());
    int expectedSize = record.remaining();
    InputStream stream = new ByteBufferInputStream(record);
    // verify stream
    MessageFormatInputStreamTest.checkTtlUpdateMessage(stream, null, key, key.getAccountId(), key.getContainerId(), expiresAtMs, opTimeMs, (short) 0);
    // verify MessageInfo
    // since the record has been verified, the buffer size before verification is a good indicator of size
    MessageInfoTest.checkGetters(info, key, expectedSize, false, true, false, expiresAtMs, null, key.getAccountId(), key.getContainerId(), opTimeMs, (short) 0);
}
Also used : ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) ByteBufferDataInputStream(com.github.ambry.utils.ByteBufferDataInputStream) InputStream(java.io.InputStream) ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) BlobId(com.github.ambry.commons.BlobId) ByteBuffer(java.nio.ByteBuffer) MessageInfo(com.github.ambry.store.MessageInfo)

Example 58 with MessageInfo

use of com.github.ambry.store.MessageInfo in project ambry by linkedin.

the class CloudBlobStore method findKey.

@Override
public MessageInfo findKey(StoreKey key) throws StoreException {
    try {
        Map<String, CloudBlobMetadata> cloudBlobMetadataListMap = requestAgent.doWithRetries(() -> cloudDestination.getBlobMetadata(Collections.singletonList((BlobId) key)), "FindKey", partitionId.toPathString());
        CloudBlobMetadata cloudBlobMetadata = cloudBlobMetadataListMap.get(key.getID());
        if (cloudBlobMetadata != null) {
            return new MessageInfo(key, cloudBlobMetadata.getSize(), cloudBlobMetadata.isDeleted(), cloudBlobMetadata.isExpired(), cloudBlobMetadata.isUndeleted(), cloudBlobMetadata.getExpirationTime(), null, (short) cloudBlobMetadata.getAccountId(), (short) cloudBlobMetadata.getContainerId(), cloudBlobMetadata.getLastUpdateTime(), cloudBlobMetadata.getLifeVersion());
        } else {
            throw new StoreException(String.format("FindKey couldn't find key: %s", key), StoreErrorCodes.ID_Not_Found);
        }
    } catch (CloudStorageException e) {
        throw new StoreException(e, StoreErrorCodes.IOError);
    }
}
Also used : CloudBlobMetadata(com.github.ambry.cloud.CloudBlobMetadata) MessageInfo(com.github.ambry.store.MessageInfo) StoreException(com.github.ambry.store.StoreException)

Example 59 with MessageInfo

use of com.github.ambry.store.MessageInfo in project ambry by linkedin.

the class CloudBlobStore method getMessageInfoFromMetadata.

/**
 * Create {@link MessageInfo} object from {@link CloudBlobMetadata} object.
 * @param metadata {@link CloudBlobMetadata} object.
 * @return {@link MessageInfo} object.
 * @throws IOException
 */
private MessageInfo getMessageInfoFromMetadata(CloudBlobMetadata metadata) throws IOException {
    BlobId blobId = new BlobId(metadata.getId(), clusterMap);
    long operationTime = (metadata.getDeletionTime() > 0) ? metadata.getDeletionTime() : (metadata.getCreationTime() > 0) ? metadata.getCreationTime() : metadata.getUploadTime();
    boolean isDeleted = metadata.getDeletionTime() > 0;
    // No way to know
    boolean isTtlUpdated = false;
    return new MessageInfo(blobId, metadata.getSize(), isDeleted, isTtlUpdated, metadata.getExpirationTime(), (short) metadata.getAccountId(), (short) metadata.getContainerId(), operationTime);
}
Also used : BlobId(com.github.ambry.commons.BlobId) MessageInfo(com.github.ambry.store.MessageInfo)

Example 60 with MessageInfo

use of com.github.ambry.store.MessageInfo 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)

Aggregations

MessageInfo (com.github.ambry.store.MessageInfo)109 ArrayList (java.util.ArrayList)49 StoreKey (com.github.ambry.store.StoreKey)42 ByteBuffer (java.nio.ByteBuffer)38 BlobId (com.github.ambry.commons.BlobId)36 StoreException (com.github.ambry.store.StoreException)30 DataInputStream (java.io.DataInputStream)23 Test (org.junit.Test)22 HashMap (java.util.HashMap)21 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)19 PartitionId (com.github.ambry.clustermap.PartitionId)19 IOException (java.io.IOException)19 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)18 ByteBufferInputStream (com.github.ambry.utils.ByteBufferInputStream)18 InputStream (java.io.InputStream)17 List (java.util.List)16 ClusterMap (com.github.ambry.clustermap.ClusterMap)15 Map (java.util.Map)15 MockMessageWriteSet (com.github.ambry.store.MockMessageWriteSet)13 HashSet (java.util.HashSet)13