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());
}
}
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();
}
}
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();
}
}
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();
}
}
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);
}
}
}
}
Aggregations