Search in sources :

Example 11 with RequestInfo

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

the class DeleteOperation method fetchRequests.

/**
 * Fetch {@link DeleteRequest}s to send for the operation.
 */
private void fetchRequests(RequestRegistrationCallback<DeleteOperation> requestRegistrationCallback) {
    Iterator<ReplicaId> replicaIterator = operationTracker.getReplicaIterator();
    while (replicaIterator.hasNext()) {
        ReplicaId replica = replicaIterator.next();
        String hostname = replica.getDataNodeId().getHostname();
        Port port = RouterUtils.getPortToConnectTo(replica, routerConfig.routerEnableHttp2NetworkClient);
        DeleteRequest deleteRequest = createDeleteRequest();
        deleteRequestInfos.put(deleteRequest.getCorrelationId(), new DeleteRequestInfo(time.milliseconds(), replica));
        RequestInfo requestInfo = new RequestInfo(hostname, port, deleteRequest, replica, operationQuotaCharger);
        requestRegistrationCallback.registerRequestToSend(this, requestInfo);
        replicaIterator.remove();
        if (RouterUtils.isRemoteReplica(routerConfig, replica)) {
            logger.trace("Making request with correlationId {} to a remote replica {} in {} ", deleteRequest.getCorrelationId(), replica.getDataNodeId(), replica.getDataNodeId().getDatacenterName());
            routerMetrics.crossColoRequestCount.inc();
        } else {
            logger.trace("Making request with correlationId {} to a local replica {} ", deleteRequest.getCorrelationId(), replica.getDataNodeId());
        }
        routerMetrics.getDataNodeBasedMetrics(replica.getDataNodeId()).deleteRequestRate.mark();
    }
}
Also used : Port(com.github.ambry.network.Port) RequestInfo(com.github.ambry.network.RequestInfo) DeleteRequest(com.github.ambry.protocol.DeleteRequest) ReplicaId(com.github.ambry.clustermap.ReplicaId)

Example 12 with RequestInfo

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

the class GetBlobInfoOperation method fetchRequests.

/**
 * Fetch {@link GetRequest}s to send for the operation.
 */
private void fetchRequests(RequestRegistrationCallback<GetOperation> requestRegistrationCallback) {
    Iterator<ReplicaId> replicaIterator = operationTracker.getReplicaIterator();
    while (replicaIterator.hasNext()) {
        ReplicaId replicaId = replicaIterator.next();
        String hostname = replicaId.getDataNodeId().getHostname();
        Port port = RouterUtils.getPortToConnectTo(replicaId, routerConfig.routerEnableHttp2NetworkClient);
        GetRequest getRequest = createGetRequest(blobId, getOperationFlag(), options.getBlobOptions.getGetOption());
        RequestInfo request = new RequestInfo(hostname, port, getRequest, replicaId, operationQuotaCharger);
        int correlationId = getRequest.getCorrelationId();
        correlationIdToGetRequestInfo.put(correlationId, new GetRequestInfo(replicaId, time.milliseconds()));
        requestRegistrationCallback.registerRequestToSend(this, request);
        replicaIterator.remove();
        if (RouterUtils.isRemoteReplica(routerConfig, replicaId)) {
            logger.trace("Making request with correlationId {} to a remote replica {} in {} ", correlationId, replicaId.getDataNodeId(), replicaId.getDataNodeId().getDatacenterName());
            routerMetrics.crossColoRequestCount.inc();
        } else {
            logger.trace("Making request with correlationId {} to a local replica {} ", correlationId, replicaId.getDataNodeId());
        }
        routerMetrics.getDataNodeBasedMetrics(replicaId.getDataNodeId()).getBlobInfoRequestRate.mark();
    }
}
Also used : Port(com.github.ambry.network.Port) GetRequest(com.github.ambry.protocol.GetRequest) RequestInfo(com.github.ambry.network.RequestInfo) ReplicaId(com.github.ambry.clustermap.ReplicaId)

Example 13 with RequestInfo

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

the class QuotaAwareOperationController method pollQuotaCompliantRequests.

