Beispiel #1
0
proxy_t::proxy_t(McrouterInstance& rtr)
    : router_(rtr),
      destinationMap(folly::make_unique<ProxyDestinationMap>(this)),
      randomGenerator(folly::randomNumberSeed()),
      fiberManager(
        fiber_local::ContextTypeTag(),
        folly::make_unique<folly::fibers::EventBaseLoopController>(),
        getFiberManagerOptions(router_.opts())) {

  memset(stats, 0, sizeof(stats));
  memset(stats_bin, 0, sizeof(stats_bin));
  memset(stats_num_within_window, 0, sizeof(stats_num_within_window));

  static uint64_t next_magic = 0x12345678900000LL;

  magic = __sync_fetch_and_add(&next_magic, 1);

  init_stats(stats);

  messageQueue_ = folly::make_unique<MessageQueue<ProxyMessage>>(
    router_.opts().client_queue_size,
    [this] (ProxyMessage&& message) {
      this->messageReady(message.type, message.data);
    },
    router_.opts().client_queue_no_notify_rate,
    router_.opts().client_queue_wait_threshold_us,
    &nowUs,
    [this] () {
      stat_incr_safe(stats, client_queue_notifications_stat);
    }
  );

  statsContainer = folly::make_unique<ProxyStatsContainer>(*this);
}
Beispiel #2
0
ProxyRequestContext::ProxyRequestContext(
  proxy_t& pr,
  McMsgRef req,
  void (*enqReply)(ProxyRequestContext& preq),
  void* context,
  ProxyRequestPriority priority__,
  void (*reqComplete)(ProxyRequestContext& preq))
    : requestId_(pr.nextRequestId()),
      proxy_(pr),
      context_(context),
      enqueueReply_(enqReply),
      reqComplete_(reqComplete),
      priority_(priority__) {

  logger_.emplace(&proxy_);
  additionalLogger_.emplace(&proxy_);

  static const char* const kInternalGetPrefix = "__mcrouter__.";

  if (req->op == mc_op_get && !strncmp(req->key.str, kInternalGetPrefix,
                                       strlen(kInternalGetPrefix))) {
    /* HACK: for backwards compatibility, convert (get, "__mcrouter__.key")
       into (get-service-info, "key") */
    auto copy = MutableMcMsgRef(mc_msg_dup(req.get()));
    copy->op = mc_op_get_service_info;
    copy->key.str += strlen(kInternalGetPrefix);
    copy->key.len -= strlen(kInternalGetPrefix);
    origReq_ = std::move(copy);
  } else {
    origReq_ = std::move(req);
  }

  stat_incr_safe(proxy_.stats, proxy_request_num_outstanding_stat);
}