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