/**
 * Drain the request queue based on resource quota only and update the requests to be sent to {@code requestsToSend}.
 * @param requestsToSend a list of {@link RequestInfo} that will contain the requests to be sent out.
 * @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 pollQuotaCompliantRequests(List<RequestInfo> requestsToSend, Map<QuotaResource, LinkedList<RequestInfo>> requestQueue) {
    for (QuotaResource quotaResource : requestQueue.keySet()) {
        if (quotaResource.equals(UNKNOWN_QUOTA_RESOURCE)) {
            // If there are requests for which QuotaResource couldn't be found, this is most likely a bug.
            // As a temporary hack, we will consider all those requests to be quota compliant.
            requestsToSend.addAll(requestQueue.get(UNKNOWN_QUOTA_RESOURCE));
            requestQueue.remove(UNKNOWN_QUOTA_RESOURCE);
            continue;
        }
        while (!requestQueue.get(quotaResource).isEmpty()) {
            RequestInfo requestInfo = requestQueue.get(quotaResource).getFirst();
            if (requestInfo.getChargeable().check()) {
                requestsToSend.add(requestInfo);
                requestQueue.get(quotaResource).removeFirst();
                requestInfo.getChargeable().charge();
            } else {
                break;
            }
        }
        if (requestQueue.get(quotaResource).isEmpty()) {
            requestQueue.remove(quotaResource);
        }
    }
}
Also used : QuotaResource(com.github.ambry.quota.QuotaResource) RequestInfo(com.github.ambry.network.RequestInfo)

Example 14 with RequestInfo

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

the class TtlUpdateOperation method fetchRequests.

/**
 * Fetch {@link TtlUpdateRequest}s to send for the operation.
 * @param requestRegistrationCallback the {@link RequestRegistrationCallback} to use for addition of requests that
 *                                    need to be sent to the storage server
 */
private void fetchRequests(RequestRegistrationCallback<TtlUpdateOperation> requestRegistrationCallback) {
    Iterator<ReplicaId> replicaIterator = operationTracker.getReplicaIterator();
    while (replicaIterator.hasNext()) {
        ReplicaId replica = replicaIterator.next();
        String hostname = replica.getDataNodeId().getHostname();
        Port port = RouterUtils.getPortToConnectTo(replica, routerConfig.routerEnableHttp2NetworkClient);
        TtlUpdateRequest ttlUpdateRequest = createTtlUpdateRequest();
        ttlUpdateRequestInfos.put(ttlUpdateRequest.getCorrelationId(), new TtlUpdateRequestInfo(time.milliseconds(), replica));
        RequestInfo requestInfo = new RequestInfo(hostname, port, ttlUpdateRequest, replica, operationQuotaCharger);
        requestRegistrationCallback.registerRequestToSend(this, requestInfo);
        replicaIterator.remove();
        if (RouterUtils.isRemoteReplica(routerConfig, replica)) {
            LOGGER.trace("Making request with correlationId {} to a remote replica {} in {} ", ttlUpdateRequest.getCorrelationId(), replica.getDataNodeId(), replica.getDataNodeId().getDatacenterName());
            routerMetrics.crossColoRequestCount.inc();
        } else {
            LOGGER.trace("Making request with correlationId {} to a local replica {} ", ttlUpdateRequest.getCorrelationId(), replica.getDataNodeId());
        }
        routerMetrics.getDataNodeBasedMetrics(replica.getDataNodeId()).ttlUpdateRequestRate.mark();
    }
}
Also used : Port(com.github.ambry.network.Port) TtlUpdateRequest(com.github.ambry.protocol.TtlUpdateRequest) RequestInfo(com.github.ambry.network.RequestInfo) ReplicaId(com.github.ambry.clustermap.ReplicaId)

Example 15 with RequestInfo

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

the class PutManager method handleResponse.

/**
 * Hands over the response to the associated PutOperation that issued the request.
 * @param responseInfo the {@link ResponseInfo} containing the response.
 */
void handleResponse(ResponseInfo responseInfo) {
    long startTime = time.milliseconds();
    PutResponse putResponse = RouterUtils.extractResponseAndNotifyResponseHandler(responseHandler, routerMetrics, responseInfo, PutResponse::readFrom, PutResponse::getError);
    RequestInfo routerRequestInfo = responseInfo.getRequestInfo();
    int correlationId = routerRequestInfo.getRequest().getCorrelationId();
    // Get the PutOperation that generated the request.
    PutOperation putOperation = correlationIdToPutOperation.remove(correlationId);
    // putOperation may be null if the operation was already completed in a previous event loop iteration.
    if (putOperation != null && putOperations.contains(putOperation)) {
        try {
            putOperation.handleResponse(responseInfo, putResponse);
        } catch (Exception e) {
            putOperation.setOperationExceptionAndComplete(new RouterException("Put handleResponse encountered unexpected error", e, RouterErrorCode.UnexpectedInternalError));
        }
        if (putOperation.isOperationComplete() && putOperations.remove(putOperation)) {
            onComplete(putOperation);
        }
        routerMetrics.putManagerHandleResponseTimeMs.update(time.milliseconds() - startTime);
    } else {
        logger.debug("Put operation not found in map for {} : {}", correlationId, putOperation);
        routerMetrics.ignoredResponseCount.inc();
    }
}
Also used : PutResponse(com.github.ambry.protocol.PutResponse) 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