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);
}
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);
}
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);
}
}
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);
}
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);
}
}
Aggregations