Search in sources :

Example 31 with RequestInfo

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

the class Http2ClientResponseHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg) {
    ByteBuf dup = msg.content().retainedDuplicate();
    // Consume length
    dup.readLong();
    RequestInfo requestInfo = ctx.channel().attr(Http2NetworkClient.REQUEST_INFO).get();
    if (requestInfo != null) {
        // A request maybe just dropped by Http2NetworkClient.
        http2ClientMetrics.http2StreamFirstToAllFrameReadyTime.update(System.currentTimeMillis() - requestInfo.getStreamHeaderFrameReceiveTime());
        ResponseInfo responseInfo = new ResponseInfo(requestInfo, null, dup);
        responseInfoQueue.put(responseInfo);
        releaseAndCloseStreamChannel(ctx.channel());
    }
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) ByteBuf(io.netty.buffer.ByteBuf) RequestInfo(com.github.ambry.network.RequestInfo)

Example 32 with RequestInfo

use of com.github.ambry.network.RequestInfo 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)

Example 33 with RequestInfo

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

the class TtlUpdateManager method handleResponse.

/**
 * Handles responses received for each of the {@link TtlUpdateOperation} within this TtlUpdateManager.
 * @param responseInfo the {@link ResponseInfo} containing the response.
 */
void handleResponse(ResponseInfo responseInfo) {
    long startTime = time.milliseconds();
    TtlUpdateResponse ttlUpdateResponse = RouterUtils.extractResponseAndNotifyResponseHandler(responseHandler, routerMetrics, responseInfo, TtlUpdateResponse::readFrom, TtlUpdateResponse::getError);
    RequestInfo routerRequestInfo = responseInfo.getRequestInfo();
    int correlationId = ((TtlUpdateRequest) routerRequestInfo.getRequest()).getCorrelationId();
    TtlUpdateOperation ttlUpdateOperation = correlationIdToTtlUpdateOperation.remove(correlationId);
    // If it is still an active operation, hand over the response. Otherwise, ignore.
    if (ttlUpdateOperations.contains(ttlUpdateOperation)) {
        boolean exceptionEncountered = false;
        try {
            ttlUpdateOperation.handleResponse(responseInfo, ttlUpdateResponse);
        } catch (Exception e) {
            exceptionEncountered = true;
            ttlUpdateOperation.setOperationException(new RouterException("TTLUpdate handleResponse encountered unexpected error", e, RouterErrorCode.UnexpectedInternalError));
        }
        if (exceptionEncountered || ttlUpdateOperation.isOperationComplete()) {
            if (ttlUpdateOperations.remove(ttlUpdateOperation)) {
                onComplete(ttlUpdateOperation);
            }
        }
        routerMetrics.ttlUpdateManagerHandleResponseTimeMs.update(time.milliseconds() - startTime);
    } else {
        routerMetrics.ignoredResponseCount.inc();
    }
}
Also used : TtlUpdateResponse(com.github.ambry.protocol.TtlUpdateResponse) TtlUpdateRequest(com.github.ambry.protocol.TtlUpdateRequest) RequestInfo(com.github.ambry.network.RequestInfo)

Example 34 with RequestInfo

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

the class UndeleteManager method handleResponse.

/**
 * Handles responses received for each of the {@link UndeleteOperation} within this UndeleteManager.
 * @param responseInfo the {@link ResponseInfo} containing the response.
 */
