Search in sources :

Example 1 with NetworkClientErrorCode

use of com.github.ambry.network.NetworkClientErrorCode in project ambry by linkedin.

the class DeleteManager method extractDeleteResponseAndNotifyResponseHandler.

/**
 * Extract the {@link DeleteResponse} from the given {@link ResponseInfo}
 * @param responseInfo the {@link ResponseInfo} from which the {@link DeleteResponse} is to be extracted.
 * @return the extracted {@link DeleteResponse} if there is one; null otherwise.
 */
private DeleteResponse extractDeleteResponseAndNotifyResponseHandler(ResponseInfo responseInfo) {
    DeleteResponse deleteResponse = null;
    ReplicaId replicaId = ((RouterRequestInfo) responseInfo.getRequestInfo()).getReplicaId();
    NetworkClientErrorCode networkClientErrorCode = responseInfo.getError();
    if (networkClientErrorCode == null) {
        try {
            deleteResponse = DeleteResponse.readFrom(new DataInputStream(new ByteBufferInputStream(responseInfo.getResponse())));
            responseHandler.onEvent(replicaId, deleteResponse.getError());
        } catch (Exception e) {
            // Ignore. There is no value in notifying the response handler.
            logger.error("Response deserialization received unexpected error", e);
            routerMetrics.responseDeserializationErrorCount.inc();
        }
    } else {
        responseHandler.onEvent(replicaId, networkClientErrorCode);
    }
    return deleteResponse;
}
Also used : DeleteResponse(com.github.ambry.protocol.DeleteResponse) NetworkClientErrorCode(com.github.ambry.network.NetworkClientErrorCode) ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) DataInputStream(java.io.DataInputStream) ReplicaId(com.github.ambry.clustermap.ReplicaId)

Example 2 with NetworkClientErrorCode

use of com.github.ambry.network.NetworkClientErrorCode in project ambry by linkedin.

the class GetBlobResultInternal method extractGetResponseAndNotifyResponseHandler.

/**
 * Extract the {@link GetResponse} from the given {@link ResponseInfo}
 * @param responseInfo the {@link ResponseInfo} from which the {@link GetResponse} is to be extracted.
 * @return the extracted {@link GetResponse} if there is one; null otherwise.
 */
private GetResponse extractGetResponseAndNotifyResponseHandler(ResponseInfo responseInfo) {
    GetResponse getResponse = null;
    ReplicaId replicaId = ((RouterRequestInfo) responseInfo.getRequestInfo()).getReplicaId();
    NetworkClientErrorCode networkClientErrorCode = responseInfo.getError();
    if (networkClientErrorCode == null) {
        try {
            getResponse = GetResponse.readFrom(new DataInputStream(new ByteBufferInputStream(responseInfo.getResponse())), clusterMap);
            ServerErrorCode serverError = getResponse.getError();
            if (serverError == ServerErrorCode.No_Error) {
                serverError = getResponse.getPartitionResponseInfoList().get(0).getErrorCode();
            }
            responseHandler.onEvent(replicaId, serverError);
        } catch (Exception e) {
            // Ignore. There is no value in notifying the response handler.
            logger.error("Response deserialization received unexpected error", e);
            routerMetrics.responseDeserializationErrorCount.inc();
        }
    } else {
        responseHandler.onEvent(replicaId, networkClientErrorCode);
    }
    return getResponse;
}
Also used : NetworkClientErrorCode(com.github.ambry.network.NetworkClientErrorCode) ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) DataInputStream(java.io.DataInputStream) GetResponse(com.github.ambry.protocol.GetResponse) ReplicaId(com.github.ambry.clustermap.ReplicaId) ServerErrorCode(com.github.ambry.commons.ServerErrorCode)

Example 3 with NetworkClientErrorCode

use of com.github.ambry.network.NetworkClientErrorCode in project ambry by linkedin.

the class PutManager method extractPutResponseAndNotifyResponseHandler.

/**
 * Extract the {@link PutResponse} from the given {@link ResponseInfo}
 * @param responseInfo the {@link ResponseInfo} from which the {@link PutResponse} is to be extracted.
 * @return the extracted {@link PutResponse} if there is one; null otherwise.
 */
