folly::Future ClientHandler::write()

in src/hbase/connection/client-handler.cc [118:144]


folly::Future<folly::Unit> ClientHandler::write(Context *ctx, std::unique_ptr<Request> r) {
  /* for RPC test, there's no need to send connection header */
  if (!conf_->GetBool(RpcSerde::HBASE_CLIENT_RPC_TEST_MODE,
                      RpcSerde::DEFAULT_HBASE_CLIENT_RPC_TEST_MODE)) {
    // We need to send the header once.
    // So use call_once to make sure that only one thread wins this.
    std::call_once((*once_flag_), [ctx, this]() {
      VLOG(3) << "Writing RPC Header to server: " << server_;
      auto header = serde_.Header(user_name_);
      ctx->fireWrite(std::move(header));
    });
  }

  VLOG(3) << "Writing RPC Request:" << r->DebugString() << ", server: " << server_;

  // Now store the call id to response.
  resp_msgs_->insert(std::make_pair(r->call_id(), r->resp_msg()));

  try {
    // Send the data down the pipeline.
    return ctx->fireWrite(serde_.Request(r->call_id(), r->method(), r->req_msg().get()));
  } catch (const folly::AsyncSocketException &e) {
    /* clear protobuf::Message to avoid overflow. */
    resp_msgs_->erase(r->call_id());
    throw e;
  }
}