void handleResponse(ResponseInfo responseInfo) {
    long startTime = time.milliseconds();
    UndeleteResponse undeleteResponse = RouterUtils.extractResponseAndNotifyResponseHandler(responseHandler, routerMetrics, responseInfo, UndeleteResponse::readFrom, UndeleteResponse::getError);
    RequestInfo routerRequestInfo = responseInfo.getRequestInfo();
    int correlationId = routerRequestInfo.getRequest().getCorrelationId();
    UndeleteOperation undeleteOperation = correlationIdToUndeleteOperation.remove(correlationId);
    // If it is still an active operation, hand over the response. Otherwise, ignore.
    if (undeleteOperations.contains(undeleteOperation)) {
        boolean exceptionEncountered = false;
        try {
            undeleteOperation.handleResponse(responseInfo, undeleteResponse);
        } catch (Exception e) {
            exceptionEncountered = true;
            undeleteOperation.setOperationException(new RouterException("Undelete handleResponse encountered unexpected error", e, RouterErrorCode.UnexpectedInternalError));
        }
        if (exceptionEncountered || undeleteOperation.isOperationComplete()) {
            if (undeleteOperations.remove(undeleteOperation)) {
                onComplete(undeleteOperation);
            }
        }
        routerMetrics.undeleteManagerHandleResponseTimeMs.update(time.milliseconds() - startTime);
    } else {
        routerMetrics.ignoredResponseCount.inc();
    }
}
Also used : UndeleteResponse(com.github.ambry.protocol.UndeleteResponse) RequestInfo(com.github.ambry.network.RequestInfo)

Example 35 with RequestInfo

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

the class QuotaAwareOperationController method pollQuotaExceedAllowedRequestsIfAny.

/**
 * Poll for out of quota requests that are allowed to exceed quota.
 * @param requestsToSend {@link List} of {@link RequestInfo} to be sent.
 * @param requestQueue {@link Map} of {@link QuotaResource} to {@link List} of {@link RequestInfo} from which the requests to be sent will be polled.
 */
private void pollQuotaExceedAllowedRequestsIfAny(List<RequestInfo> requestsToSend, Map<QuotaResource, LinkedList<RequestInfo>> requestQueue) {
    List<QuotaResource> quotaResources = new ArrayList<>(requestQueue.keySet());
    Collections.shuffle(quotaResources);
    while (!requestQueue.isEmpty()) {
        for (QuotaResource quotaResource : quotaResources) {
            RequestInfo requestInfo = requestQueue.get(quotaResource).getFirst();
            if (!requestInfo.getChargeable().quotaExceedAllowed()) {
                // If quota exceeded requests aren't allowed, then there is nothing more to do.
                return;
            }
            requestInfo.getChargeable().charge();
            requestsToSend.add(requestInfo);
            requestQueue.get(quotaResource).removeFirst();
            if (requestQueue.get(quotaResource).isEmpty()) {
                requestQueue.remove(quotaResource);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) QuotaResource(com.github.ambry.quota.QuotaResource) RequestInfo(com.github.ambry.network.RequestInfo)

Aggregations

RequestInfo (com.github.ambry.network.RequestInfo)45 ResponseInfo (com.github.ambry.network.ResponseInfo)31 ArrayList (java.util.ArrayList)22 Test (org.junit.Test)14 GetResponse (com.github.ambry.protocol.GetResponse)12 PartitionRequestInfo (com.github.ambry.protocol.PartitionRequestInfo)11 PutResponse (com.github.ambry.protocol.PutResponse)10 ReplicaId (com.github.ambry.clustermap.ReplicaId)8 BlobId (com.github.ambry.commons.BlobId)8 Port (com.github.ambry.network.Port)8 PartitionResponseInfo (com.github.ambry.protocol.PartitionResponseInfo)7 BlobProperties (com.github.ambry.messageformat.BlobProperties)6 TtlUpdateResponse (com.github.ambry.protocol.TtlUpdateResponse)6 NettyByteBufDataInputStream (com.github.ambry.utils.NettyByteBufDataInputStream)6 DataInputStream (java.io.DataInputStream)6 DeleteResponse (com.github.ambry.protocol.DeleteResponse)5 GetRequest (com.github.ambry.protocol.GetRequest)5 UndeleteResponse (com.github.ambry.protocol.UndeleteResponse)5 InMemAccountService (com.github.ambry.account.InMemAccountService)4 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)4