private PutResponse extractPutResponseAndNotifyResponseHandler(ResponseInfo responseInfo) {
    PutResponse putResponse = null;
    ReplicaId replicaId = ((RouterRequestInfo) responseInfo.getRequestInfo()).getReplicaId();
    NetworkClientErrorCode networkClientErrorCode = responseInfo.getError();
    if (networkClientErrorCode == null) {
        try {
            putResponse = PutResponse.readFrom(new DataInputStream(new ByteBufferInputStream(responseInfo.getResponse())));
            responseHandler.onEvent(replicaId, putResponse.getError());
        } catch (Exception e) {
            // Ignore. There is no value in notifying the response handler.
            logger.error("Response deserialization received unexpected error", e);
            routerMetrics.responseDeserializationErrorCount.inc();
        }
    } else {
        responseHandler.onEvent(replicaId, networkClientErrorCode);
    }
    return putResponse;
}
Also used : NetworkClientErrorCode(com.github.ambry.network.NetworkClientErrorCode) ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) PutResponse(com.github.ambry.protocol.PutResponse) DataInputStream(java.io.DataInputStream) ReplicaId(com.github.ambry.clustermap.ReplicaId)

Example 4 with NetworkClientErrorCode

use of com.github.ambry.network.NetworkClientErrorCode in project ambry by linkedin.

the class RouterUtils method extractResponseAndNotifyResponseHandler.

/**
 * Extract the {@link Response} from the given {@link ResponseInfo}
 * @param <R> the {@link Response} type.
 * @param responseHandler the {@link ResponseHandler} instance to use.
 * @param routerMetrics the {@link NonBlockingRouterMetrics} instance to use.
 * @param responseInfo the {@link ResponseInfo} from which the {@link Response} is to be extracted.
 * @param deserializer the {@link Deserializer} to use.
 * @param errorExtractor extract the {@link ServerErrorCode} to send to {@link ResponseHandler#onEvent}.
 * @return the extracted {@link Response} if there is one; null otherwise.
 */
@SuppressWarnings("unchecked")
static <R extends Response> R extractResponseAndNotifyResponseHandler(ResponseHandler responseHandler, NonBlockingRouterMetrics routerMetrics, ResponseInfo responseInfo, Deserializer<R> deserializer, Function<R, ServerErrorCode> errorExtractor) {
    R response = null;
    ReplicaId replicaId = responseInfo.getRequestInfo().getReplicaId();
    NetworkClientErrorCode networkClientErrorCode = responseInfo.getError();
    if (networkClientErrorCode == null) {
        try {
            if (responseInfo.getResponse() != null) {
                // If this responseInfo already has the deserialized java object, we can reference it directly. This is
                // applicable when we are receiving responses from Azure APIs in frontend. The responses from Azure are
                // handled in {@code AmbryRequest} class methods using a thread pool running with in the frontend. These
                // responses are then sent using local queues in {@code LocalRequestResponseChannel}.
                response = (R) mapToReceivedResponse((Response) responseInfo.getResponse());
            } else {
                DataInputStream dis = new NettyByteBufDataInputStream(responseInfo.content());
                response = deserializer.readFrom(dis);
            }
            responseHandler.onEvent(replicaId, errorExtractor.apply(response));
        } catch (Exception e) {
            // Ignore. There is no value in notifying the response handler.
            logger.error("Response deserialization received unexpected error", e);
            routerMetrics.responseDeserializationErrorCount.inc();
        }
    } else {
        responseHandler.onEvent(replicaId, networkClientErrorCode);
    }
    return response;
}
Also used : NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) NetworkClientErrorCode(com.github.ambry.network.NetworkClientErrorCode) DataInputStream(java.io.DataInputStream) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) ReplicaId(com.github.ambry.clustermap.ReplicaId) IOException(java.io.IOException)

Aggregations

ReplicaId (com.github.ambry.clustermap.ReplicaId)4 NetworkClientErrorCode (com.github.ambry.network.NetworkClientErrorCode)4 DataInputStream (java.io.DataInputStream)4 ByteBufferInputStream (com.github.ambry.utils.ByteBufferInputStream)3 ServerErrorCode (com.github.ambry.commons.ServerErrorCode)1 DeleteResponse (com.github.ambry.protocol.DeleteResponse)1 GetResponse (com.github.ambry.protocol.GetResponse)1 PutResponse (com.github.ambry.protocol.PutResponse)1 NettyByteBufDataInputStream (com.github.ambry.utils.NettyByteBufDataInputStream)1 IOException (java.io.IOException)1