use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class PartitionResponseInfo method readFrom.
public static PartitionResponseInfo readFrom(DataInputStream stream, ClusterMap map, short getResponseVersion) throws IOException {
PartitionId partitionId = map.getPartitionIdFromStream(stream);
MessageInfoAndMetadataListSerde messageInfoAndMetadataList = MessageInfoAndMetadataListSerde.deserializeMessageInfoAndMetadataList(stream, map, getMessageInfoAndMetadataListSerDeVersion(getResponseVersion));
ServerErrorCode error = ServerErrorCode.values()[stream.readShort()];
if (error != ServerErrorCode.No_Error) {
return new PartitionResponseInfo(partitionId, new ArrayList<>(), new ArrayList<>(), error, getResponseVersion);
} else {
return new PartitionResponseInfo(partitionId, messageInfoAndMetadataList.getMessageInfoList(), messageInfoAndMetadataList.getMessageMetadataList(), ServerErrorCode.No_Error, getResponseVersion);
}
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class AmbryRequests method handleUndeleteRequest.
@Override
public void handleUndeleteRequest(NetworkRequest request) throws IOException, InterruptedException {
UndeleteRequest undeleteRequest;
if (request instanceof LocalChannelRequest) {
// This is a case where handleUndeleteRequest is called when frontends are talking to Azure. In this case, this method
// is called by request handler threads running within the frontend router itself. So, the request can be directly
// referenced as java objects without any need for deserialization.
undeleteRequest = (UndeleteRequest) ((LocalChannelRequest) request).getRequestInfo().getRequest();
} else {
undeleteRequest = UndeleteRequest.readFrom(new DataInputStream(request.getInputStream()), clusterMap);
}
long requestQueueTime = SystemTime.getInstance().milliseconds() - request.getStartTimeInMs();
long totalTimeSpent = requestQueueTime;
metrics.undeleteBlobRequestQueueTimeInMs.update(requestQueueTime);
metrics.undeleteBlobRequestRate.mark();
long startTime = SystemTime.getInstance().milliseconds();
UndeleteResponse response = null;
Store storeToUndelete;
StoreKey convertedStoreKey;
try {
convertedStoreKey = getConvertedStoreKeys(Collections.singletonList(undeleteRequest.getBlobId())).get(0);
ServerErrorCode error = validateRequest(undeleteRequest.getBlobId().getPartition(), RequestOrResponseType.UndeleteRequest, false);
if (error != ServerErrorCode.No_Error) {
logger.error("Validating undelete request failed with error {} for request {}", error, undeleteRequest);
response = new UndeleteResponse(undeleteRequest.getCorrelationId(), undeleteRequest.getClientId(), error);
} else {
BlobId convertedBlobId = (BlobId) convertedStoreKey;
MessageInfo info = new MessageInfo.Builder(convertedBlobId, -1, convertedBlobId.getAccountId(), convertedBlobId.getContainerId(), undeleteRequest.getOperationTimeMs()).isUndeleted(true).lifeVersion(MessageInfo.LIFE_VERSION_FROM_FRONTEND).build();
storeToUndelete = storeManager.getStore(undeleteRequest.getBlobId().getPartition());
short lifeVersion = storeToUndelete.undelete(info);
response = new UndeleteResponse(undeleteRequest.getCorrelationId(), undeleteRequest.getClientId(), lifeVersion);
if (notification != null) {
notification.onBlobReplicaUndeleted(currentNode.getHostname(), currentNode.getPort(), convertedStoreKey.getID(), BlobReplicaSourceType.PRIMARY);
}
}
} catch (StoreException e) {
boolean logInErrorLevel = false;
if (e.getErrorCode() == StoreErrorCodes.ID_Not_Found) {
metrics.idNotFoundError.inc();
} else if (e.getErrorCode() == StoreErrorCodes.TTL_Expired) {
metrics.ttlExpiredError.inc();
} else if (e.getErrorCode() == StoreErrorCodes.ID_Deleted_Permanently) {
metrics.idDeletedError.inc();
} else if (e.getErrorCode() == StoreErrorCodes.Life_Version_Conflict) {
metrics.lifeVersionConflictError.inc();
} else if (e.getErrorCode() == StoreErrorCodes.ID_Not_Deleted) {
metrics.idNotDeletedError.inc();
} else if (e.getErrorCode() == StoreErrorCodes.ID_Undeleted) {
metrics.idUndeletedError.inc();
} else if (e.getErrorCode() == StoreErrorCodes.Authorization_Failure) {
metrics.undeleteAuthorizationFailure.inc();
} else {
logInErrorLevel = true;
metrics.unExpectedStoreUndeleteError.inc();
}
if (logInErrorLevel) {
logger.error("Store exception on a undelete with error code {} for request {}", e.getErrorCode(), undeleteRequest, e);
} else {
logger.trace("Store exception on a undelete with error code {} for request {}", e.getErrorCode(), undeleteRequest, e);
}
if (e.getErrorCode() == StoreErrorCodes.ID_Undeleted) {
if (e instanceof IdUndeletedStoreException) {
response = new UndeleteResponse(undeleteRequest.getCorrelationId(), undeleteRequest.getClientId(), ((IdUndeletedStoreException) e).getLifeVersion(), ServerErrorCode.Blob_Already_Undeleted);
} else {
response = new UndeleteResponse(undeleteRequest.getCorrelationId(), undeleteRequest.getClientId(), MessageInfo.LIFE_VERSION_FROM_FRONTEND, ServerErrorCode.Blob_Already_Undeleted);
}
} else {
response = new UndeleteResponse(undeleteRequest.getCorrelationId(), undeleteRequest.getClientId(), ErrorMapping.getStoreErrorMapping(e.getErrorCode()));
}
} catch (Exception e) {
logger.error("Unknown exception for undelete request {}", undeleteRequest, e);
response = new UndeleteResponse(undeleteRequest.getCorrelationId(), undeleteRequest.getClientId(), ServerErrorCode.Unknown_Error);
metrics.unExpectedStoreUndeleteError.inc();
} finally {
long processingTime = SystemTime.getInstance().milliseconds() - startTime;
totalTimeSpent += processingTime;
publicAccessLogger.info("{} {} processingTime {}", undeleteRequest, response, processingTime);
metrics.undeleteBlobProcessingTimeInMs.update(processingTime);
}
requestResponseChannel.sendResponse(response, request, new ServerNetworkResponseMetrics(metrics.undeleteBlobResponseQueueTimeInMs, metrics.undeleteBlobSendTimeInMs, metrics.undeleteBlobTotalTimeInMs, null, null, totalTimeSpent));
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class RequestResponseTest method catchupStatusAdminRequestTest.
/**
* Tests the ser/de of {@link CatchupStatusAdminRequest} and checks for equality of fields with reference data.
* @throws IOException
*/
@Test
public void catchupStatusAdminRequestTest() throws IOException {
MockClusterMap clusterMap = new MockClusterMap();
PartitionId id = clusterMap.getWritablePartitionIds(MockClusterMap.DEFAULT_PARTITION_CLASS).get(0);
int correlationId = 1234;
String clientId = "client";
// request
long acceptableLag = Utils.getRandomLong(TestUtils.RANDOM, 10000);
short numCaughtUpPerPartition = Utils.getRandomShort(TestUtils.RANDOM);
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.CatchupStatus, id, correlationId, clientId);
CatchupStatusAdminRequest catchupStatusRequest = new CatchupStatusAdminRequest(acceptableLag, numCaughtUpPerPartition, adminRequest);
DataInputStream requestStream = serAndPrepForRead(catchupStatusRequest, -1, true);
AdminRequest deserializedAdminRequest = deserAdminRequestAndVerify(requestStream, clusterMap, correlationId, clientId, AdminRequestOrResponseType.CatchupStatus, id);
CatchupStatusAdminRequest deserializedCatchupStatusRequest = CatchupStatusAdminRequest.readFrom(requestStream, deserializedAdminRequest);
Assert.assertEquals("Acceptable lag not as set", acceptableLag, deserializedCatchupStatusRequest.getAcceptableLagInBytes());
Assert.assertEquals("Num caught up per partition not as set", numCaughtUpPerPartition, deserializedCatchupStatusRequest.getNumReplicasCaughtUpPerPartition());
catchupStatusRequest.release();
// response
boolean isCaughtUp = TestUtils.RANDOM.nextBoolean();
ServerErrorCode[] values = ServerErrorCode.values();
int indexToPick = TestUtils.RANDOM.nextInt(values.length);
ServerErrorCode responseErrorCode = values[indexToPick];
AdminResponse adminResponse = new AdminResponse(correlationId, clientId, responseErrorCode);
CatchupStatusAdminResponse catchupStatusResponse = new CatchupStatusAdminResponse(isCaughtUp, adminResponse);
DataInputStream responseStream = serAndPrepForRead(catchupStatusResponse, -1, false);
CatchupStatusAdminResponse deserializedCatchupStatusResponse = CatchupStatusAdminResponse.readFrom(responseStream);
Assert.assertEquals(deserializedCatchupStatusResponse.getCorrelationId(), correlationId);
Assert.assertEquals(deserializedCatchupStatusResponse.getClientId(), clientId);
Assert.assertEquals(deserializedCatchupStatusResponse.getError(), responseErrorCode);
Assert.assertEquals(deserializedCatchupStatusResponse.isCaughtUp(), isCaughtUp);
catchupStatusResponse.release();
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class RequestResponseTest method adminRequestResponseTest.
/**
* Tests the ser/de of {@link AdminRequest} and {@link AdminResponse} and checks for equality of fields with
* reference data.
* @throws IOException
*/
@Test
public void adminRequestResponseTest() throws IOException {
int correlationId = 1234;
String clientId = "client";
for (AdminRequestOrResponseType type : AdminRequestOrResponseType.values()) {
MockClusterMap clusterMap = new MockClusterMap();
PartitionId id = clusterMap.getWritablePartitionIds(MockClusterMap.DEFAULT_PARTITION_CLASS).get(0);
// with a valid partition id
AdminRequest adminRequest = new AdminRequest(type, id, correlationId, clientId);
DataInputStream requestStream = serAndPrepForRead(adminRequest, -1, true);
deserAdminRequestAndVerify(requestStream, clusterMap, correlationId, clientId, type, id);
adminRequest.release();
// with a null partition id
adminRequest = new AdminRequest(type, null, correlationId, clientId);
requestStream = serAndPrepForRead(adminRequest, -1, true);
deserAdminRequestAndVerify(requestStream, clusterMap, correlationId, clientId, type, null);
adminRequest.release();
// response
ServerErrorCode[] values = ServerErrorCode.values();
int indexToPick = TestUtils.RANDOM.nextInt(values.length);
ServerErrorCode responseErrorCode = values[indexToPick];
AdminResponse response = new AdminResponse(correlationId, clientId, responseErrorCode);
DataInputStream responseStream = serAndPrepForRead(response, -1, false);
AdminResponse deserializedAdminResponse = AdminResponse.readFrom(responseStream);
Assert.assertEquals(deserializedAdminResponse.getCorrelationId(), correlationId);
Assert.assertEquals(deserializedAdminResponse.getClientId(), clientId);
Assert.assertEquals(deserializedAdminResponse.getError(), responseErrorCode);
response.release();
}
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class PutResponse method readFrom.
public static PutResponse readFrom(DataInputStream stream) throws IOException {
RequestOrResponseType type = RequestOrResponseType.values()[stream.readShort()];
if (type != RequestOrResponseType.PutResponse) {
throw new IllegalArgumentException("The type of request response is not compatible: " + type);
}
Short versionId = stream.readShort();
int correlationId = stream.readInt();
String clientId = Utils.readIntString(stream);
ServerErrorCode error = ServerErrorCode.values()[stream.readShort()];
// ignore version for now
return new PutResponse(correlationId, clientId, error);
}
Aggregations