Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing HostWithShard-fwd.h #9336

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion third-party/mcrouter/mcrouter-CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,19 @@ add_custom_command(
"${CMAKE_CURRENT_BINARY_DIR}/mcrouter/mcrouter_sr_deps.h"
COMMENT "Creating mcrouter_sr_deps.h symlink"
)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mcrouter/HostWithShard-fwd.h"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/mcrouter/HostWithShard-fwd-impl.h"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/mcrouter"
COMMAND ${CMAKE_COMMAND} -E create_symlink
"${CMAKE_CURRENT_SOURCE_DIR}/mcrouter/HostWithShard-fwd-impl.h"
"${CMAKE_CURRENT_BINARY_DIR}/mcrouter/HostWithShard-fwd.h"
COMMENT "Creating HostWithShard-fwd.h symlink"
)
list(APPEND CXX_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/mcrouter/RouterRegistry.h")
list(APPEND CXX_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/mcrouter/ThriftAcceptor.h")
list(APPEND CXX_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/mcrouter/mcrouter_sr_deps.h")
list(APPEND CXX_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/mcrouter/HostWithShard-fwd.h")
list(APPEND CXX_SOURCES ${files})

add_definitions(-DNO_LIB_GFLAGS)
Expand Down Expand Up @@ -100,4 +110,4 @@ target_include_directories(mcrouter PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "${JEMA
install(
TARGETS mcrouter
LIBRARY ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
)
)
1 change: 1 addition & 0 deletions third-party/mcrouter/src/mcrouter/CarbonRouterClient-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "mcrouter/CarbonRouterInstance.h"
#include "mcrouter/ForEachPossibleClient.h"
#include "mcrouter/HostWithShard-fwd.h"
#include "mcrouter/McrouterFiberContext.h"
#include "mcrouter/ProxyRequestContextTyped.h"
#include "mcrouter/lib/RouteHandleTraverser.h"
Expand Down
21 changes: 21 additions & 0 deletions third-party/mcrouter/src/mcrouter/HostWithShard-fwd-impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

#include <cstdint>
#include <memory>

namespace facebook {
namespace memcache {

class HostInfo;
using HostInfoPtr = std::shared_ptr<HostInfo>;
using HostWithShard = std::pair<HostInfoPtr, int64_t>;

} // namespace memcache
} // namespace facebook
1 change: 1 addition & 0 deletions third-party/mcrouter/src/mcrouter/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ libmcroutercore_a_SOURCES = \
ProxyConfig.h \
ProxyConfigBuilder.cpp \
ProxyConfigBuilder.h \
ProxyDestination.cpp \
ProxyDestination-inl.h \
ProxyDestination.h \
ProxyDestinationBase.cpp \
Expand Down
104 changes: 19 additions & 85 deletions third-party/mcrouter/src/mcrouter/ProxyDestination-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
* LICENSE file in the root directory of this source tree.
*/

#pragma once

#include "mcrouter/ProxyDestination.h"

#include <limits>
#include <random>

#include <folly/io/async/AsyncSSLSocket.h>

#include "mcrouter/OptionsUtil.h"
#include "mcrouter/ProxyBase.h"
#include "mcrouter/ProxyDestinationMap.h"
Expand All @@ -19,13 +21,13 @@
#include "mcrouter/lib/Reply.h"
#include "mcrouter/lib/fbi/cpp/util.h"
#include "mcrouter/lib/mc/protocol.h"
#include "mcrouter/lib/network/AsyncTlsToPlaintextSocket.h"
#include "mcrouter/lib/network/ConnectionDownReason.h"
#include "mcrouter/lib/network/ConnectionOptions.h"
#include "mcrouter/lib/network/McFizzClient.h"
#include "mcrouter/lib/network/McSSLUtil.h"
#include "mcrouter/lib/network/RpcStatsContext.h"
#include "mcrouter/lib/network/TlsToPlainTransport.h"

namespace folly {
class AsyncTransport;
} // namespace folly

namespace facebook {
namespace memcache {
Expand Down Expand Up @@ -264,6 +266,13 @@ void ProxyDestination<Transport>::resetInactive() {
}
}

namespace detail {
void incrementProxyTlsKtlsSslStats(
const folly::AsyncTransport& socket,
SecurityMech mech,
ProxyBase& proxy);
} // namespace detail

template <class Transport>
void ProxyDestination<Transport>::initializeTransport() {
assert(!transport_);
Expand Down Expand Up @@ -349,94 +358,19 @@ void ProxyDestination<Transport>::initializeTransport() {

transport_->setConnectionStatusCallbacks(ConnectionStatusCallbacks{
[this](
const folly::AsyncTransportWrapper& socket,
const folly::AsyncTransport& socket,
int64_t numConnectRetries) mutable {
setState(State::Up);
proxy().stats().increment(num_connections_opened_stat);

updatePoolStatConnections(true);
auto mech = accessPoint()->getSecurityMech();
if (mech == SecurityMech::TLS_TO_PLAINTEXT) {
if (const auto* tlsToPlainSock =
socket.getUnderlyingTransport<TlsToPlainTransport>()) {
auto stats = tlsToPlainSock->getStats();
proxy().stats().increment(num_tls_to_plain_connections_opened_stat);
if (stats.sessionReuseAttempted) {
proxy().stats().increment(
num_tls_to_plain_resumption_attempts_stat);
}
if (stats.sessionReuseSuccess) {
proxy().stats().increment(
num_tls_to_plain_resumption_successes_stat);
}
} else if (
const auto* thriftTlsToPlainSock =
socket.getUnderlyingTransport<AsyncTlsToPlaintextSocket>()) {
proxy().stats().increment(num_tls_to_plain_connections_opened_stat);

using Status = AsyncTlsToPlaintextSocket::SessionResumptionStatus;
switch (thriftTlsToPlainSock->getSessionResumptionStatus()) {
case Status::RESUMPTION_NOT_ATTEMPTED:
break;
case Status::RESUMPTION_ATTEMPTED_AND_SUCCEEDED:
proxy().stats().increment(
num_tls_to_plain_resumption_successes_stat);
FOLLY_FALLTHROUGH;
case Status::RESUMPTION_ATTEMPTED_AND_FAILED:
proxy().stats().increment(
num_tls_to_plain_resumption_attempts_stat);
};
} else {
proxy().stats().increment(num_tls_to_plain_fallback_failures_stat);
}
}
if (mech == SecurityMech::KTLS12) {
auto stats = McSSLUtil::getKtlsStats(socket);
if (stats) {
proxy().stats().increment(num_ktls_connections_opened_stat);
if (stats->sessionReuseAttempted) {
proxy().stats().increment(num_ktls_resumption_attempts_stat);
}
if (stats->sessionReuseSuccess) {
proxy().stats().increment(num_ktls_resumption_successes_stat);
}
} else {
proxy().stats().increment(num_ktls_fallback_failures_stat);
}
}
// no else if here in case the tls to plain didn't work - we can capture
// ssl socket stats here
if (const auto* sslSocket =
socket.getUnderlyingTransport<folly::AsyncSSLSocket>()) {
proxy().stats().increment(num_ssl_connections_opened_stat);
if (sslSocket->sessionResumptionAttempted()) {
proxy().stats().increment(num_ssl_resumption_attempts_stat);
}
if (sslSocket->getSSLSessionReused()) {
proxy().stats().increment(num_ssl_resumption_successes_stat);
}
} else if (
const auto* fizzSock =
socket.getUnderlyingTransport<McFizzClient>()) {
proxy().stats().increment(num_ssl_connections_opened_stat);
if (fizzSock->pskResumed()) {
proxy().stats().increment(num_ssl_resumption_successes_stat);
proxy().stats().increment(num_ssl_resumption_attempts_stat);
} else {
auto pskState = fizzSock->getState().pskType();
if (pskState && pskState.value() == fizz::PskType::Rejected) {
// session resumption was attempted, but failed
proxy().stats().increment(num_ssl_resumption_attempts_stat);
}
}
}

detail::incrementProxyTlsKtlsSslStats(
socket, accessPoint()->getSecurityMech(), proxy());
if (numConnectRetries > 0) {
proxy().stats().increment(num_connect_success_after_retrying_stat);
proxy().stats().increment(
num_connect_retries_stat, numConnectRetries);
}

updateConnectionClosedInternalStat();
},
[pdstnPtr = selfPtr_](
Expand Down Expand Up @@ -485,7 +419,7 @@ void ProxyDestination<Transport>::initializeTransport() {

transport_->setAuthorizationCallbacks(AuthorizationCallbacks{
[this](
const folly::AsyncTransportWrapper& socket,
const folly::AsyncTransport& socket,
const ConnectionOptions& connectionOptions) mutable {
if (auto& callback = proxy().router().svcIdentAuthCallbackFunc()) {
if (!callback(socket, connectionOptions)) {
Expand Down
94 changes: 94 additions & 0 deletions third-party/mcrouter/src/mcrouter/ProxyDestination.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "mcrouter/ProxyDestination.h"

#include <folly/io/async/AsyncSSLSocket.h>

#include "mcrouter/lib/network/AsyncTlsToPlaintextSocket.h"
#include "mcrouter/lib/network/McFizzClient.h"
#include "mcrouter/lib/network/McSSLUtil.h"
#include "mcrouter/lib/network/TlsToPlainTransport.h"

namespace facebook::memcache::mcrouter::detail {

void incrementProxyTlsKtlsSslStats(
const folly::AsyncTransport& socket,
SecurityMech mech,
ProxyBase& proxy) {
if (mech == SecurityMech::TLS_TO_PLAINTEXT) {
if (const auto* tlsToPlainSock =
socket.getUnderlyingTransport<TlsToPlainTransport>()) {
auto stats = tlsToPlainSock->getStats();
proxy.stats().increment(num_tls_to_plain_connections_opened_stat);
if (stats.sessionReuseAttempted) {
proxy.stats().increment(num_tls_to_plain_resumption_attempts_stat);
}
if (stats.sessionReuseSuccess) {
proxy.stats().increment(num_tls_to_plain_resumption_successes_stat);
}
} else if (
const auto* thriftTlsToPlainSock =
socket.getUnderlyingTransport<AsyncTlsToPlaintextSocket>()) {
proxy.stats().increment(num_tls_to_plain_connections_opened_stat);

using Status = AsyncTlsToPlaintextSocket::SessionResumptionStatus;
switch (thriftTlsToPlainSock->getSessionResumptionStatus()) {
case Status::RESUMPTION_NOT_ATTEMPTED:
break;
case Status::RESUMPTION_ATTEMPTED_AND_SUCCEEDED:
proxy.stats().increment(num_tls_to_plain_resumption_successes_stat);
FOLLY_FALLTHROUGH;
case Status::RESUMPTION_ATTEMPTED_AND_FAILED:
proxy.stats().increment(num_tls_to_plain_resumption_attempts_stat);
};
} else {
proxy.stats().increment(num_tls_to_plain_fallback_failures_stat);
}
}
if (mech == SecurityMech::KTLS12) {
auto stats = McSSLUtil::getKtlsStats(socket);
if (stats) {
proxy.stats().increment(num_ktls_connections_opened_stat);
if (stats->sessionReuseAttempted) {
proxy.stats().increment(num_ktls_resumption_attempts_stat);
}
if (stats->sessionReuseSuccess) {
proxy.stats().increment(num_ktls_resumption_successes_stat);
}
} else {
proxy.stats().increment(num_ktls_fallback_failures_stat);
}
}
// no else if here in case the tls to plain didn't work - we can capture
// ssl socket stats here
if (const auto* sslSocket =
socket.getUnderlyingTransport<folly::AsyncSSLSocket>()) {
proxy.stats().increment(num_ssl_connections_opened_stat);
if (sslSocket->sessionResumptionAttempted()) {
proxy.stats().increment(num_ssl_resumption_attempts_stat);
}
if (sslSocket->getSSLSessionReused()) {
proxy.stats().increment(num_ssl_resumption_successes_stat);
}
} else if (
const auto* fizzSock = socket.getUnderlyingTransport<McFizzClient>()) {
proxy.stats().increment(num_ssl_connections_opened_stat);
if (fizzSock->pskResumed()) {
proxy.stats().increment(num_ssl_resumption_successes_stat);
proxy.stats().increment(num_ssl_resumption_attempts_stat);
} else {
auto pskState = fizzSock->getState().pskType();
if (pskState && pskState.value() == fizz::PskType::Rejected) {
// session resumption was attempted, but failed
proxy.stats().increment(num_ssl_resumption_attempts_stat);
}
}
}
}

} // namespace facebook::memcache::mcrouter::detail
1 change: 1 addition & 0 deletions third-party/mcrouter/src/mcrouter/Server-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "mcrouter/config.h"
#include "mcrouter/lib/network/AsyncMcServer.h"
#include "mcrouter/lib/network/AsyncMcServerWorker.h"
#include "mcrouter/lib/network/McSSLUtil.h"
#include "mcrouter/lib/network/Qos.h"
#include "mcrouter/standalone_options.h"

Expand Down
2 changes: 2 additions & 0 deletions third-party/mcrouter/src/mcrouter/ServiceInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include <folly/Range.h>

#include "mcrouter/lib/network/gen/MemcacheMessages.h"

namespace facebook {
namespace memcache {
namespace mcrouter {
Expand Down
1 change: 1 addition & 0 deletions third-party/mcrouter/src/mcrouter/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ AC_CONFIG_LINKS([test/config.py:test/mcrouter_config.py])
AC_CONFIG_LINKS([RouterRegistry.h:RouterRegistry-impl.h])
AC_CONFIG_LINKS([ThriftAcceptor.h:ThriftAcceptor-impl.h])
AC_CONFIG_LINKS([mcrouter_sr_deps.h:mcrouter_sr_deps-impl.h])
AC_CONFIG_LINKS([HostWithShard-fwd.h:HostWithShard-fwd-impl.h])
AC_CONFIG_AUX_DIR([build-aux])

AM_INIT_AUTOMAKE([1.14 foreign dist-bzip2 nostdinc subdir-objects parallel-tests])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <memory>
#include <vector>

#include "mcrouter/HostWithShard-fwd.h"
#include "mcrouter/McrouterFiberContext.h"
#include "mcrouter/lib/PoolContext.h"
#include "mcrouter/lib/network/AccessPoint.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <folly/ExceptionWrapper.h>

#ifndef LIBMC_FBTRACE_DISABLE
#include <contextprop/cpp/serde/SerDeHelper.h>
#include <contextprop/if/gen-cpp2/ContextpropConstants_constants.h>
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <folly/io/async/EventBase.h>
#include <thrift/lib/cpp2/async/RequestChannel.h>

#ifndef LIBMC_FBTRACE_DISABLE
#include <contextprop/cpp/serde/SerDeHelper.h>
#endif

#include "mcrouter/lib/fbi/cpp/LogFailure.h"
#include "mcrouter/lib/network/AsyncTlsToPlaintextSocket.h"
#include "mcrouter/lib/network/ConnectionOptions.h"
Expand Down