Search in sources :

Example 31 with ServerErrorCode

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);
    }
}
Also used : ArrayList(java.util.ArrayList) ServerErrorCode(com.github.ambry.server.ServerErrorCode)

Example 32 with ServerErrorCode

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);
}
Also used : ServerErrorCode(com.github.ambry.server.ServerErrorCode)

Example 33 with ServerErrorCode

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);
}
Also used : ServerErrorCode(com.github.ambry.server.ServerErrorCode)

Example 34 with ServerErrorCode

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)));
    }
}
Also used : MessageMetadata(com.github.ambry.messageformat.MessageMetadata) PartitionResponseInfo(com.github.ambry.protocol.PartitionResponseInfo) ServerErrorCode(com.github.ambry.server.ServerErrorCode) MessageInfo(com.github.ambry.store.MessageInfo)

Example 35 with ServerErrorCode

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();
    }
}
Also used : GetRequest(com.github.ambry.protocol.GetRequest) RequestInfo(com.github.ambry.network.RequestInfo) GetResponse(com.github.ambry.protocol.GetResponse) ServerErrorCode(com.github.ambry.server.ServerErrorCode) IOException(java.io.IOException)

Aggregations

ServerErrorCode (com.github.ambry.server.ServerErrorCode)56 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)20 DataInputStream (java.io.DataInputStream)16 BlobProperties (com.github.ambry.messageformat.BlobProperties)12 IOException (java.io.IOException)11 HashMap (java.util.HashMap)11 BlobId (com.github.ambry.commons.BlobId)10 VerifiableProperties (com.github.ambry.config.VerifiableProperties)10 MessageFormatException (com.github.ambry.messageformat.MessageFormatException)9 NettyByteBufDataInputStream (com.github.ambry.utils.NettyByteBufDataInputStream)9 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)8 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)8 RouterConfig (com.github.ambry.config.RouterConfig)8 Map (java.util.Map)8 Properties (java.util.Properties)8 DataNodeId (com.github.ambry.clustermap.DataNodeId)7 PartitionId (com.github.ambry.clustermap.PartitionId)7 MessageInfo (com.github.ambry.store.MessageInfo)7 IdUndeletedStoreException (com.github.ambry.store.IdUndeletedStoreException)6