use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class ReplicaMetadataResponse method readFrom.
public static ReplicaMetadataResponse readFrom(DataInputStream stream, FindTokenHelper helper, ClusterMap clusterMap) throws IOException {
RequestOrResponseType type = RequestOrResponseType.values()[stream.readShort()];
if (type != RequestOrResponseType.ReplicaMetadataResponse) {
throw new IllegalArgumentException("The type of request response is not compatible");
}
Short versionId = stream.readShort();
int correlationId = stream.readInt();
String clientId = Utils.readIntString(stream);
ServerErrorCode error = ServerErrorCode.values()[stream.readShort()];
int replicaMetadataResponseInfoListCount = stream.readInt();
ArrayList<ReplicaMetadataResponseInfo> replicaMetadataResponseInfoList = new ArrayList<ReplicaMetadataResponseInfo>(replicaMetadataResponseInfoListCount);
for (int i = 0; i < replicaMetadataResponseInfoListCount; i++) {
ReplicaMetadataResponseInfo replicaMetadataResponseInfo = ReplicaMetadataResponseInfo.readFrom(stream, helper, clusterMap, versionId);
replicaMetadataResponseInfoList.add(replicaMetadataResponseInfo);
}
if (error != ServerErrorCode.No_Error) {
return new ReplicaMetadataResponse(correlationId, clientId, error, versionId);
} else {
return new ReplicaMetadataResponse(correlationId, clientId, error, replicaMetadataResponseInfoList, versionId);
}
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class TtlUpdateResponse method readFrom.
/**
* Helper to help construct TtlUpdateResponse from the {@code stream}.
* @param stream the stream to read bytes from
* @return a TtlUpdateResponse based on data read from the {@code stream}
* @throws IOException if there was any problem reading the stream
*/
public static TtlUpdateResponse readFrom(DataInputStream stream) throws IOException {
RequestOrResponseType type = RequestOrResponseType.values()[stream.readShort()];
if (type != RequestOrResponseType.TtlUpdateResponse) {
throw new IllegalArgumentException("The type of request response is not compatible");
}
short version = stream.readShort();
if (version != TTL_UPDATE_RESPONSE_VERSION_V1) {
throw new IllegalStateException("Unknown TtlUpdateResponse version: " + version);
}
int correlationId = stream.readInt();
String clientId = Utils.readIntString(stream);
ServerErrorCode error = ServerErrorCode.values()[stream.readShort()];
return new TtlUpdateResponse(correlationId, clientId, error);
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class UndeleteResponse method readFrom.
public static UndeleteResponse readFrom(DataInputStream stream) throws IOException {
RequestOrResponseType type = RequestOrResponseType.values()[stream.readShort()];
if (type != RequestOrResponseType.UndeleteResponse) {
throw new IllegalArgumentException("The type of request response is not compatible");
}
Short versionId = stream.readShort();
if (versionId != UNDELETE_RESPONSE_VERSION_1) {
throw new IllegalArgumentException("Unknown version from stream " + versionId);
}
int correlationId = stream.readInt();
String clientId = Utils.readIntString(stream);
ServerErrorCode error = ServerErrorCode.values()[stream.readShort()];
short lifeVersion = stream.readShort();
return new UndeleteResponse(correlationId, clientId, lifeVersion, error);
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class GetBlobInfoOperation method processGetBlobInfoResponse.
/**
* Process the {@link GetResponse} extracted from a {@link ResponseInfo}
* @param getRequestInfo the associated {@link GetRequestInfo} for which this response was received.
* @param getResponse the {@link GetResponse} extracted from the {@link ResponseInfo}
* @throws IOException if there is an error during deserialization of the GetResponse.
* @throws MessageFormatException if there is an error during deserialization of the GetResponse.
*/
private void processGetBlobInfoResponse(GetRequestInfo getRequestInfo, GetResponse getResponse) throws IOException, MessageFormatException {
ServerErrorCode getError = getResponse.getError();
if (getError == ServerErrorCode.No_Error) {
int partitionsInResponse = getResponse.getPartitionResponseInfoList().size();
// Each get request issued by the router is for a single blob.
if (partitionsInResponse != 1) {
onErrorResponse(getRequestInfo.replicaId, new RouterException("Unexpected number of partition responses, expected: 1, " + "received: " + partitionsInResponse, RouterErrorCode.UnexpectedInternalError));
// Again, no need to notify the responseHandler.
} else {
getError = getResponse.getPartitionResponseInfoList().get(0).getErrorCode();
if (getError == ServerErrorCode.No_Error) {
PartitionResponseInfo partitionResponseInfo = getResponse.getPartitionResponseInfoList().get(0);
int msgsInResponse = partitionResponseInfo.getMessageInfoList().size();
if (msgsInResponse != 1) {
onErrorResponse(getRequestInfo.replicaId, new RouterException("Unexpected number of messages in a partition response, expected: 1, " + "received: " + msgsInResponse, RouterErrorCode.UnexpectedInternalError));
} else {
MessageMetadata messageMetadata = partitionResponseInfo.getMessageMetadataList().get(0);
MessageInfo messageInfo = partitionResponseInfo.getMessageInfoList().get(0);
handleBody(getResponse.getInputStream(), messageMetadata, messageInfo);
operationTracker.onResponse(getRequestInfo.replicaId, TrackedRequestFinalState.SUCCESS);
if (RouterUtils.isRemoteReplica(routerConfig, getRequestInfo.replicaId)) {
logger.trace("Cross colo request successful for remote replica in {} ", getRequestInfo.replicaId.getDataNodeId().getDatacenterName());
routerMetrics.crossColoSuccessCount.inc();
}
}
} else {
// process and set the most relevant exception.
logger.trace("Replica {} returned error {} with response correlationId {} ", getRequestInfo.replicaId.getDataNodeId(), getError, getResponse.getCorrelationId());
RouterErrorCode routerErrorCode = processServerError(getError);
if (getError == ServerErrorCode.Disk_Unavailable) {
operationTracker.onResponse(getRequestInfo.replicaId, TrackedRequestFinalState.DISK_DOWN);
setOperationException(new RouterException("Server returned: " + getError, routerErrorCode));
routerMetrics.routerRequestErrorCount.inc();
routerMetrics.getDataNodeBasedMetrics(getRequestInfo.replicaId.getDataNodeId()).getBlobInfoRequestErrorCount.inc();
} else {
if (getError == ServerErrorCode.Blob_Deleted || getError == ServerErrorCode.Blob_Expired || getError == ServerErrorCode.Blob_Authorization_Failure) {
// this is a successful response and one that completes the operation regardless of whether the
// success target has been reached or not.
operationCompleted = true;
}
// any server error code that is not equal to ServerErrorCode.No_Error, the onErrorResponse should be invoked
// because the operation itself doesn't succeed although the response in some cases is successful (i.e. Blob_Deleted)
onErrorResponse(getRequestInfo.replicaId, new RouterException("Server returned: " + getError, routerErrorCode));
}
}
}
} else {
logger.trace("Replica {} returned an error {} for a GetBlobInfoRequest with response correlationId : {} ", getRequestInfo.replicaId.getDataNodeId(), getError, getResponse.getCorrelationId());
onErrorResponse(getRequestInfo.replicaId, new RouterException("Server returned", processServerError(getError)));
}
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class GetBlobResultInternal method handleResponse.
/**
* Hands over the response to the associated GetOperation that issued the request.
* @param responseInfo the {@link ResponseInfo} containing the response.
*/
void handleResponse(ResponseInfo responseInfo) {
long startTime = time.milliseconds();
GetResponse getResponse = RouterUtils.extractResponseAndNotifyResponseHandler(responseHandler, routerMetrics, responseInfo, stream -> GetResponse.readFrom(stream, clusterMap), response -> {
ServerErrorCode serverError = response.getError();
if (serverError == ServerErrorCode.No_Error) {
serverError = response.getPartitionResponseInfoList().get(0).getErrorCode();
}
return serverError;
});
RequestInfo routerRequestInfo = responseInfo.getRequestInfo();
GetRequest getRequest = (GetRequest) routerRequestInfo.getRequest();
GetOperation getOperation = correlationIdToGetOperation.remove(getRequest.getCorrelationId());
if (getOperation != null && getOperations.contains(getOperation)) {
try {
getOperation.handleResponse(responseInfo, getResponse);
if (getOperation.isOperationComplete()) {
remove(getOperation);
}
} catch (Exception e) {
removeAndAbort(getOperation, new RouterException("Get handleResponse encountered unexpected error", e, RouterErrorCode.UnexpectedInternalError));
}
routerMetrics.getManagerHandleResponseTimeMs.update(time.milliseconds() - startTime);
} else {
routerMetrics.ignoredResponseCount.inc();
}
}
Aggregations