in mcrouter/routes/DestinationRoute.h [135:204]
ReplyT<Request> checkAndRoute(const Request& req) const {
auto& ctx = fiber_local<RouterInfo>::getSharedCtx();
auto requestClass = fiber_local<RouterInfo>::getRequestClass();
bool isShadow = requestClass.is(RequestClass::kShadow);
auto proxy = &ctx->proxy();
// If not a shadow destination, check if the request deadline has exceeded
// If yes, return DeadlineExceeded reply
if (!isShadow && !disableRequestDeadlineCheck_ &&
isRequestDeadlineExceeded(req)) {
// Return remote error until all clients are updated to latest version
// And un-comment the following line for returning the correct response
// return constructAndLog(req, *ctx, DeadlineExceededReply);
return constructAndLog(
req,
*ctx,
RemoteErrorReply,
std::string("Failed to send request - deadline exceeded"));
}
carbon::Result tkoReason;
if (!destination_->maySend(tkoReason)) {
return constructAndLog(
req,
*ctx,
TkoReply,
folly::to<std::string>(
"Server unavailable. Reason: ",
carbon::resultToString(tkoReason)));
}
if (poolStatIndex_ >= 0) {
ctx->setPoolStatsIndex(poolStatIndex_);
}
if (ctx->recording()) {
ctx->recordDestination(
PoolContext{poolName_, indexInPool_, isShadow},
*destination_->accessPoint());
return constructAndLog(req, *ctx, DefaultReply, req);
}
if (isShadow) {
if ((proxy->router().opts().target_max_shadow_requests > 0 &&
pendingShadowReqs_ >=
proxy->router().opts().target_max_shadow_requests) ||
(proxy->router().opts().proxy_max_inflight_shadow_requests > 0 &&
proxy->stats().getValue(destination_inflight_shadow_reqs_stat) >=
proxy->router().opts().proxy_max_inflight_shadow_requests)) {
return constructAndLog(req, *ctx, ErrorReply);
}
auto& mutableCounter = const_cast<size_t&>(pendingShadowReqs_);
++mutableCounter;
proxy->stats().increment(destination_inflight_shadow_reqs_stat, 1);
proxy->stats().setValue(
destination_max_inflight_shadow_reqs_stat,
std::max(
proxy->stats().getValue(
destination_max_inflight_shadow_reqs_stat),
proxy->stats().getValue(destination_inflight_reqs_stat)));
}
SCOPE_EXIT {
if (isShadow) {
auto& mutableCounter = const_cast<size_t&>(pendingShadowReqs_);
--mutableCounter;
proxy->stats().decrement(destination_inflight_shadow_reqs_stat, 1);
}
};
return doRoute(req, *ctx);
}