├── .github └── workflows │ └── build.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md └── mcrouter ├── .gitignore ├── AsyncLog.cpp ├── AsyncLog.h ├── AsyncWriter.cpp ├── AsyncWriter.h ├── AsyncWriterEntry.h ├── CarbonRouterClient-inl.h ├── CarbonRouterClient.cpp ├── CarbonRouterClient.h ├── CarbonRouterClientBase.cpp ├── CarbonRouterClientBase.h ├── CarbonRouterFactory-inl.h ├── CarbonRouterFactory.cpp ├── CarbonRouterFactory.h ├── CarbonRouterInstance-inl.h ├── CarbonRouterInstance.cpp ├── CarbonRouterInstance.h ├── CarbonRouterInstanceBase.cpp ├── CarbonRouterInstanceBase.h ├── ConfigApi.cpp ├── ConfigApi.h ├── ConfigApiIf.h ├── ExecutorObserver.h ├── ExponentialSmoothData.h ├── ExternalStatsHandler.cpp ├── ExternalStatsHandler.h ├── FileDataProvider.cpp ├── FileDataProvider.h ├── FileObserver.cpp ├── FileObserver.h ├── ForEachPossibleClient.h ├── HostWithShard-fwd-impl.h ├── LeaseTokenMap.cpp ├── LeaseTokenMap.h ├── Makefile.am ├── McDistributionUtils.cpp ├── McDistributionUtils.h ├── McReqUtil.h ├── McrouterClient.h ├── McrouterFiberContext.cpp ├── McrouterFiberContext.h ├── McrouterInstance.h ├── McrouterLogFailure.cpp ├── McrouterLogFailure.h ├── McrouterLogger.cpp ├── McrouterLogger.h ├── McrouterManager.cpp ├── McrouterManager.h ├── OptionsUtil.cpp ├── OptionsUtil.h ├── PoolFactory.cpp ├── PoolFactory.h ├── PoolStats.h ├── Proxy-inl.h ├── Proxy.h ├── ProxyBase-inl.h ├── ProxyBase.cpp ├── ProxyBase.h ├── ProxyConfig-inl.h ├── ProxyConfig.h ├── ProxyConfigBuilder.cpp ├── ProxyConfigBuilder.h ├── ProxyDestination-inl.h ├── ProxyDestination.cpp ├── ProxyDestination.h ├── ProxyDestinationBase.cpp ├── ProxyDestinationBase.h ├── ProxyDestinationKey.cpp ├── ProxyDestinationKey.h ├── ProxyDestinationMap-inl.h ├── ProxyDestinationMap.cpp ├── ProxyDestinationMap.h ├── ProxyRequestContext.cpp ├── ProxyRequestContext.h ├── ProxyRequestContextTyped-inl.h ├── ProxyRequestContextTyped.h ├── ProxyRequestLogger-inl.h ├── ProxyRequestLogger.h ├── ProxyRequestPriority.h ├── ProxyStats.cpp ├── ProxyStats.h ├── RequestAclChecker.cpp ├── RequestAclChecker.h ├── RouterRegistry-impl.h ├── RoutingPrefix.cpp ├── RoutingPrefix.h ├── Server-inl.h ├── Server.h ├── ServerOnRequest.h ├── ServiceInfo-inl.h ├── ServiceInfo.cpp ├── ServiceInfo.h ├── StandaloneConfig.cpp ├── StandaloneConfig.h ├── StandaloneUtils.cpp ├── StandaloneUtils.h ├── TargetHooks.h ├── ThreadUtil.cpp ├── ThreadUtil.h ├── ThriftAcceptor-impl.h ├── ThriftAcceptor.cpp ├── ThriftObserver.h ├── TkoCounters.h ├── TkoLog.cpp ├── TkoLog.h ├── TkoTracker.cpp ├── TkoTracker.h ├── __init__.py ├── autogen.sh ├── configure.ac ├── flavor.cpp ├── flavor.h ├── lib ├── AuxiliaryCPUThreadPool.cpp ├── AuxiliaryCPUThreadPool.h ├── AuxiliaryIOThreadPool.cpp ├── AuxiliaryIOThreadPool.h ├── CacheClientStats.h ├── CallbackPool-inl.h ├── CallbackPool.h ├── Ch3HashFunc.h ├── Clocks.cpp ├── Clocks.h ├── Compression.cpp ├── Compression.h ├── CompressionCodecManager.cpp ├── CompressionCodecManager.h ├── Crc32HashFunc.h ├── DynamicUtil.cpp ├── DynamicUtil.h ├── FailoverContext.h ├── FailoverErrorsSettings.h ├── FailoverErrorsSettingsBase.cpp ├── FailoverErrorsSettingsBase.h ├── FiberLocal.h ├── FiberLocalInternal.cpp ├── FiberLocalInternal.h ├── HashFunctionType.h ├── HashSelector.h ├── HashUtil.h ├── IOBufUtil.cpp ├── IOBufUtil.h ├── IovecCursor-inl.h ├── IovecCursor.cpp ├── IovecCursor.h ├── Lz4CompressionCodec.cpp ├── Lz4CompressionCodec.h ├── Lz4Immutable.cpp ├── Lz4Immutable.h ├── Lz4ImmutableCompressionCodec.cpp ├── Lz4ImmutableCompressionCodec.h ├── Makefile.am ├── McKey.h ├── McResUtil.h ├── MessageQueue.cpp ├── MessageQueue.h ├── Observable-inl.h ├── Observable.h ├── Operation.h ├── PoolContext.h ├── Ref.h ├── RendezvousHashFunc.cpp ├── RendezvousHashFunc.h ├── RendezvousHashHelper.cpp ├── RendezvousHashHelper.h ├── Reply.h ├── RequestLoggerContext.h ├── RouteHandleTraverser.h ├── RuntimeVarsData.cpp ├── RuntimeVarsData.h ├── SelectionRouteFactory.h ├── StatsReply.cpp ├── StatsReply.h ├── WeightedCh3HashFunc.cpp ├── WeightedCh3HashFunc.h ├── WeightedCh3RvHashFunc.cpp ├── WeightedCh3RvHashFunc.h ├── WeightedChHashFuncBase.cpp ├── WeightedChHashFuncBase.h ├── WeightedRendezvousHashFunc.cpp ├── WeightedRendezvousHashFunc.h ├── ZstdCompressionCodec.cpp ├── ZstdCompressionCodec.h ├── carbon │ ├── Artillery-inl.h │ ├── Artillery.h │ ├── CarbonMessageConversionUtils-inl.h │ ├── CarbonMessageConversionUtils.h │ ├── CarbonProtocolCommon.h │ ├── CarbonProtocolReader.cpp │ ├── CarbonProtocolReader.h │ ├── CarbonProtocolWriter.h │ ├── CarbonQueueAppender.cpp │ ├── CarbonQueueAppender.h │ ├── CmdLineClient-inl.h │ ├── CmdLineClient.cpp │ ├── CmdLineClient.h │ ├── CommonSerializationTraits.h │ ├── ExternalCarbonConnectionStats.h │ ├── FailoverUtil.h │ ├── Fields.h │ ├── JsonClient-inl.h │ ├── JsonClient.cpp │ ├── JsonClient.h │ ├── Keys-inl.h │ ├── Keys.h │ ├── Makefile.am │ ├── MessageCommon.h │ ├── NoopAdditionalLogger.h │ ├── NoopExternalConnectionLogger.h │ ├── ReplyCommon.h │ ├── RequestCommon.h │ ├── RequestReplyUtil.h │ ├── Result.cpp │ ├── Result.h │ ├── RoutingGroups.h │ ├── SerializationTraits.h │ ├── Stats.h │ ├── TypeList-inl.h │ ├── TypeList.h │ ├── Util.h │ ├── Variant.h │ ├── carbon.thrift │ ├── carbon_result.thrift │ ├── connection │ │ ├── CarbonConnectionUtil.h │ │ ├── ExternalCarbonConnectionImpl-inl.h │ │ ├── ExternalCarbonConnectionImpl.cpp │ │ ├── ExternalCarbonConnectionImpl.h │ │ ├── InternalCarbonConnectionImpl.h │ │ └── PooledCarbonConnectionImpl.h │ ├── example │ │ ├── CarbonLookasideRoute.h │ │ ├── DuplicateRoute.h │ │ ├── HelloGoodbye.idl │ │ ├── HelloGoodbyeTest.cpp │ │ ├── ThreadAffinityHelloGoodbye.cpp │ │ ├── ThreadAffinityMC.cpp │ │ ├── gen │ │ │ ├── HelloGoodbye.h │ │ │ ├── HelloGoodbye.thrift │ │ │ ├── HelloGoodbyeClientTool.cpp │ │ │ ├── HelloGoodbyeConnection.h │ │ │ ├── HelloGoodbyeMessages-inl.h │ │ │ ├── HelloGoodbyeMessages.cpp │ │ │ ├── HelloGoodbyeMessages.h │ │ │ ├── HelloGoodbyeMessagesThrift.cpp │ │ │ ├── HelloGoodbyeRouteHandleIf.h │ │ │ ├── HelloGoodbyeRouterInfo-BuildExtraProvider.cpp │ │ │ ├── HelloGoodbyeRouterInfo-ExternTemplate.cpp │ │ │ ├── HelloGoodbyeRouterInfo.cpp │ │ │ ├── HelloGoodbyeRouterInfo.h │ │ │ ├── HelloGoodbyeRouterStats.h │ │ │ ├── HelloGoodbyeRoutingGroups.h │ │ │ ├── HelloGoodbyeServer.h │ │ │ ├── HelloGoodbyeServerOnRequestThrift.h │ │ │ ├── HelloGoodbyeService.thrift │ │ │ └── HelloGoodbyeThriftTransport.h │ │ └── main.cpp │ └── test │ │ ├── A.idl │ │ ├── B.idl │ │ ├── CarbonMessageConversionUtilsTest.cpp │ │ ├── CarbonStructuresTest.cpp │ │ ├── CarbonTest.idl │ │ ├── CarbonThriftTest.idl │ │ ├── JsonClientTest.cpp │ │ ├── RequestReplyUtilTest.cpp │ │ ├── SerializationTest.cpp │ │ ├── Timestamp.cpp │ │ ├── Timestamp.h │ │ ├── Util-inl.h │ │ ├── Util.cpp │ │ ├── Util.h │ │ ├── VariantTest.cpp │ │ └── gen │ │ ├── A.h │ │ ├── A.thrift │ │ ├── AConnection.h │ │ ├── AMessages-inl.h │ │ ├── AMessages.cpp │ │ ├── AMessages.h │ │ ├── AMessagesThrift.cpp │ │ ├── ARouteHandleIf.h │ │ ├── ARouterInfo-BuildExtraProvider.cpp │ │ ├── ARouterInfo-ExternTemplate.cpp │ │ ├── ARouterInfo.cpp │ │ ├── ARouterInfo.h │ │ ├── ARouterStats.h │ │ ├── ARoutingGroups.h │ │ ├── AServer.h │ │ ├── AServerOnRequestThrift.h │ │ ├── AService.thrift │ │ ├── AThriftTransport.h │ │ ├── B.h │ │ ├── B.thrift │ │ ├── BConnection.h │ │ ├── BMessages-inl.h │ │ ├── BMessages.cpp │ │ ├── BMessages.h │ │ ├── BMessagesThrift.cpp │ │ ├── BRouteHandleIf.h │ │ ├── BRouterInfo-BuildExtraProvider.cpp │ │ ├── BRouterInfo-ExternTemplate.cpp │ │ ├── BRouterInfo.cpp │ │ ├── BRouterInfo.h │ │ ├── BRouterStats.h │ │ ├── BRoutingGroups.h │ │ ├── BServer.h │ │ ├── BServerOnRequestThrift.h │ │ ├── BService.thrift │ │ ├── BThriftTransport.h │ │ ├── CarbonTest.h │ │ ├── CarbonTest.thrift │ │ ├── CarbonTestConnection.h │ │ ├── CarbonTestMessages-inl.h │ │ ├── CarbonTestMessages.cpp │ │ ├── CarbonTestMessages.h │ │ ├── CarbonTestMessagesThrift.cpp │ │ ├── CarbonTestRouteHandleIf.h │ │ ├── CarbonTestRouterInfo-BuildExtraProvider.cpp │ │ ├── CarbonTestRouterInfo-ExternTemplate.cpp │ │ ├── CarbonTestRouterInfo.cpp │ │ ├── CarbonTestRouterInfo.h │ │ ├── CarbonTestRouterStats.h │ │ ├── CarbonTestRoutingGroups.h │ │ ├── CarbonTestServer.h │ │ ├── CarbonTestServerOnRequestThrift.h │ │ ├── CarbonTestService.thrift │ │ ├── CarbonTestThriftTransport.h │ │ ├── CarbonThriftTest.h │ │ ├── CarbonThriftTest.thrift │ │ ├── CarbonThriftTestConnection.h │ │ ├── CarbonThriftTestMessages-inl.h │ │ ├── CarbonThriftTestMessages.cpp │ │ ├── CarbonThriftTestMessages.h │ │ ├── CarbonThriftTestMessagesThrift.cpp │ │ ├── CarbonThriftTestRouteHandleIf.h │ │ ├── CarbonThriftTestRouterInfo-BuildExtraProvider.cpp │ │ ├── CarbonThriftTestRouterInfo-ExternTemplate.cpp │ │ ├── CarbonThriftTestRouterInfo.cpp │ │ ├── CarbonThriftTestRouterInfo.h │ │ ├── CarbonThriftTestRouterStats.h │ │ ├── CarbonThriftTestRoutingGroups.h │ │ ├── CarbonThriftTestServer.h │ │ ├── CarbonThriftTestServerOnRequestThrift.h │ │ ├── CarbonThriftTestService.thrift │ │ └── CarbonThriftTestThriftTransport.h ├── config │ ├── ConfigPreprocessor.cpp │ ├── ConfigPreprocessor.h │ ├── ImportResolverIf.h │ ├── Makefile.am │ ├── RendezvousHash.cpp │ ├── RendezvousHash.h │ ├── RouteHandleBuilder.h │ ├── RouteHandleFactory-inl.h │ ├── RouteHandleFactory.h │ ├── RouteHandleProviderIf.h │ └── test │ │ ├── .gitignore │ │ ├── Makefile.am │ │ ├── config_preprocessor_test.cpp │ │ ├── config_preprocessor_test_comments.json │ │ ├── config_preprocessor_test_errors.json │ │ ├── config_preprocessor_test_file.json │ │ ├── main.cpp │ │ └── rendezvous_hash_test.cpp ├── debug │ ├── ConnectionFifo.cpp │ ├── ConnectionFifo.h │ ├── ConnectionFifoProtocol.cpp │ ├── ConnectionFifoProtocol.h │ ├── Fifo.cpp │ ├── Fifo.h │ ├── FifoManager.cpp │ └── FifoManager.h ├── fbi │ ├── .gitignore │ ├── Makefile.am │ ├── WeightedFurcHash.cpp │ ├── WeightedFurcHash.h │ ├── counting_sem.cpp │ ├── counting_sem.h │ ├── cpp │ │ ├── FuncGenerator.h │ │ ├── LogFailure.cpp │ │ ├── LogFailure.h │ │ ├── LowerBoundPrefixMap.cpp │ │ ├── LowerBoundPrefixMap.h │ │ ├── Makefile.am │ │ ├── ObjectPool.h │ │ ├── ParsingUtil.cpp │ │ ├── ParsingUtil.h │ │ ├── TypeList-inl.h │ │ ├── TypeList.h │ │ ├── globals.cpp │ │ ├── globals.h │ │ ├── test │ │ │ ├── .gitignore │ │ │ ├── FuncGeneratorBenchmark.cpp │ │ │ ├── LowerBoundPrefixMapTest.cpp │ │ │ ├── Makefile.am │ │ │ ├── ObjectPoolTests.cpp │ │ │ └── main.cpp │ │ ├── util.cpp │ │ └── util.h │ ├── decls.h │ ├── hash.c │ ├── hash.h │ ├── network.c │ ├── network.h │ ├── queue.h │ ├── test │ │ ├── .gitignore │ │ ├── Makefile.am │ │ ├── hash_test.cpp │ │ ├── main.cpp │ │ ├── sem_test.cpp │ │ ├── test_util.cpp │ │ └── test_util.h │ ├── time.h │ └── util.h ├── invalidation │ ├── McInvalidationDefs.h │ ├── McInvalidationKvPairs.cpp │ ├── McInvalidationKvPairs.h │ └── test │ │ └── McInvalidationKvPairsTest.cpp ├── mc │ ├── mc_fbtrace_info.c │ ├── mc_fbtrace_info.h │ ├── msg.cpp │ ├── msg.h │ └── protocol.h ├── network │ ├── .gitignore │ ├── AccessPoint.cpp │ ├── AccessPoint.h │ ├── AsciiSerialized-inl.h │ ├── AsciiSerialized.cpp │ ├── AsciiSerialized.h │ ├── AsyncMcClient-inl.h │ ├── AsyncMcClient.h │ ├── AsyncMcClientImpl-inl.h │ ├── AsyncMcClientImpl.cpp │ ├── AsyncMcClientImpl.h │ ├── AsyncMcServer.cpp │ ├── AsyncMcServer.h │ ├── AsyncMcServerWorker.cpp │ ├── AsyncMcServerWorker.h │ ├── AsyncMcServerWorkerOptions.h │ ├── AsyncTlsToPlaintextSocket.cpp │ ├── AsyncTlsToPlaintextSocket.h │ ├── CarbonMessageDispatcher.h │ ├── CarbonMessageList.h │ ├── CarbonRequestHandler.h │ ├── CaretHeader.h │ ├── CaretProtocol.cpp │ ├── CaretProtocol.h │ ├── CaretSerializedMessage-inl.h │ ├── CaretSerializedMessage.h │ ├── ClientMcParser-inl.h │ ├── ClientMcParser.h │ ├── Common.idl │ ├── ConnectionDownReason.h │ ├── ConnectionOptions.h │ ├── ConnectionTracker.cpp │ ├── ConnectionTracker.h │ ├── CpuController.cpp │ ├── CpuController.h │ ├── FBTrace-inl.h │ ├── FBTrace.h │ ├── FailureDomains.cpp │ ├── FailureDomains.h │ ├── FizzContextProvider.cpp │ ├── FizzContextProvider.h │ ├── McAsciiParser-inl.h │ ├── McAsciiParser.cpp │ ├── McAsciiParser.h │ ├── McAsciiParser.rl │ ├── McClientRequestContext-inl.h │ ├── McClientRequestContext.cpp │ ├── McClientRequestContext.h │ ├── McFizzClient.h │ ├── McFizzServer.h │ ├── McParser.cpp │ ├── McParser.h │ ├── McSSLUtil.cpp │ ├── McSSLUtil.h │ ├── McSerializedRequest-inl.h │ ├── McSerializedRequest.cpp │ ├── McSerializedRequest.h │ ├── McServerRequestContext-inl.h │ ├── McServerRequestContext.cpp │ ├── McServerRequestContext.h │ ├── McServerSession-inl.h │ ├── McServerSession.cpp │ ├── McServerSession.h │ ├── McServerThriftRequestContext.cpp │ ├── McServerThriftRequestContext.h │ ├── McThriftContext.h │ ├── Memcache.idl │ ├── MessageHelpers.h │ ├── MultiOpParent.cpp │ ├── MultiOpParent.h │ ├── Qos.cpp │ ├── Qos.h │ ├── RemoteConnection.h │ ├── RpcStatsContext.h │ ├── SecurityOptions.cpp │ ├── SecurityOptions.h │ ├── ServerLoad.cpp │ ├── ServerLoad.h │ ├── ServerMcParser-inl.h │ ├── ServerMcParser.h │ ├── SocketConnector.cpp │ ├── SocketConnector.h │ ├── SocketUtil.cpp │ ├── SocketUtil.h │ ├── ThreadLocalSSLContextProvider.cpp │ ├── ThreadLocalSSLContextProvider.h │ ├── ThriftTransport-inl.h │ ├── ThriftTransport.cpp │ ├── ThriftTransport.h │ ├── TlsToPlainTransport.h │ ├── Transport.h │ ├── TypedMsg-inl.h │ ├── TypedMsg.h │ ├── UniqueIntrusiveList.h │ ├── Utils.h │ ├── WriteBuffer-inl.h │ ├── WriteBuffer.cpp │ ├── WriteBuffer.h │ ├── gen │ │ ├── Common.h │ │ ├── Common.thrift │ │ ├── CommonMessages-inl.h │ │ ├── CommonMessages.cpp │ │ ├── CommonMessages.h │ │ ├── CommonMessagesThrift.cpp │ │ ├── Makefile.am │ │ ├── Memcache.h │ │ ├── Memcache.thrift │ │ ├── MemcacheClientTool.cpp │ │ ├── MemcacheConnection.h │ │ ├── MemcacheMessages-inl.h │ │ ├── MemcacheMessages.cpp │ │ ├── MemcacheMessages.h │ │ ├── MemcacheMessagesThrift.cpp │ │ ├── MemcacheRouteHandleIf.h │ │ ├── MemcacheRouterInfo-AllFastestRoute.cpp │ │ ├── MemcacheRouterInfo-BuildExtraProvider.cpp │ │ ├── MemcacheRouterInfo-ExternTemplate.cpp │ │ ├── MemcacheRouterInfo-FailoverRoute.cpp │ │ ├── MemcacheRouterInfo-HashRoute.cpp │ │ ├── MemcacheRouterInfo.cpp │ │ ├── MemcacheRouterInfo.h │ │ ├── MemcacheRouterStats.h │ │ ├── MemcacheRoutingGroups.h │ │ ├── MemcacheServer.h │ │ ├── MemcacheServerOnRequestThrift.h │ │ ├── MemcacheService.thrift │ │ └── MemcacheThriftTransport.h │ └── test │ │ ├── .gitignore │ │ ├── AccessPointTest.cpp │ │ ├── AsyncMcClientTestSync.cpp │ │ ├── AsyncMcServerShutdownTest.cpp │ │ ├── AsyncMcServerTest.cpp │ │ ├── CarbonMessageDispatcherTest.cpp │ │ ├── CarbonMockMcTest.cpp │ │ ├── CarbonQueueAppenderTest.cpp │ │ ├── CarbonTest.idl │ │ ├── ClientSocket.cpp │ │ ├── ClientSocket.h │ │ ├── ListenSocket.cpp │ │ ├── ListenSocket.h │ │ ├── Makefile.am │ │ ├── McAsciiParserTest.cpp │ │ ├── McParserTest.cpp │ │ ├── McServerAsciiParserTest.cpp │ │ ├── MemcacheConnectionTest.cpp │ │ ├── MemcacheTest.cpp │ │ ├── MockMc.cpp │ │ ├── MockMc.h │ │ ├── MockMcOnRequest.h │ │ ├── MockMcServer.cpp │ │ ├── MockMcServerDual.cpp │ │ ├── MockMcThriftServer.cpp │ │ ├── MockMcThriftServerHandler.h │ │ ├── RequestExpiryTest.cpp │ │ ├── SessionTest.cpp │ │ ├── SessionTestHarness.cpp │ │ ├── SessionTestHarness.h │ │ ├── TestClientServerUtil.cpp │ │ ├── TestClientServerUtil.h │ │ ├── TestMcAsciiParserUtil.cpp │ │ ├── TestMcAsciiParserUtil.h │ │ ├── broken_cert.pem │ │ ├── broken_key.pem │ │ ├── ca_cert.pem │ │ ├── ca_key.pem │ │ ├── gen │ │ ├── CarbonTest.h │ │ ├── CarbonTest.thrift │ │ ├── CarbonTestMessages-inl.h │ │ ├── CarbonTestMessages.cpp │ │ ├── CarbonTestMessages.h │ │ └── CarbonTestMessagesThrift.cpp │ │ ├── generate_keys-inl.sh │ │ ├── generate_keys.sh │ │ ├── test_cert.pem │ │ └── test_key.pem ├── routes │ ├── AllAsyncRoute.h │ ├── AllFastestRoute.h │ ├── AllInitialRoute.h │ ├── AllMajorityRoute.h │ ├── AllSyncRoute.h │ ├── CollectionRoute.h │ ├── DefaultShadowSelectorPolicy.h │ ├── L1L2CacheRoute.h │ ├── MigrateRoute.h │ ├── NullRoute.h │ ├── RandomRoute.h │ └── SelectionRoute.h └── test │ ├── .gitignore │ ├── AllSyncCollectionRoute.h │ ├── Ch3HashTest.cpp │ ├── CompressionCodecManagerTest.cpp │ ├── CompressionTest.cpp │ ├── CompressionTestUtil.cpp │ ├── CompressionTestUtil.h │ ├── Crc32HashTest.cpp │ ├── DynamicUtilTest.cpp │ ├── FiberLocalTest.cpp │ ├── HashTestUtil.cpp │ ├── HashTestUtil.h │ ├── IovecCursorTest.cpp │ ├── Lz4ImmutableTest.cpp │ ├── Main.cpp │ ├── Makefile.am │ ├── McResUtilTest.cpp │ ├── MigrateRouteTest.cpp │ ├── RandomRouteTest.cpp │ ├── RendezvousHashTest.cpp │ ├── RouteHandleTest.cpp │ ├── RouteHandleTestUtil.h │ ├── TestRouteHandle.h │ ├── WeightedCh3HashFuncTest.cpp │ ├── WeightedChHashFuncBaseTest.cpp │ ├── WeightedHashBenchmark.cpp │ ├── WeightedRendezvousHashTest.cpp │ ├── observable_test.cpp │ └── runtime_vars_data_test.cpp ├── m4 ├── ax_boost_base.m4 ├── ax_boost_context.m4 ├── ax_boost_filesystem.m4 ├── ax_boost_program_options.m4 ├── ax_boost_regex.m4 ├── ax_boost_system.m4 ├── ax_boost_thread.m4 ├── ax_cxx_compile_stdcxx.m4 ├── ax_cxx_compile_stdcxx_14.m4 └── ax_python_devel.m4 ├── main.cpp ├── mcrouter_config-impl.h ├── mcrouter_config.cpp ├── mcrouter_config.h ├── mcrouter_options_list.h ├── mcrouter_sr_deps-impl.h ├── options-template.h ├── options.cpp ├── options.h ├── route.cpp ├── route.h ├── routes ├── AllAsyncRouteFactory.h ├── AllFastestRouteFactory.h ├── AllInitialRouteFactory.h ├── AllMajorityRouteFactory.h ├── AllSyncRouteFactory.h ├── AsynclogRoute.h ├── BigValueRoute-inl.h ├── BigValueRoute.cpp ├── BigValueRoute.h ├── BigValueRouteIf.h ├── BlackholeRoute-inl.h ├── BlackholeRoute.h ├── BlackholingPolicyVisitor.h ├── CarbonLookasideRoute.cpp ├── CarbonLookasideRoute.h ├── ClientCompatibilityCheckerRoute.h ├── CollectionRouteFactory.h ├── DefaultShadowPolicy.h ├── DestinationRoute.h ├── DevNullRoute.h ├── DistributionRoute-inl.h ├── DistributionRoute.h ├── ErrorRoute.h ├── ExtraRouteHandleProviderIf.h ├── FailoverPolicy.h ├── FailoverRateLimiter.cpp ├── FailoverRateLimiter.h ├── FailoverRoute-inl.h ├── FailoverRoute.h ├── FailoverWithExptimeRouteFactory.h ├── HashRouteFactory.h ├── HashStopAllowListRoute.cpp ├── HashStopAllowListRoute.h ├── HostIdRouteFactory.h ├── KeyParseRoute.cpp ├── KeyParseRoute.h ├── KeySplitRoute-inl.h ├── KeySplitRoute.h ├── L1L2CacheRouteFactory.h ├── L1L2SizeSplitRoute-inl.h ├── L1L2SizeSplitRoute.h ├── LatencyInjectionRoute.cpp ├── LatencyInjectionRoute.h ├── LatestRoute.h ├── LoadBalancerRoute.h ├── LoggingRoute.h ├── Makefile.am ├── McBucketRoute-inl.h ├── McBucketRoute.cpp ├── McBucketRoute.h ├── McExtraRouteHandleProvider-inl.h ├── McExtraRouteHandleProvider.h ├── McImportResolver.cpp ├── McImportResolver.h ├── McRouteHandleBuilder.h ├── McRouteHandleProvider-AllFastestRoute.cpp ├── McRouteHandleProvider-CarbonLookasideRoute.cpp ├── McRouteHandleProvider-FailoverRoute.cpp ├── McRouteHandleProvider-HashRoute.cpp ├── McRouteHandleProvider-PoolRoute.cpp ├── McRouteHandleProvider-inl.h ├── McRouteHandleProvider.cpp ├── McRouteHandleProvider.h ├── McrouterRouteHandle.h ├── MigrateRouteFactory.h ├── MissFailoverRoute.h ├── ModifyExptimeRoute.h ├── ModifyKeyRoute.h ├── NullRoute.cpp ├── OperationSelectorRoute-inl.h ├── OperationSelectorRoute.h ├── OriginalClientHashRoute.h ├── OutstandingLimitRoute.h ├── PoolRouteUtils.h ├── PrefixSelectorRoute.h ├── ProxyRoute-inl.h ├── ProxyRoute.h ├── RandomRouteFactory.h ├── RateLimitRoute.h ├── RateLimiter.cpp ├── RateLimiter.h ├── RendezvousRouteHelpers.cpp ├── RendezvousRouteHelpers.h ├── RootRoute.h ├── RouteHandleMap-inl.h ├── RouteHandleMap.h ├── RoutePolicyMap-inl.h ├── RoutePolicyMap.h ├── RouteSelectorMap.h ├── RoutingGroupRoute-inl.h ├── RoutingGroupRoute.h ├── RoutingUtils.cpp ├── RoutingUtils.h ├── ShadowRoute-inl.h ├── ShadowRoute.h ├── ShadowRouteIf.h ├── ShadowSettings.cpp ├── ShadowSettings.h ├── ShardHashFunc.cpp ├── ShardHashFunc.h ├── ShardSelectionRouteFactory-inl.h ├── ShardSelectionRouteFactory.cpp ├── ShardSelectionRouteFactory.h ├── ShardSplitRoute.cpp ├── ShardSplitRoute.h ├── ShardSplitter.cpp ├── ShardSplitter.h ├── SlowWarmUpRoute.h ├── SlowWarmUpRouteSettings.cpp ├── SlowWarmUpRouteSettings.h ├── StagingRoute.cpp ├── StagingRoute.h ├── TimeProviderFunc.h ├── WarmUpRoute.cpp ├── WarmUpRoute.h └── test │ ├── .gitignore │ ├── AllSyncCollectionRouteFactory.h │ ├── BigValueRouteTest.cpp │ ├── BigValueRouteTestBase.h │ ├── BlackholeRouteTest.cpp │ ├── ClientCompatibilityCheckerRouteTest.cpp │ ├── CollectionRouteFactoryTest.cpp │ ├── ConstShardHashFuncTest.cpp │ ├── DistributionRouteTest.cpp │ ├── EagerShardSelectionRouteTest.cpp │ ├── EagerShardSelectionShadowRouteTest.cpp │ ├── ErrorRouteTest.cpp │ ├── FailoverRouteTest.cpp │ ├── FailoverWithExptimeRouteTest.cpp │ ├── HashStopAllowListRouteTest.cpp │ ├── KeyParseRouteTest.cpp │ ├── KeySplitRouteTest.cpp │ ├── LatencyInjectionRouteTest.cpp │ ├── LatestRouteTest.cpp │ ├── LoadBalancerRouteTest.cpp │ ├── LoggingRouteTest.cpp │ ├── Main.cpp │ ├── Makefile.am │ ├── McBucketRouteTest.cpp │ ├── MissFailoverRouteTest.cpp │ ├── OriginalClientHashRouteTest.cpp │ ├── OutstandingLimitRouteTest.cpp │ ├── PrefixSelectorRouteTest.cpp │ ├── RateLimitRouteTest.cpp │ ├── RootRouteTest.cpp │ ├── RouteHandleTestBase.h │ ├── RouteHandleTestUtil.h │ ├── RoutePolicyMapTest.cpp │ ├── ShadowRouteTest.cpp │ ├── ShadowSettingsTest.cpp │ ├── ShardSelectionRouteFactoryBenchmark.cpp │ ├── ShardSelectionRouteTest.cpp │ ├── ShardSplitRouteTest.cpp │ ├── ShardSplitRouteTestUtil.h │ ├── ShardSplitterTest.cpp │ ├── SlowWarmUpRouteTest.cpp │ ├── StagingRouteTest.cpp │ └── WarmUpRouteTest.cpp ├── scripts ├── Makefile_ubuntu-18.04 ├── Makefile_ubuntu-20.04 ├── Makefile_ubuntu-24.04 ├── clean_ubuntu_14.04.sh ├── common.sh ├── docker │ ├── almalinux │ │ ├── Dockerfile │ │ └── scripts │ │ │ ├── build.sh │ │ │ ├── build_deps.sh │ │ │ └── runtime_deps.sh │ └── ubuntu │ │ ├── Dockerfile │ │ └── scripts │ │ ├── build.sh │ │ └── deps.sh ├── get_and_build_by_make.sh ├── get_and_build_everything.sh ├── install_centos_7.2.sh ├── install_ubuntu_14.04.sh ├── install_ubuntu_15.04.sh ├── install_ubuntu_16.04.sh ├── install_ubuntu_18.04.sh ├── install_ubuntu_20.04.sh ├── install_ubuntu_24.04.sh ├── order_centos-7.2 │ ├── 10_folly │ ├── 11_fizz │ ├── 12_wangle │ ├── 15_fbthrift │ └── 20_mcrouter ├── order_ubuntu-14.04 │ ├── 09_openssl │ ├── 10_folly │ ├── 11_fizz │ ├── 12_wangle │ ├── 13_rsocket-yarpl │ ├── 14_fmt │ ├── 15_fbthrift │ ├── 16_gtest │ └── 20_mcrouter ├── order_ubuntu-15.04 │ ├── 10_folly │ ├── 11_fizz │ ├── 12_wangle │ ├── 13_rsocket-yarpl │ ├── 14_fmt │ ├── 15_fbthrift │ ├── 16_gtest │ └── 20_mcrouter ├── order_ubuntu-16.04 │ ├── 10_folly │ ├── 11_fizz │ ├── 12_wangle │ ├── 13_rsocket-yarpl │ ├── 14_fmt │ ├── 15_fbthrift │ ├── 16_gtest │ └── 20_mcrouter ├── recipes │ ├── fbthrift.sh │ ├── fizz.sh │ ├── fmtlib.sh │ ├── folly.sh │ ├── glog.sh │ ├── gtest.sh │ ├── mcrouter.sh │ ├── mvfst.sh │ ├── python.sh │ └── wangle.sh └── run_loadtest.sh ├── standalone_options.h ├── standalone_options_list.h ├── stat_list.h ├── stats.cpp ├── stats.h ├── test ├── .gitignore ├── MCProcess.py ├── Makefile.am ├── McrouterTestCase.py ├── __init__.py ├── cpp_unit_tests │ ├── .gitignore │ ├── LeaseTokenMapTest.cpp │ ├── Makefile.am │ ├── McDistributionUtilsTest.cpp │ ├── McrouterClientUsage.cpp │ ├── McrouterFiberContextTest.cpp │ ├── ProxyRequestContextTest.cpp │ ├── awriter_test.cpp │ ├── config_api_test.cpp │ ├── exponential_smooth_data_test.cpp │ ├── file_observer_test.cpp │ ├── files │ │ ├── already_replied.json │ │ ├── libmcrouter_invalid_pools.json │ │ └── memcache_local_config.json │ ├── flavor_test.cpp │ ├── main.cpp │ ├── mc_route_handle_provider_test.cpp │ ├── options_test.cpp │ ├── pool_factory_test.cpp │ ├── route_handle_factory_test.cpp │ ├── route_test.cpp │ ├── test_foreach_client.json │ └── util_test.cpp ├── invalid_config.json ├── mcrouter_config.py ├── mcrouter_test_basic_1_1_1.json ├── mcrouter_test_basic_2_1_1.json ├── mcrouter_test_basic_3_1_1.json ├── mcrouter_test_bucketized_poolroute_bucketized.json ├── mcrouter_test_bucketized_poolroute_nonbucketized.json ├── mcrouter_test_portoverride.json ├── mock_servers.py ├── routing_prefix_test_ascii.json ├── routing_prefix_test_caret.json ├── routing_prefix_test_custom.json ├── routing_prefix_test_fallback_route.json ├── routing_prefix_test_old_naming.json ├── routing_prefix_test_simple_routes.json ├── run_cpp_test.sh ├── run_python_test.sh ├── runtime_vars_file.json ├── test_additional_fields.py ├── test_allow_only_gets.py ├── test_ascii.json ├── test_ascii_error.py ├── test_ascii_gut.json ├── test_ascii_multiget_mock.py ├── test_async_files.py ├── test_async_files_attr.py ├── test_axon_log.json ├── test_axon_log_alldelete.json ├── test_axonlog.py ├── test_bad_params.py ├── test_basic_all_first.json ├── test_basic_all_majority.json ├── test_basic_all_sync.json ├── test_basic_caret.json ├── test_basic_failover.json ├── test_basic_failover_least_failures.json ├── test_basic_failover_override.json ├── test_basic_l1_l2.json ├── test_basic_l1_l2_ncache.json ├── test_basic_l1_l2_sizesplit.json ├── test_basic_l1_l2_sizesplit_bothset.json ├── test_basic_l1_l2_sizesplit_retry_invalid.json ├── test_basic_l1_l2_sizesplit_retry_valid.json ├── test_basic_l1_multiple_l2_sizesplit.json ├── test_bigvalue.json ├── test_bigvalue.py ├── test_bucketized_poolroute.py ├── test_carbonlookaside_route.py ├── test_caret.json ├── test_caret_server.json ├── test_config_params.json ├── test_config_params.py ├── test_const_shard_hash.json ├── test_const_shard_hash.py ├── test_custom_failover.json ├── test_custom_failover.py ├── test_custom_failover_override.json ├── test_debug_fifos.py ├── test_deterministic_failover.json ├── test_deterministic_failover.py ├── test_deterministic_failover2.json ├── test_deterministic_failover3.json ├── test_deterministic_failover4.json ├── test_deterministic_failover5.json ├── test_deterministic_failover_big_retries.json ├── test_dev_null.json ├── test_dump_config.py ├── test_dump_config_invalid.json ├── test_duplicate_servers.json ├── test_duplicate_servers_difftimeouts.json ├── test_empty_pool.json ├── test_empty_pool.py ├── test_failover_limit.json ├── test_failover_limit_error.json ├── test_flush_all.py ├── test_get_failover.json ├── test_get_failover_with_failover_tag.json ├── test_largeobj.json ├── test_largeobj.py ├── test_latency_injection_after.json ├── test_latency_injection_before.json ├── test_latency_injection_route.py ├── test_latency_injection_total.json ├── test_lease_pairing.py ├── test_lease_pairing_basic.json ├── test_lease_pairing_disabled.json ├── test_lease_pairing_nested.json ├── test_linenumbers.py ├── test_loadbalancer_route.json ├── test_loadbalancer_route.py ├── test_loadbalancer_route_thrift.json ├── test_logging_route.py ├── test_logging_route_mc.json ├── test_logging_route_server.json ├── test_logical_routing_policies.json ├── test_logical_routing_policies.py ├── test_max_shadow_requests.json ├── test_max_shadow_requests.py ├── test_mcpiper.py ├── test_mcrefill.json ├── test_mcrouter.py ├── test_mcrouter_basic.py ├── test_mcrouter_errors.py ├── test_mcrouter_processing_time.json ├── test_mcrouter_processing_time.py ├── test_mcrouter_sanity_mock.py ├── test_mcrouter_serialized.py ├── test_mcrouter_states.py ├── test_mcrouter_to_mcrouter_tko.json ├── test_mcrouter_to_mcrouter_tko.py ├── test_memcache_router.py ├── test_migrated_failover.json ├── test_migrated_failover.py ├── test_migrated_pools.json ├── test_migrated_pools_failover.json ├── test_miss_on_error_arith_ops.json ├── test_miss_on_error_arith_ops.py ├── test_modify_exptime.json ├── test_modify_exptime.py ├── test_modify_key.json ├── test_modify_key.py ├── test_named_handles.py ├── test_named_handles_list.json ├── test_named_handles_obj.json ├── test_noreply.json ├── test_noreply.py ├── test_nullroute.json ├── test_operation_selector_route.json ├── test_operation_selector_route.py ├── test_pool_server_errors.json ├── test_poolstats.json ├── test_poolstats.py ├── test_poolstats_config.json ├── test_probe_timeout.json ├── test_probe_timeout.py ├── test_probe_timeout_reconfig.json ├── test_regional_replicated_pools.json ├── test_rendezvous_failover.json ├── test_rendezvous_failover.py ├── test_routing_group_route.json ├── test_routing_group_route.py ├── test_routing_group_route_incomplete.json ├── test_routing_prefixes.py ├── test_same_pool_failover.json ├── test_send_to_all_hosts.json ├── test_send_to_all_hosts.py ├── test_server_stats_pending.json ├── test_service_info.json ├── test_service_info.py ├── test_shadow.json ├── test_shadow.py ├── test_shadow_route.json ├── test_shadow_route.py ├── test_shadow_with_file.json ├── test_shadow_with_file.py ├── test_shadow_with_file_config.json ├── test_shard_splits.json ├── test_shard_splits.py ├── test_slow_warmup.json ├── test_slow_warmup.py ├── test_stats.py ├── test_thrift.json ├── test_thrift_gut.json ├── test_tko_inactive.py ├── test_tko_reconfigure.py ├── test_tko_reconfigure1.json ├── test_tko_reconfigure2.json ├── test_unknown_name_handle.json ├── test_validate_config.py ├── test_warmup.json ├── test_warmup.py ├── test_warmup2.json ├── test_warmup2.py ├── test_wch3.json └── test_wch3.py └── tools ├── Makefile.am └── mcpiper ├── AnsiColorCodeStream-inl.h ├── AnsiColorCodeStream.cpp ├── AnsiColorCodeStream.h ├── ClientServerMcParser-inl.h ├── ClientServerMcParser.h ├── Color.h ├── Config.cpp ├── Config.h ├── FifoReader.cpp ├── FifoReader.h ├── Makefile.am ├── McPiper.cpp ├── McPiper.h ├── McPiperVisitor.h ├── MessagePrinter-inl.h ├── MessagePrinter.cpp ├── MessagePrinter.h ├── PrettyFormat.h ├── SnifferParser-inl.h ├── SnifferParser.h ├── StyleAwareStream-inl.h ├── StyleAwareStream.h ├── StyledString.cpp ├── StyledString.h ├── Util.cpp ├── Util.h ├── ValueFormatter.h ├── main.cpp └── test └── McPiperVisitorTest.cpp /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - github_action 8 | pull_request: 9 | branches: 10 | - main 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-24.04 15 | steps: 16 | - name: Checkout code 17 | uses: actions/checkout@v4 18 | - name: Build dependencies 19 | run: | 20 | ./mcrouter/scripts/install_ubuntu_24.04.sh "$(pwd)"/mcrouter-install deps 21 | - name: Build mcrouter 22 | run: | 23 | mkdir -p "$(pwd)"/mcrouter-install/install 24 | ./mcrouter/scripts/install_ubuntu_24.04.sh "$(pwd)"/mcrouter-install mcrouter 25 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please [read the full text](https://code.fb.com/codeofconduct) so that you can understand what actions will and will not be tolerated. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Facebook, Inc. and its affiliates. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /mcrouter/.gitignore: -------------------------------------------------------------------------------- 1 | .dirstamp 2 | Makefile 3 | Makefile.in 4 | *.pyc 5 | *.pyo 6 | *.log 7 | *.trs 8 | /build-aux/ 9 | /test/config.py 10 | /mcrouter 11 | /doc/ 12 | /git-describe.h 13 | /.mm* 14 | .deps/ 15 | /aclocal.m4 16 | /autom4te.cache/ 17 | /config.h* 18 | /config-impl.h 19 | /config.status 20 | /configure 21 | /depcomp 22 | /install-sh 23 | /lib/carbon/gen-cpp2/ 24 | /lib/network/CaretSerializedMessage.h 25 | /lib/network/McAsciiParser-gen.cpp 26 | /lib/network/gen-cpp2/* 27 | /lib/network/gen/gen-cpp2/ 28 | /libtool 29 | /m4/libtool.m4 30 | /m4/ltoptions.m4 31 | /m4/ltsugar.m4 32 | /m4/ltversion.m4 33 | /m4/lt~obsolete.m4 34 | /mcrouter_sr_deps.h 35 | /missing 36 | /RouterRegistry.h 37 | /scripts/.*-done 38 | /scripts/all 39 | /ServerOnRequest.h 40 | /stamp-h1 41 | /ThriftAcceptor.h 42 | /lib/gtest*/* 43 | /tools/mcpiper/mcpiper 44 | *.o 45 | *.a 46 | *.la 47 | -------------------------------------------------------------------------------- /mcrouter/AsyncWriterEntry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "mcrouter/lib/fbi/queue.h" 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | namespace mcrouter { 15 | 16 | // Forward declaration. 17 | struct awriter_entry_t; 18 | 19 | struct awriter_callbacks_t { 20 | void (*completed)(awriter_entry_t*, int); 21 | int (*perform_write)(awriter_entry_t*); 22 | }; 23 | 24 | struct awriter_entry_t { 25 | TAILQ_ENTRY(awriter_entry_t) links; 26 | void* context; 27 | const awriter_callbacks_t* callbacks; 28 | }; 29 | 30 | } // namespace mcrouter 31 | } // namespace memcache 32 | } // namespace facebook 33 | -------------------------------------------------------------------------------- /mcrouter/CarbonRouterClient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "mcrouter/CarbonRouterClient.h" 9 | #include "mcrouter/mcrouter_sr_deps.h" 10 | 11 | namespace facebook::memcache::mcrouter::detail { 12 | 13 | bool srHostInfoPtrFuncCarbonRouterClient( 14 | const HostInfoPtr& host, 15 | const RequestClass& requestClass, 16 | uint64_t& hash) { 17 | if (!requestClass.is(RequestClass::kShadow) && host) { 18 | // Host unique key is derived from IP and port 19 | hash = host->location().hostUniqueKey(); 20 | return true; 21 | } 22 | return false; 23 | } 24 | 25 | } // namespace facebook::memcache::mcrouter::detail 26 | -------------------------------------------------------------------------------- /mcrouter/CarbonRouterClientBase.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "CarbonRouterClientBase.h" 9 | 10 | #include "mcrouter/lib/MessageQueue.h" 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | namespace mcrouter { 15 | 16 | CarbonRouterClientBase::CarbonRouterClientBase( 17 | size_t maximumOutstanding, 18 | bool maximumOutstandingError) 19 | : maxOutstanding_(maximumOutstanding), 20 | maxOutstandingError_(maximumOutstandingError) { 21 | static std::atomic nextClientId(0ULL); 22 | clientId_ = nextClientId++; 23 | 24 | if (maxOutstanding_ != 0) { 25 | counting_sem_init(&outstandingReqsSem_, maxOutstanding_); 26 | } 27 | } 28 | } // namespace mcrouter 29 | } // namespace memcache 30 | } // namespace facebook 31 | -------------------------------------------------------------------------------- /mcrouter/ConfigApiIf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | namespace mcrouter { 15 | 16 | enum class ConfigType { ConfigFile = 0, ConfigImport = 1, Pool = 2 }; 17 | 18 | class ConfigApiIf { 19 | public: 20 | virtual bool 21 | get(ConfigType type, const std::string& path, std::string& contents) = 0; 22 | 23 | virtual bool getConfigFile(std::string& config, std::string& path) = 0; 24 | 25 | virtual bool partialReconfigurableSource( 26 | const std::string& configPath, 27 | std::string& path) = 0; 28 | 29 | virtual ~ConfigApiIf() = default; 30 | }; 31 | } // namespace mcrouter 32 | } // namespace memcache 33 | } // namespace facebook 34 | -------------------------------------------------------------------------------- /mcrouter/ExecutorObserver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | namespace facebook { 16 | namespace memcache { 17 | namespace mcrouter { 18 | 19 | /** 20 | * Convenience method to convert the keepalives returned by getAllEventBases() 21 | * into raw pointers, to accommodate for AsyncMcServer::Options interface. 22 | * TODO: Change Options to accept KeepAlives instead? 23 | */ 24 | inline std::vector extractEvbs( 25 | folly::IOThreadPoolExecutorBase& ex) { 26 | auto evbKeepAlives = ex.getAllEventBases(); 27 | std::vector ret; 28 | ret.reserve(evbKeepAlives.size()); 29 | for (const auto& ka : evbKeepAlives) { 30 | ret.push_back(ka.get()); 31 | } 32 | return ret; 33 | } 34 | 35 | } // namespace mcrouter 36 | } // namespace memcache 37 | } // namespace facebook 38 | -------------------------------------------------------------------------------- /mcrouter/HostWithShard-fwd-impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace facebook { 14 | namespace memcache { 15 | 16 | class HostInfo; 17 | using HostInfoPtr = std::shared_ptr; 18 | 19 | } // namespace memcache 20 | } // namespace facebook 21 | -------------------------------------------------------------------------------- /mcrouter/McrouterClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "mcrouter/CarbonRouterClient.h" 11 | #include "mcrouter/lib/network/gen/MemcacheRouterInfo.h" 12 | 13 | namespace facebook { 14 | namespace memcache { 15 | namespace mcrouter { 16 | 17 | class McrouterClient { 18 | public: 19 | using Pointer = typename CarbonRouterClient::Pointer; 20 | }; 21 | 22 | } // namespace mcrouter 23 | } // namespace memcache 24 | } // namespace facebook 25 | -------------------------------------------------------------------------------- /mcrouter/McrouterFiberContext.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "McrouterFiberContext.h" 9 | 10 | namespace facebook { 11 | namespace memcache { 12 | namespace mcrouter { 13 | 14 | const RequestClass RequestClass::kFailover{0x1}; 15 | const RequestClass RequestClass::kShadow{0x2}; 16 | 17 | const char* RequestClass::toString() const { 18 | if (is(RequestClass::kFailover) && is(RequestClass::kShadow)) { 19 | return "failover|shadow"; 20 | } else if (is(RequestClass::kFailover)) { 21 | return "failover"; 22 | } else if (is(RequestClass::kShadow)) { 23 | return "shadow"; 24 | } 25 | return "normal"; 26 | } 27 | } // namespace mcrouter 28 | } // namespace memcache 29 | } // namespace facebook 30 | -------------------------------------------------------------------------------- /mcrouter/McrouterInstance.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "mcrouter/CarbonRouterInstance.h" 11 | #include "mcrouter/lib/network/gen/MemcacheRouterInfo.h" 12 | 13 | namespace facebook { 14 | namespace memcache { 15 | namespace mcrouter { 16 | 17 | using McrouterInstance = CarbonRouterInstance; 18 | 19 | } // namespace mcrouter 20 | } // namespace memcache 21 | } // namespace facebook 22 | -------------------------------------------------------------------------------- /mcrouter/McrouterLogFailure.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "McrouterLogFailure.h" 9 | 10 | #include "mcrouter/options.h" 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | namespace mcrouter { 15 | 16 | std::string routerName(const McrouterOptions& opts) { 17 | return "libmcrouter." + opts.service_name + "." + opts.router_name; 18 | } 19 | } // namespace mcrouter 20 | } // namespace memcache 21 | } // namespace facebook 22 | -------------------------------------------------------------------------------- /mcrouter/McrouterLogFailure.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "mcrouter/lib/fbi/cpp/LogFailure.h" 13 | 14 | namespace facebook { 15 | namespace memcache { 16 | 17 | class McrouterOptions; 18 | 19 | namespace mcrouter { 20 | 21 | std::string routerName(const McrouterOptions& opts); 22 | 23 | #define MC_LOG_FAILURE(opts, ...) LOG_FAILURE(routerName(opts), __VA_ARGS__) 24 | } // namespace mcrouter 25 | } // namespace memcache 26 | } // namespace facebook 27 | -------------------------------------------------------------------------------- /mcrouter/ProxyDestinationKey.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace facebook { 14 | namespace memcache { 15 | 16 | struct AccessPoint; 17 | 18 | namespace mcrouter { 19 | 20 | class ProxyDestinationBase; 21 | 22 | struct ProxyDestinationKey { 23 | const AccessPoint& accessPoint; 24 | const std::chrono::milliseconds timeout; 25 | const uint32_t idx{0}; 26 | 27 | explicit ProxyDestinationKey(const ProxyDestinationBase& dst); 28 | ProxyDestinationKey( 29 | const AccessPoint& ap, 30 | std::chrono::milliseconds timeout, 31 | uint32_t idx); 32 | 33 | std::string str() const; 34 | size_t hash() const; 35 | 36 | bool operator==(const ProxyDestinationKey& other) const; 37 | }; 38 | 39 | } // namespace mcrouter 40 | } // namespace memcache 41 | } // namespace facebook 42 | -------------------------------------------------------------------------------- /mcrouter/ProxyRequestPriority.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | namespace facebook { 11 | namespace memcache { 12 | namespace mcrouter { 13 | 14 | enum class ProxyRequestPriority : uint8_t { 15 | kCritical = 0, 16 | kAsync = 1, 17 | kNumPriorities = 2, 18 | }; 19 | 20 | } // namespace mcrouter 21 | } // namespace memcache 22 | } // namespace facebook 23 | -------------------------------------------------------------------------------- /mcrouter/Server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | 15 | class McrouterOptions; 16 | 17 | namespace mcrouter { 18 | 19 | class CarbonRouterInstanceBase; 20 | class McrouterStandaloneOptions; 21 | 22 | using StandalonePreRunCb = 23 | std::function; 24 | 25 | extern thread_local size_t tlsWorkerThreadId; 26 | 27 | /** 28 | * Spawns the standalone server and blocks until it's shutdown. 29 | * 30 | * @return True if server shut down cleanly, false if any errors occurred. 31 | */ 32 | template class RequestHandler> 33 | bool runServer( 34 | const McrouterOptions& mcrouterOpts, 35 | const McrouterStandaloneOptions& standaloneOpts, 36 | StandalonePreRunCb preRunCb = nullptr); 37 | 38 | } // namespace mcrouter 39 | } // namespace memcache 40 | } // namespace facebook 41 | 42 | #include "Server-inl.h" 43 | -------------------------------------------------------------------------------- /mcrouter/ServiceInfo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "mcrouter/ServiceInfo.h" 9 | #include "mcrouter/mcrouter_sr_deps.h" 10 | 11 | namespace facebook::memcache::mcrouter::detail { 12 | 13 | bool srHostInfoPtrFuncRouteHandlesCommandDispatcher( 14 | const HostInfoPtr& host, 15 | std::string& tree, 16 | const int level) { 17 | bool haveHost = (host != nullptr); 18 | tree.append( 19 | std::string(level, ' ') + 20 | "host: " + (haveHost ? host->location().getIp() : "unknown") + " port:" + 21 | (haveHost ? folly::to(host->location().getPort()) 22 | : "unknown") + 23 | '\n'); 24 | return false; 25 | } 26 | 27 | } // namespace facebook::memcache::mcrouter::detail 28 | -------------------------------------------------------------------------------- /mcrouter/ThreadUtil.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "ThreadUtil.h" 9 | 10 | #include 11 | #include 12 | 13 | #include "mcrouter/options.h" 14 | 15 | namespace facebook { 16 | namespace memcache { 17 | namespace mcrouter { 18 | 19 | void mcrouterSetThisThreadName( 20 | const McrouterOptions& opts, 21 | folly::StringPiece prefix, 22 | folly::Optional threadIdx) { 23 | auto name = folly::to(prefix, "-", opts.router_name); 24 | if (threadIdx.has_value()) { 25 | name.append(folly::to("-", threadIdx.value())); 26 | } 27 | if (!folly::setThreadName(name)) { 28 | LOG(WARNING) << "Unable to set thread name to " << name; 29 | } 30 | } 31 | } // namespace mcrouter 32 | } // namespace memcache 33 | } // namespace facebook 34 | -------------------------------------------------------------------------------- /mcrouter/ThreadUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace facebook { 14 | namespace memcache { 15 | 16 | class McrouterOptions; 17 | 18 | namespace mcrouter { 19 | 20 | void mcrouterSetThisThreadName( 21 | const McrouterOptions& opts, 22 | folly::StringPiece prefix, 23 | folly::Optional threadId = folly::none); 24 | } 25 | } // namespace memcache 26 | } // namespace facebook 27 | -------------------------------------------------------------------------------- /mcrouter/TkoCounters.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace facebook { 14 | namespace memcache { 15 | namespace mcrouter { 16 | 17 | /** 18 | * Number of boxes marked as TKO 19 | */ 20 | struct TkoCounters { 21 | std::atomic softTkos{0}; 22 | std::atomic hardTkos{0}; 23 | 24 | size_t totalTko() const { 25 | return softTkos + hardTkos; 26 | } 27 | }; 28 | 29 | } // namespace mcrouter 30 | } // namespace memcache 31 | } // namespace facebook 32 | -------------------------------------------------------------------------------- /mcrouter/TkoLog.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "TkoLog.h" 9 | 10 | #include "mcrouter/lib/network/AccessPoint.h" 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | namespace mcrouter { 15 | 16 | TkoLog::TkoLog(const AccessPoint& ap, const TkoCounters& gt) 17 | : accessPoint(ap), globalTkos(gt) {} 18 | 19 | std::string TkoLog::eventName() const { 20 | switch (event) { 21 | case TkoLogEvent::MarkHardTko: 22 | return "mark_hard_tko"; 23 | case TkoLogEvent::MarkSoftTko: 24 | return "mark_soft_tko"; 25 | case TkoLogEvent::RemoveFromConfig: 26 | return "remove_from_config"; 27 | case TkoLogEvent::UnMarkTko: 28 | return "unmark_tko"; 29 | default: 30 | return "unknown"; 31 | } 32 | } 33 | } // namespace mcrouter 34 | } // namespace memcache 35 | } // namespace facebook 36 | -------------------------------------------------------------------------------- /mcrouter/TkoLog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | #include "mcrouter/TkoCounters.h" 15 | #include "mcrouter/lib/carbon/Result.h" 16 | 17 | namespace facebook { 18 | namespace memcache { 19 | 20 | struct AccessPoint; 21 | 22 | namespace mcrouter { 23 | 24 | enum class TkoLogEvent { 25 | MarkHardTko, 26 | MarkSoftTko, 27 | RemoveFromConfig, 28 | UnMarkTko 29 | }; 30 | 31 | struct TkoLog { 32 | TkoLog(const AccessPoint& ap, const TkoCounters& gt); 33 | 34 | std::string eventName() const; 35 | 36 | TkoLogEvent event{TkoLogEvent::MarkHardTko}; 37 | uintptr_t curSumFailures{0}; 38 | bool isHardTko{false}; 39 | bool isSoftTko{false}; 40 | carbon::Result result; 41 | size_t probesSent{0}; 42 | double avgLatency{0.0}; 43 | const AccessPoint& accessPoint; 44 | const TkoCounters& globalTkos; 45 | }; 46 | } // namespace mcrouter 47 | } // namespace memcache 48 | } // namespace facebook 49 | -------------------------------------------------------------------------------- /mcrouter/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/mcrouter/1f17a1926a19d121caf4818e22636d73657ce675/mcrouter/__init__.py -------------------------------------------------------------------------------- /mcrouter/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | set -e 8 | 9 | autoreconf --install 10 | -------------------------------------------------------------------------------- /mcrouter/lib/AuxiliaryCPUThreadPool.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "AuxiliaryCPUThreadPool.h" 9 | #include 10 | 11 | namespace facebook::memcache::mcrouter { 12 | 13 | // Number of CPU threads to run in CPU thread pool. 14 | constexpr size_t kNumCPUThreads = 5; 15 | 16 | namespace { 17 | folly::Singleton gAuxiliaryCPUThreadPool; 18 | } // namespace 19 | 20 | folly::CPUThreadPoolExecutor& AuxiliaryCPUThreadPool::getThreadPool() { 21 | folly::call_once(initFlag_, [&] { 22 | threadPool_ = std::make_unique( 23 | kNumCPUThreads, 24 | std::make_shared("mcr-cpuaux-")); 25 | }); 26 | 27 | return *threadPool_; 28 | } 29 | 30 | } // namespace facebook::memcache::mcrouter 31 | -------------------------------------------------------------------------------- /mcrouter/lib/AuxiliaryCPUThreadPool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace facebook::memcache::mcrouter { 15 | 16 | /** 17 | * CPU Thread pool that is shared between router intances. 18 | * 19 | * Should not be used directly, use AuxiliaryCPUThreadPoolSingleton instead. 20 | * Thread pool is lazily initialized on first call to getThreadPool(). 21 | */ 22 | class AuxiliaryCPUThreadPool { 23 | public: 24 | folly::CPUThreadPoolExecutor& getThreadPool(); 25 | 26 | private: 27 | std::unique_ptr threadPool_; 28 | folly::once_flag initFlag_; 29 | }; 30 | 31 | using AuxiliaryCPUThreadPoolSingleton = 32 | folly::Singleton; 33 | 34 | } // namespace facebook::memcache::mcrouter 35 | -------------------------------------------------------------------------------- /mcrouter/lib/AuxiliaryIOThreadPool.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "AuxiliaryIOThreadPool.h" 9 | #include 10 | 11 | namespace facebook::memcache::mcrouter { 12 | 13 | // Number of IO threads to run in IO thread pool. 14 | constexpr size_t kNumIOThreads = 5; 15 | 16 | namespace { 17 | folly::Singleton gAuxiliaryIOThreadPool; 18 | } // namespace 19 | 20 | folly::IOThreadPoolExecutorBase& AuxiliaryIOThreadPool::getThreadPool() { 21 | folly::call_once(initFlag_, [&] { 22 | threadPool_ = std::make_unique( 23 | kNumIOThreads, 24 | std::make_shared("mcr-ioaux-")); 25 | }); 26 | 27 | return *threadPool_; 28 | } 29 | 30 | } // namespace facebook::memcache::mcrouter 31 | -------------------------------------------------------------------------------- /mcrouter/lib/AuxiliaryIOThreadPool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace facebook::memcache::mcrouter { 15 | 16 | /** 17 | * IO Thread pool that is shared between router intances. 18 | * 19 | * Should not be used directly, use AuxiliaryIOThreadPoolSingleton instead. 20 | * Thread pool is lazily initialized on first call to getThreadPool(). 21 | */ 22 | class AuxiliaryIOThreadPool { 23 | public: 24 | folly::IOThreadPoolExecutorBase& getThreadPool(); 25 | 26 | private: 27 | std::unique_ptr threadPool_; 28 | folly::once_flag initFlag_; 29 | }; 30 | 31 | using AuxiliaryIOThreadPoolSingleton = folly::Singleton; 32 | 33 | } // namespace facebook::memcache::mcrouter 34 | -------------------------------------------------------------------------------- /mcrouter/lib/Ch3HashFunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "mcrouter/lib/HashFunctionType.h" 13 | #include "mcrouter/lib/fbi/hash.h" 14 | 15 | namespace folly { 16 | struct dynamic; 17 | } // namespace folly 18 | 19 | namespace facebook::memcache { 20 | 21 | /* CH3 consistent hashing function object */ 22 | class Ch3HashFunc { 23 | public: 24 | explicit Ch3HashFunc(size_t n) : n_(n) { 25 | if (!n_ || n_ > furc_maximum_pool_size()) { 26 | throw std::logic_error("Pool size out of range for Ch3"); 27 | } 28 | } 29 | 30 | size_t operator()(folly::StringPiece hashable) const { 31 | return furc_hash(hashable.data(), hashable.size(), n_); 32 | } 33 | 34 | static const char* type() { 35 | return "Ch3"; 36 | } 37 | 38 | static HashFunctionType typeId() { 39 | return HashFunctionType::CH3; 40 | } 41 | 42 | private: 43 | size_t n_; 44 | }; 45 | } // namespace facebook::memcache 46 | -------------------------------------------------------------------------------- /mcrouter/lib/Clocks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace facebook::memcache::cycles { 13 | 14 | /** 15 | * Returns the number of cpu cycles since power-on. This clock doesn't involve 16 | * a system call. This clock does not measure context switches. 17 | * Thread-safe. 18 | * NOTE: Not all cpu and operating systems guarantee that this clock is 19 | * synchronized and increments constantly across all cpu cores. 20 | * This clock has no serializing instruction, which means that for some cpu 21 | * implementations this clock might be inaccurate for measuring a really small 22 | * amount of instructions due to out-of-order execution. 23 | */ 24 | uint64_t getCpuCycles() noexcept; 25 | 26 | } // namespace facebook::memcache::cycles 27 | -------------------------------------------------------------------------------- /mcrouter/lib/Crc32HashFunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "mcrouter/lib/HashFunctionType.h" 13 | #include "mcrouter/lib/fbi/hash.h" 14 | 15 | namespace folly { 16 | struct dynamic; 17 | } // namespace folly 18 | 19 | namespace facebook { 20 | namespace memcache { 21 | 22 | /* Crc32 : crc32 hashing function object */ 23 | class Crc32HashFunc { 24 | public: 25 | explicit Crc32HashFunc(size_t n) : n_(n) {} 26 | 27 | size_t operator()(folly::StringPiece hashable) const { 28 | auto res = crc32_hash(hashable.data(), hashable.size()); 29 | return (res & 0x7fffffff) % n_; 30 | } 31 | 32 | static const char* type() { 33 | return "Crc32"; 34 | } 35 | static HashFunctionType typeId() { 36 | return HashFunctionType::CRC32; 37 | } 38 | 39 | private: 40 | size_t n_; 41 | }; 42 | } // namespace memcache 43 | } // namespace facebook 44 | -------------------------------------------------------------------------------- /mcrouter/lib/HashFunctionType.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | /** 13 | * Types of Hash Functions 14 | */ 15 | enum class HashFunctionType : uint8_t { 16 | Unknown = 0, 17 | CH3 = 1, 18 | ConstShard = 2, 19 | CRC32 = 3, 20 | Rendezvous = 4, 21 | WeightedCh3 = 5, 22 | // unused = 6, 23 | WeightedRendezvous = 7, 24 | WeightedCh3Rv = 8, 25 | }; 26 | -------------------------------------------------------------------------------- /mcrouter/lib/HashUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | namespace facebook { 15 | namespace memcache { 16 | 17 | template 18 | typename std::invoke_result::type hashWithSalt( 19 | const folly::StringPiece key, 20 | const folly::StringPiece salt, 21 | F&& hashFunc) { 22 | constexpr size_t kMaxKeySaltSize = 512; 23 | auto keySaltSize = key.size() + salt.size(); 24 | auto copyAndHash = [&](char* buff) { 25 | memcpy(buff, key.data(), key.size()); 26 | memcpy(buff + key.size(), salt.data(), salt.size()); 27 | return hashFunc({buff, buff + keySaltSize}); 28 | }; 29 | if (keySaltSize <= kMaxKeySaltSize) { 30 | char c[kMaxKeySaltSize]; 31 | return copyAndHash(c); 32 | } else { 33 | std::vector vc(keySaltSize); 34 | return copyAndHash(vc.data()); 35 | } 36 | } 37 | 38 | } // namespace memcache 39 | } // namespace facebook 40 | -------------------------------------------------------------------------------- /mcrouter/lib/IovecCursor-inl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace facebook { 17 | namespace memcache { 18 | 19 | template 20 | T IovecCursor::peek() const { 21 | static_assert(std::is_integral::value, "Read requires an integral type"); 22 | 23 | if (FOLLY_LIKELY(curBufLen_ >= sizeof(T))) { 24 | return folly::loadUnaligned( 25 | reinterpret_cast(iov_[iovIndex_].iov_base) + curBufPos_); 26 | } 27 | 28 | uint8_t buf[sizeof(T)]; 29 | peekInto(buf, sizeof(T)); 30 | T val; 31 | std::memcpy(&val, buf, sizeof(T)); 32 | return val; 33 | } 34 | 35 | template 36 | T IovecCursor::read() { 37 | T val = peek(); 38 | advance(sizeof(T)); 39 | return val; 40 | } 41 | 42 | } // namespace memcache 43 | } // namespace facebook 44 | -------------------------------------------------------------------------------- /mcrouter/lib/Lz4ImmutableCompressionCodec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "mcrouter/lib/Compression.h" 11 | #include "mcrouter/lib/Lz4Immutable.h" 12 | 13 | namespace facebook { 14 | namespace memcache { 15 | 16 | class Lz4ImmutableCompressionCodec : public CompressionCodec { 17 | public: 18 | Lz4ImmutableCompressionCodec( 19 | std::unique_ptr dictionary, 20 | uint32_t id, 21 | FilteringOptions codecFilteringOptions, 22 | uint32_t codecCompressionLevel); 23 | 24 | std::unique_ptr compress(const struct iovec* iov, size_t iovcnt) 25 | final; 26 | 27 | std::unique_ptr uncompress( 28 | const struct iovec* iov, 29 | size_t iovcnt, 30 | size_t uncompressedSize) final; 31 | 32 | private: 33 | Lz4Immutable codec_; 34 | }; 35 | 36 | } // namespace memcache 37 | } // namespace facebook 38 | -------------------------------------------------------------------------------- /mcrouter/lib/Operation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | namespace facebook { 11 | namespace memcache { 12 | 13 | template 14 | using ReplyT = typename Request::reply_type; 15 | 16 | } // namespace memcache 17 | } // namespace facebook 18 | -------------------------------------------------------------------------------- /mcrouter/lib/PoolContext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | namespace facebook { 15 | namespace memcache { 16 | 17 | /** 18 | * Struct that holds information about a given destination in a pool. 19 | */ 20 | struct PoolContext { 21 | folly::StringPiece poolName; 22 | size_t indexInPool; 23 | bool isShadow; 24 | }; 25 | 26 | } // namespace memcache 27 | } // namespace facebook 28 | -------------------------------------------------------------------------------- /mcrouter/lib/RendezvousHashHelper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "mcrouter/lib/RendezvousHashHelper.h" 9 | #include "mcrouter/lib/fbi/hash.h" 10 | 11 | namespace facebook { 12 | namespace memcache { 13 | 14 | RendezvousIterator::RendezvousIterator(std::vector scores) 15 | : queue_{std::less(), std::move(scores)} {} 16 | 17 | RendezvousIterator& RendezvousIterator::operator++() { 18 | if (!queue_.empty()) { 19 | queue_.pop(); 20 | } 21 | 22 | return *this; 23 | } 24 | 25 | uint64_t RendezvousIterator::keyHash(folly::StringPiece key) { 26 | return murmur_hash_64A(key.data(), key.size(), kRendezvousExtraHashSeed); 27 | } 28 | 29 | } // namespace memcache 30 | } // namespace facebook 31 | -------------------------------------------------------------------------------- /mcrouter/lib/RuntimeVarsData.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "RuntimeVarsData.h" 9 | 10 | #include "mcrouter/lib/fbi/cpp/util.h" 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | namespace mcrouter { 15 | 16 | RuntimeVarsData::RuntimeVarsData(folly::StringPiece json) 17 | : configData_(parseJsonString(json)) {} 18 | 19 | folly::dynamic RuntimeVarsData::getVariableByName( 20 | folly::StringPiece name) const { 21 | return configData_.getDefault(name, nullptr); 22 | } 23 | } // namespace mcrouter 24 | } // namespace memcache 25 | } // namespace facebook 26 | -------------------------------------------------------------------------------- /mcrouter/lib/RuntimeVarsData.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace facebook { 14 | namespace memcache { 15 | namespace mcrouter { 16 | 17 | class RuntimeVarsData { 18 | public: 19 | RuntimeVarsData() = default; 20 | explicit RuntimeVarsData(folly::StringPiece json); 21 | 22 | /** 23 | * Returns the value of the variable with key = name. 24 | * 25 | * @param name key of the data to be retrieved 26 | * @return Variable value, or null if key not found 27 | */ 28 | folly::dynamic getVariableByName(folly::StringPiece name) const; 29 | 30 | private: 31 | folly::dynamic configData_; 32 | }; 33 | } // namespace mcrouter 34 | } // namespace memcache 35 | } // namespace facebook 36 | -------------------------------------------------------------------------------- /mcrouter/lib/StatsReply.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "StatsReply.h" 9 | 10 | #include 11 | 12 | #include "mcrouter/lib/network/gen/MemcacheMessages.h" 13 | 14 | namespace facebook { 15 | namespace memcache { 16 | 17 | McStatsReply StatsReply::getReply() { 18 | /** 19 | * In the 'stats' IOBuf, we store the string representation returned to 20 | * clients, e.g., 21 | * "STAT stat1 value1\r\nSTAT stat2 value2\r\n..." 22 | */ 23 | 24 | McStatsReply reply(carbon::Result::OK); 25 | std::vector statsList; 26 | 27 | for (const auto& s : stats_) { 28 | statsList.emplace_back( 29 | folly::to("STAT ", s.first, ' ', s.second)); 30 | } 31 | 32 | reply.stats_ref() = std::move(statsList); 33 | 34 | return reply; 35 | } 36 | } // namespace memcache 37 | } // namespace facebook 38 | -------------------------------------------------------------------------------- /mcrouter/lib/StatsReply.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace facebook { 16 | namespace memcache { 17 | 18 | class McStatsReply; 19 | 20 | class StatsReply { 21 | public: 22 | template 23 | void addStat(folly::StringPiece name, V&& value) { 24 | stats_.emplace_back( 25 | name.str(), folly::to(std::forward(value))); 26 | } 27 | 28 | McStatsReply getReply(); 29 | 30 | private: 31 | std::vector> stats_; 32 | }; 33 | } // namespace memcache 34 | } // namespace facebook 35 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/Artillery.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace carbon { 13 | namespace tracing { 14 | 15 | /** 16 | * Serialized a traceContext in order to send it over the wire. 17 | */ 18 | std::pair serializeTraceContext( 19 | const std::string& traceContext); 20 | 21 | /** 22 | * Deserializes a traceContext after receiving it over the wire. 23 | */ 24 | std::string deserializeTraceContext( 25 | std::pair serializedTraceId); 26 | 27 | } // namespace tracing 28 | } // namespace carbon 29 | 30 | #include "Artillery-inl.h" 31 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/CarbonProtocolCommon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace carbon { 13 | namespace detail { 14 | 15 | constexpr size_t kDefaultStackSize = 16; 16 | } 17 | } // namespace carbon 18 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/CmdLineClient-inl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace carbon { 13 | namespace tools { 14 | 15 | template 16 | void CmdLineClient::sendRequests(int argc, const char** argv) { 17 | auto settings = parseSettings(argc, argv); 18 | Client jsonClient(settings.clientOptions, [this](const std::string& msg) { 19 | targetErr_ << msg << std::endl; 20 | }); 21 | sendRequests(jsonClient, settings.requestName, settings.data); 22 | } 23 | 24 | } // namespace tools 25 | } // namespace carbon 26 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/NoopExternalConnectionLogger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "mcrouter/lib/carbon/ExternalCarbonConnectionStats.h" 11 | 12 | namespace carbon { 13 | 14 | class NoopExternalConnectionAdditionalLogger { 15 | public: 16 | explicit NoopExternalConnectionAdditionalLogger( 17 | carbon::ExternalCarbonConnectionLoggerOptions&) {} 18 | 19 | void log(carbon::ExternalCarbonConnectionStats&) {} 20 | 21 | bool shouldLog() const { 22 | return false; 23 | } 24 | 25 | void setEnabledStatus(bool /* unused */) {} 26 | bool getEnabledStatus() { 27 | return false; 28 | } 29 | }; 30 | } // namespace carbon 31 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/Result.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "mcrouter/lib/carbon/Result.h" 9 | 10 | #include 11 | 12 | namespace carbon { 13 | 14 | namespace { 15 | std::unordered_map makeStringToResultMap() { 16 | std::unordered_map resMap; 17 | for (size_t i = static_cast(Result::UNKNOWN); 18 | i < static_cast(Result::NUM_RESULTS); 19 | ++i) { 20 | auto res = static_cast(i); 21 | resMap[resultToString(res)] = res; 22 | } 23 | return resMap; 24 | } 25 | 26 | const static std::unordered_map kStringToResult = 27 | makeStringToResultMap(); 28 | } // anonymous namespace 29 | 30 | Result resultFromString(const char* result) { 31 | auto it = kStringToResult.find(result); 32 | if (it != kStringToResult.cend()) { 33 | return it->second; 34 | } 35 | return Result::UNKNOWN; 36 | } 37 | 38 | } // namespace carbon 39 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/SerializationTraits.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | namespace carbon { 11 | 12 | class CarbonProtocolReader; 13 | 14 | class CarbonQueueAppenderStorage; 15 | 16 | template 17 | class CarbonProtocolWriterImpl; 18 | 19 | using CarbonProtocolWriter = 20 | CarbonProtocolWriterImpl; 21 | 22 | /* 23 | * A user type may be used in a Carbon structure if the user provides an 24 | * appropriate specialization of carbon::SerializationTraits. The following 25 | * methods should be provided in such a specialization: 26 | * 27 | * template 28 | * struct SerializationTraits; 29 | * static T read(CarbonProtocolReader&); 30 | * static void write(const T&, CarbonProtocolReader&); 31 | * static bool isEmpty(const T&); 32 | * }; 33 | */ 34 | template 35 | struct SerializationTraits; 36 | 37 | } // namespace carbon 38 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/Util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace carbon { 13 | namespace util { 14 | 15 | inline uint16_t zigzag(const int16_t i) { 16 | return (static_cast(i) << 1) ^ static_cast(i >> 15); 17 | } 18 | 19 | inline uint32_t zigzag(const int32_t i) { 20 | return (static_cast(i) << 1) ^ static_cast(i >> 31); 21 | } 22 | 23 | inline uint64_t zigzag(const int64_t i) { 24 | return (static_cast(i) << 1) ^ static_cast(i >> 63); 25 | } 26 | 27 | inline int16_t unzigzag(const uint16_t i) { 28 | return (i >> 1) ^ -(i & 1); 29 | } 30 | 31 | inline int32_t unzigzag(const uint32_t i) { 32 | return (i >> 1) ^ -(i & 1); 33 | } 34 | 35 | inline int64_t unzigzag(const uint64_t i) { 36 | return (i >> 1) ^ -(i & 1); 37 | } 38 | 39 | } // namespace util 40 | } // namespace carbon 41 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/carbon.thrift: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | namespace cpp2 carbon.thrift 9 | namespace py3 carbon.thrift 10 | 11 | cpp_include "" 12 | 13 | include "thrift/annotation/cpp.thrift" 14 | 15 | @cpp.Adapter{name = "::carbon::KeysAdapter"} 16 | typedef IOBuf IOBufKey 17 | 18 | @cpp.Adapter{name = "::carbon::KeysAdapter"} 19 | typedef binary StringKey 20 | 21 | @cpp.Type{name = "uint8_t"} 22 | typedef byte ui8 23 | 24 | @cpp.Type{name = "uint16_t"} 25 | typedef i16 ui16 26 | 27 | @cpp.Type{name = "uint32_t"} 28 | typedef i32 ui32 29 | 30 | @cpp.Type{name = "uint64_t"} 31 | typedef i64 ui64 32 | 33 | @cpp.Type{name = "folly::IOBuf"} 34 | typedef binary IOBuf 35 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/connection/CarbonConnectionUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace carbon { 17 | 18 | class CarbonConnectionRecreateException : public std::runtime_error { 19 | public: 20 | explicit CarbonConnectionRecreateException(const std::string& what) 21 | : std::runtime_error(what) {} 22 | }; 23 | 24 | class CarbonConnectionException : public std::runtime_error { 25 | public: 26 | explicit CarbonConnectionException(const std::string& what) 27 | : std::runtime_error(what) {} 28 | }; 29 | 30 | template 31 | using RequestCb = 32 | std::function&&)>; 33 | } // namespace carbon 34 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/example/HelloGoodbyeTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include "mcrouter/lib/carbon/example/gen/HelloGoodbyeRouterInfo.h" 11 | 12 | TEST(HelloGoodbye, getTypeIdByName) { 13 | EXPECT_EQ( 14 | carbon::getTypeIdByName( 15 | "hello", hellogoodbye::HelloGoodbyeRouterInfo::RoutableRequests()), 16 | 65); 17 | EXPECT_EQ( 18 | carbon::getTypeIdByName( 19 | "hello1", hellogoodbye::HelloGoodbyeRouterInfo::RoutableRequests()), 20 | 0); 21 | } 22 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/example/gen/HelloGoodbye.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #pragma once 16 | 17 | #include "mcrouter/lib/carbon/example/gen/HelloGoodbyeMessages.h" 18 | #include "mcrouter/lib/carbon/example/gen/HelloGoodbyeServer.h" 19 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/example/gen/HelloGoodbyeMessages.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #include "HelloGoodbyeMessages.h" 16 | 17 | namespace hellogoodbye { 18 | 19 | std::string enumEnumUInt32ToString(EnumUInt32 val) { 20 | switch (val) { 21 | case EnumUInt32::HIGH: 22 | return "HIGH"; 23 | case EnumUInt32::URGENT: 24 | return "URGENT"; 25 | case EnumUInt32::YESTERDAY: 26 | return "YESTERDAY"; 27 | } 28 | return ""; 29 | } 30 | 31 | constexpr const char* const HelloRequest::name; 32 | 33 | constexpr const char* const GoodbyeRequest::name; 34 | 35 | } // namespace hellogoodbye 36 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/example/gen/HelloGoodbyeRouterInfo-BuildExtraProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #include "HelloGoodbyeRouterInfo.h" 16 | 17 | #include 18 | 19 | using namespace facebook::memcache; 20 | using namespace facebook::memcache::mcrouter; 21 | 22 | namespace hellogoodbye { 23 | 24 | /* static */ 25 | std::unique_ptr> 26 | HelloGoodbyeRouterInfo::buildExtraProvider() { 27 | return std::make_unique>(); 28 | } 29 | 30 | } // namespace hellogoodbye 31 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/A.idl: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | namespace carbon::test::A; 7 | thrift_namespace carbon.test.A.thrift; 8 | 9 | import "mcrouter/lib/network/Common.idl" 10 | import "mcrouter/lib/carbon/test/B.idl" 11 | thrift_import "graphene/ticket/if/ticket_rep.thrift" 12 | include "graphene/ticket/if/gen-cpp2/ticket_rep_types.h" 13 | cpp2_include "mcrouter/lib/carbon/test/gen/BMessages.h" 14 | 15 | request TestARequest { 16 | id: 3; 17 | name: "testA"; 18 | reply: TestAReply; 19 | 20 | 1: carbon::Keys key; 21 | 2: bool dummy2; 22 | 3: optional B::TRep ticket; 23 | }; 24 | 25 | reply TestAReply { 26 | 1: Result result; 27 | 2: int32_t valInt32; 28 | }; 29 | 30 | service { 31 | enable_shutdown: true; 32 | 33 | routing_groups: { 34 | no_group: [ 35 | TestARequest, 36 | ] 37 | }; 38 | }; 39 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/B.idl: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | namespace carbon::test::B; 7 | thrift_namespace carbon.test.B.thrift; 8 | 9 | import "mcrouter/lib/network/Common.idl" 10 | include "graphene/ticket/if/gen-cpp2/ticket_rep_types.h" 11 | 12 | struct TRep extern graphene::ticket::cpp2::TicketRep idl "graphene/ticket/if/ticket_rep.thrift"; 13 | 14 | request TestBRequest { 15 | id: 3; 16 | name: "testB"; 17 | reply: TestBReply; 18 | 19 | 1: carbon::Keys key; 20 | 2: bool dummy2; 21 | 3: optional TRep ticket; 22 | }; 23 | 24 | reply TestBReply { 25 | 1: Result result; 26 | 2: int32_t valInt32; 27 | }; 28 | 29 | service { 30 | enable_shutdown: true; 31 | 32 | routing_groups: { 33 | no_group: [ 34 | TestBRequest, 35 | ] 36 | }; 37 | }; 38 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/Timestamp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "mcrouter/lib/carbon/test/Timestamp.h" 9 | 10 | namespace carbon { 11 | namespace test { 12 | 13 | uint64_t Timestamp::toUint64() const { 14 | return v_; 15 | } 16 | 17 | Timestamp Timestamp::fromUint64(uint64_t value) { 18 | return Timestamp(value); 19 | } 20 | 21 | int64_t Timestamp::toInt64() const { 22 | return static_cast(toUint64()); 23 | } 24 | 25 | Timestamp Timestamp::fromInt64(int64_t value) { 26 | return fromUint64(static_cast(value)); 27 | } 28 | 29 | } // namespace test 30 | } // namespace carbon 31 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/VariantTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include "mcrouter/lib/carbon/Variant.h" 13 | 14 | TEST(Variant, basic) { 15 | carbon::Variant var; 16 | 17 | var.emplace("abc"); 18 | EXPECT_EQ("abc", var.get()); 19 | EXPECT_EQ(std::type_index(typeid(std::string)), var.which()); 20 | EXPECT_TRUE(var.is()); 21 | EXPECT_FALSE(var.is()); 22 | 23 | var.emplace(123); 24 | EXPECT_EQ(123, var.get()); 25 | EXPECT_EQ(std::type_index(typeid(int)), var.which()); 26 | EXPECT_TRUE(var.is()); 27 | EXPECT_FALSE(var.is()); 28 | } 29 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/gen/A.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #pragma once 16 | 17 | #include "mcrouter/lib/carbon/test/gen/AMessages.h" 18 | #include "mcrouter/lib/carbon/test/gen/AServer.h" 19 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/gen/AMessages.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #include "AMessages.h" 16 | 17 | namespace carbon { 18 | namespace test { 19 | namespace A { 20 | 21 | constexpr const char* const TestARequest::name; 22 | 23 | } // namespace A 24 | } // namespace test 25 | } // namespace carbon 26 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/gen/ARouterInfo-BuildExtraProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #include "ARouterInfo.h" 16 | 17 | #include 18 | 19 | using namespace facebook::memcache; 20 | using namespace facebook::memcache::mcrouter; 21 | 22 | namespace carbon { 23 | namespace test { 24 | namespace A { 25 | 26 | /* static */ 27 | std::unique_ptr> 28 | ARouterInfo::buildExtraProvider() { 29 | return std::make_unique>(); 30 | } 31 | 32 | } // namespace A 33 | } // namespace test 34 | } // namespace carbon 35 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/gen/ARoutingGroups.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #pragma once 16 | 17 | #include 18 | 19 | #include "mcrouter/lib/carbon/test/gen/AMessages.h" 20 | 21 | namespace carbon { 22 | 23 | // ArithmeticLike 24 | template <> 25 | struct ArithmeticLike { 26 | static const bool value = false; 27 | }; 28 | 29 | // DeleteLike 30 | template <> 31 | struct DeleteLike { 32 | static const bool value = false; 33 | }; 34 | 35 | // GetLike 36 | template <> 37 | struct GetLike { 38 | static const bool value = false; 39 | }; 40 | 41 | // UpdateLike 42 | template <> 43 | struct UpdateLike { 44 | static const bool value = false; 45 | }; 46 | } // namespace carbon 47 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/gen/B.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #pragma once 16 | 17 | #include "mcrouter/lib/carbon/test/gen/BMessages.h" 18 | #include "mcrouter/lib/carbon/test/gen/BServer.h" 19 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/gen/BMessages.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #include "BMessages.h" 16 | 17 | namespace carbon { 18 | namespace test { 19 | namespace B { 20 | 21 | constexpr const char* const TestBRequest::name; 22 | 23 | } // namespace B 24 | } // namespace test 25 | } // namespace carbon 26 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/gen/BRouterInfo-BuildExtraProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #include "BRouterInfo.h" 16 | 17 | #include 18 | 19 | using namespace facebook::memcache; 20 | using namespace facebook::memcache::mcrouter; 21 | 22 | namespace carbon { 23 | namespace test { 24 | namespace B { 25 | 26 | /* static */ 27 | std::unique_ptr> 28 | BRouterInfo::buildExtraProvider() { 29 | return std::make_unique>(); 30 | } 31 | 32 | } // namespace B 33 | } // namespace test 34 | } // namespace carbon 35 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/gen/BRoutingGroups.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #pragma once 16 | 17 | #include 18 | 19 | #include "mcrouter/lib/carbon/test/gen/BMessages.h" 20 | 21 | namespace carbon { 22 | 23 | // ArithmeticLike 24 | template <> 25 | struct ArithmeticLike { 26 | static const bool value = false; 27 | }; 28 | 29 | // DeleteLike 30 | template <> 31 | struct DeleteLike { 32 | static const bool value = false; 33 | }; 34 | 35 | // GetLike 36 | template <> 37 | struct GetLike { 38 | static const bool value = false; 39 | }; 40 | 41 | // UpdateLike 42 | template <> 43 | struct UpdateLike { 44 | static const bool value = false; 45 | }; 46 | } // namespace carbon 47 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/gen/CarbonTest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #pragma once 16 | 17 | #include "mcrouter/lib/carbon/test/gen/CarbonTestMessages.h" 18 | #include "mcrouter/lib/carbon/test/gen/CarbonTestServer.h" 19 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/gen/CarbonTestRouterInfo-BuildExtraProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #include "CarbonTestRouterInfo.h" 16 | 17 | #include 18 | 19 | using namespace facebook::memcache; 20 | using namespace facebook::memcache::mcrouter; 21 | 22 | namespace carbon { 23 | namespace test { 24 | 25 | /* static */ 26 | std::unique_ptr> 27 | CarbonTestRouterInfo::buildExtraProvider() { 28 | return std::make_unique>(); 29 | } 30 | 31 | } // namespace test 32 | } // namespace carbon 33 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/gen/CarbonThriftTest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #pragma once 16 | 17 | #include "mcrouter/lib/carbon/test/gen/CarbonThriftTestMessages.h" 18 | #include "mcrouter/lib/carbon/test/gen/CarbonThriftTestServer.h" 19 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/gen/CarbonThriftTestMessages.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #include "CarbonThriftTestMessages.h" 16 | 17 | namespace carbon { 18 | namespace test { 19 | 20 | std::string enumMyEnumToString(MyEnum val) { 21 | switch (val) { 22 | case MyEnum::A: 23 | return "A"; 24 | case MyEnum::B: 25 | return "B"; 26 | case MyEnum::C: 27 | return "C"; 28 | } 29 | return ""; 30 | } 31 | 32 | constexpr const char* const ThriftTestRequest::name; 33 | 34 | constexpr const char* const DummyThriftRequest::name; 35 | 36 | constexpr const char* const CustomRequest::name; 37 | 38 | } // namespace test 39 | } // namespace carbon 40 | -------------------------------------------------------------------------------- /mcrouter/lib/carbon/test/gen/CarbonThriftTestRouterInfo-BuildExtraProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #include "CarbonThriftTestRouterInfo.h" 16 | 17 | #include 18 | 19 | using namespace facebook::memcache; 20 | using namespace facebook::memcache::mcrouter; 21 | 22 | namespace carbon { 23 | namespace test { 24 | 25 | /* static */ 26 | std::unique_ptr> 27 | CarbonThriftTestRouterInfo::buildExtraProvider() { 28 | return std::make_unique>(); 29 | } 30 | 31 | } // namespace test 32 | } // namespace carbon 33 | -------------------------------------------------------------------------------- /mcrouter/lib/config/ImportResolverIf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | namespace facebook { 15 | namespace memcache { 16 | 17 | /** 18 | * Used by ConfigPreprocessor. Implementation should load additional files 19 | * by path passed to @import macro. 20 | */ 21 | class ImportResolverIf { 22 | public: 23 | /** 24 | * @param path parameter passed to @import macro 25 | * 26 | * @return JSON with macros 27 | */ 28 | virtual std::string import(folly::StringPiece path) = 0; 29 | 30 | virtual ~ImportResolverIf() {} 31 | }; 32 | } // namespace memcache 33 | } // namespace facebook 34 | -------------------------------------------------------------------------------- /mcrouter/lib/config/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | SUBDIRS = test 7 | -------------------------------------------------------------------------------- /mcrouter/lib/config/test/.gitignore: -------------------------------------------------------------------------------- 1 | /mcrouter_config_test 2 | -------------------------------------------------------------------------------- /mcrouter/lib/config/test/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | check_PROGRAMS = mcrouter_config_test 7 | 8 | mcrouter_config_test_SOURCES = \ 9 | main.cpp \ 10 | config_preprocessor_test.cpp \ 11 | rendezvous_hash_test.cpp 12 | 13 | mcrouter_config_test_CPPFLAGS = \ 14 | -I$(top_srcdir)/.. \ 15 | -isystem $(top_srcdir)/lib/gtest/include 16 | 17 | mcrouter_config_test_LDADD = \ 18 | $(top_builddir)/lib/libmcrouter.a \ 19 | $(top_builddir)/lib/libtestmain.la 20 | -------------------------------------------------------------------------------- /mcrouter/lib/config/test/config_preprocessor_test_comments.json: -------------------------------------------------------------------------------- 1 | // first line "/*/" /**/ 2 | { /* "string" */ 3 | /* "*/"orig": { 4 | "str": /* inline */ "//\"", 5 | "comm": "/**/ //\"//\//" 6 | }, 7 | // inside 8 | /** 9 | * multiline 10 | * "" 11 | */ 12 | "expand": { 13 | /* inline2 */ "str": "//\"", 14 | "comm": "/**/ //\"//\//" 15 | /* // "" */ 16 | /**//* */ /*//* / **/ 17 | /**/ 18 | } 19 | } // end of line 20 | /* 21 | {} -------------------------------------------------------------------------------- /mcrouter/lib/config/test/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | // Configure folly to enable INFO+ messages, and everything else to 11 | // enable WARNING+. 12 | // Set the default log handler to log asynchronously by default. 13 | FOLLY_INIT_LOGGING_CONFIG(".=WARNING,folly=INFO; default:async=true"); 14 | -------------------------------------------------------------------------------- /mcrouter/lib/fbi/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.lo 3 | *.la 4 | 5 | .mm* 6 | mm.log 7 | 8 | /Makefile 9 | /Makefile.in 10 | /compile 11 | /build/ 12 | /.deps/ 13 | /.libs/ 14 | /aclocal.m4 15 | /autom4te.cache 16 | /config.* 17 | /configure 18 | /compile 19 | /depcomp 20 | /install-sh 21 | /libtool 22 | /ltmain.sh 23 | /missing 24 | /stamp-h1 25 | 26 | __pycache__ 27 | -------------------------------------------------------------------------------- /mcrouter/lib/fbi/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | SUBDIRS = . cpp test 7 | -------------------------------------------------------------------------------- /mcrouter/lib/fbi/WeightedFurcHash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace facebook { 13 | namespace mcrouter { 14 | 15 | uint32_t weightedFurcHash( 16 | folly::StringPiece key, 17 | folly::Range weights, 18 | uint32_t maxRetries = 32); 19 | 20 | } // namespace mcrouter 21 | } // namespace facebook 22 | -------------------------------------------------------------------------------- /mcrouter/lib/fbi/cpp/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | SUBDIRS = test 7 | -------------------------------------------------------------------------------- /mcrouter/lib/fbi/cpp/globals.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | namespace globals { 15 | 16 | /** 17 | * @return lazy-initialized hostid. 18 | */ 19 | uint32_t hostid(); 20 | 21 | /** 22 | * FOR TEST PURPOSES ONLY 23 | * 24 | * Allows to override hostid for testing purposes, resets it on destruction. 25 | */ 26 | struct HostidMock { 27 | explicit HostidMock(uint32_t value); 28 | void reset(); 29 | ~HostidMock() { 30 | reset(); 31 | } 32 | }; 33 | } // namespace globals 34 | } // namespace memcache 35 | } // namespace facebook 36 | -------------------------------------------------------------------------------- /mcrouter/lib/fbi/cpp/test/.gitignore: -------------------------------------------------------------------------------- 1 | /mcrouter_fbi_cpp_test 2 | -------------------------------------------------------------------------------- /mcrouter/lib/fbi/cpp/test/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | check_PROGRAMS = mcrouter_fbi_cpp_test 7 | 8 | mcrouter_fbi_cpp_test_SOURCES = \ 9 | main.cpp 10 | 11 | mcrouter_fbi_cpp_test_CPPFLAGS = \ 12 | -I$(top_srcdir)/.. \ 13 | -isystem $(top_srcdir)/lib/gtest/include 14 | 15 | mcrouter_fbi_cpp_test_LDADD = \ 16 | $(top_builddir)/lib/libmcrouter.a \ 17 | $(top_builddir)/lib/libtestmain.la 18 | -------------------------------------------------------------------------------- /mcrouter/lib/fbi/cpp/test/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | // Configure folly to enable INFO+ messages, and everything else to 11 | // enable WARNING+. 12 | // Set the default log handler to log asynchronously by default. 13 | FOLLY_INIT_LOGGING_CONFIG(".=WARNING,folly=INFO; default:async=true"); 14 | -------------------------------------------------------------------------------- /mcrouter/lib/fbi/decls.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | /* __BEGIN_DECLS should be used at the beginning of your declarations, 11 | so that C++ compilers don't mangle their names. Use __END_DECLS at 12 | the end of C declarations. */ 13 | #undef __BEGIN_DECLS 14 | #undef __END_DECLS 15 | #if defined(__cplusplus) 16 | #define __BEGIN_DECLS extern "C" { 17 | #define __END_DECLS } 18 | #else 19 | #define __BEGIN_DECLS /* empty */ 20 | #define __END_DECLS /* empty */ 21 | #endif /* #if defined(__cplusplus) */ 22 | -------------------------------------------------------------------------------- /mcrouter/lib/fbi/test/.gitignore: -------------------------------------------------------------------------------- 1 | /mcrouter_fbi_test 2 | -------------------------------------------------------------------------------- /mcrouter/lib/fbi/test/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | check_PROGRAMS = mcrouter_fbi_test 7 | 8 | mcrouter_fbi_test_SOURCES = \ 9 | main.cpp \ 10 | sem_test.cpp \ 11 | test_util.cpp \ 12 | hash_test 13 | 14 | mcrouter_fbi_test_CPPFLAGS = \ 15 | -I$(top_srcdir)/.. \ 16 | -isystem $(top_srcdir)/lib/gtest/include 17 | 18 | mcrouter_fbi_test_LDADD = \ 19 | $(top_builddir)/lib/libmcrouter.a \ 20 | $(top_builddir)/lib/libtestmain.la 21 | -------------------------------------------------------------------------------- /mcrouter/lib/fbi/test/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | // Configure folly to enable INFO+ messages, and everything else to 11 | // enable WARNING+. 12 | // Set the default log handler to log asynchronously by default. 13 | FOLLY_INIT_LOGGING_CONFIG(".=WARNING,folly=INFO; default:async=true"); 14 | -------------------------------------------------------------------------------- /mcrouter/lib/fbi/test/test_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | double measure_time(std::function f); 13 | double measure_time_concurrent( 14 | unsigned thread_count, 15 | std::function f); 16 | -------------------------------------------------------------------------------- /mcrouter/lib/fbi/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifndef ACCESS_ONCE 11 | #define ACCESS_ONCE(x) (*((volatile __typeof__(x)*)&(x))) 12 | #endif 13 | -------------------------------------------------------------------------------- /mcrouter/lib/invalidation/McInvalidationDefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | 15 | inline const std::string kMcDeleteReqAttrInvalidationTimeout = 16 | "invalidation_timeout"; 17 | inline const std::string kMcDeleteReqAttrDBLogTimestamp = "dblog_timestamp"; 18 | inline const std::string kMcDeleteReqAttrSource = "source"; 19 | inline const std::string kMcDeleteReqHlc = "hlc"; 20 | 21 | enum class McDeleteRequestSource : uint8_t { 22 | UNKNOWN, 23 | INGESTION_SERVICE, 24 | GLOSTIC, 25 | FAILED_INVALIDATION, 26 | CROSS_REGION_BROADCAST_INVALIDATION, 27 | CROSS_REGION_DIRECTED_INVALIDATION, 28 | }; 29 | 30 | } // namespace memcache 31 | } // namespace facebook 32 | -------------------------------------------------------------------------------- /mcrouter/lib/mc/mc_fbtrace_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #ifndef FB_MEMCACHE_MC_FBTRACE_H 9 | #define FB_MEMCACHE_MC_FBTRACE_H 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "fbtrace/libfbtrace/c/fbtrace.h" 16 | #include "fbtrace/libfbtrace/c/fbtrace_encode.h" 17 | 18 | __BEGIN_DECLS 19 | 20 | typedef struct mc_fbtrace_s { 21 | int _refcount; 22 | fbtrace_node_t node; 23 | } mc_fbtrace_t; 24 | 25 | typedef struct mc_fbtrace_info_s { 26 | int _refcount; 27 | mc_fbtrace_t* fbtrace; 28 | fbtrace_remote_node_t child_node; 29 | char metadata[FBTRACE_METADATA_SZ + 1]; 30 | } mc_fbtrace_info_t; 31 | 32 | mc_fbtrace_info_t* new_mc_fbtrace_info(int is_copy); 33 | mc_fbtrace_info_t* mc_fbtrace_info_deep_copy(const mc_fbtrace_info_t* orig); 34 | void mc_fbtrace_info_decref(mc_fbtrace_info_t* fbt_w); 35 | mc_fbtrace_info_t* mc_fbtrace_info_incref(mc_fbtrace_info_t* fbt_w); 36 | 37 | __END_DECLS 38 | 39 | #endif // FB_MEMCACHE_MC_FBTRACE_H 40 | -------------------------------------------------------------------------------- /mcrouter/lib/network/.gitignore: -------------------------------------------------------------------------------- 1 | /mock_mc_server 2 | -------------------------------------------------------------------------------- /mcrouter/lib/network/ConnectionDownReason.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | namespace facebook { 11 | namespace memcache { 12 | 13 | enum class ConnectionDownReason { 14 | ERROR, 15 | ABORTED, 16 | CONNECT_TIMEOUT, 17 | CONNECT_ERROR, 18 | SERVER_GONE_AWAY, 19 | }; 20 | 21 | } // namespace memcache 22 | } // namespace facebook 23 | -------------------------------------------------------------------------------- /mcrouter/lib/network/FBTrace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "mcrouter/lib/carbon/Result.h" 13 | #include "mcrouter/lib/mc/protocol.h" 14 | #include "mcrouter/lib/network/AccessPoint.h" 15 | 16 | namespace facebook { 17 | namespace mcrouter { 18 | 19 | // Returns true if a rate limiting check passes and tracing can proceed. 20 | bool traceCheckRateLimit(); 21 | 22 | // Returns the cumulative number of traces logged. 23 | uint64_t traceGetCount(); 24 | 25 | } // namespace mcrouter 26 | } // namespace facebook 27 | 28 | #include "FBTrace-inl.h" 29 | -------------------------------------------------------------------------------- /mcrouter/lib/network/FailureDomains.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include "mcrouter/lib/network/FailureDomains.h" 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | namespace mcrouter { 15 | 16 | uint32_t getFailureDomainHash(folly::StringPiece failureDomain) { 17 | return folly::hash::SpookyHashV2::Hash32( 18 | failureDomain.begin(), failureDomain.size(), 0); 19 | } 20 | 21 | } // namespace mcrouter 22 | } // namespace memcache 23 | } // namespace facebook 24 | -------------------------------------------------------------------------------- /mcrouter/lib/network/FailureDomains.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace facebook { 14 | namespace memcache { 15 | namespace mcrouter { 16 | 17 | uint32_t getFailureDomainHash(folly::StringPiece failureDomain); 18 | 19 | } // namespace mcrouter 20 | } // namespace memcache 21 | } // namespace facebook 22 | -------------------------------------------------------------------------------- /mcrouter/lib/network/McSerializedRequest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "mcrouter/lib/network/McSerializedRequest.h" 9 | 10 | namespace facebook { 11 | namespace memcache { 12 | 13 | size_t McSerializedRequest::getBodySize() { 14 | switch (protocol_) { 15 | case mc_ascii_protocol: 16 | return asciiRequest_.getSize(); 17 | case mc_caret_protocol: 18 | return caretRequest_.getSizeNoHeader(); 19 | default: 20 | // Unreachable, see constructor. 21 | return 0; 22 | } 23 | } 24 | 25 | McSerializedRequest::~McSerializedRequest() { 26 | switch (protocol_) { 27 | case mc_ascii_protocol: 28 | asciiRequest_.~AsciiSerializedRequest(); 29 | break; 30 | case mc_caret_protocol: 31 | caretRequest_.~CaretSerializedMessage(); 32 | break; 33 | default: 34 | break; 35 | } 36 | } 37 | } // namespace memcache 38 | } // namespace facebook 39 | -------------------------------------------------------------------------------- /mcrouter/lib/network/Qos.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | 15 | /** 16 | * Validates the qosClass and qosPath sets appropriate qos if valid. 17 | * Returns true on success and false otherwise. 18 | * 19 | */ 20 | bool getQoS(uint64_t qosClassLvl, uint64_t qosPathLvl, uint64_t& qos); 21 | 22 | } // namespace memcache 23 | } // namespace facebook 24 | -------------------------------------------------------------------------------- /mcrouter/lib/network/RemoteConnection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace facebook::memcache { 16 | namespace detail { 17 | FOLLY_ATTR_WEAK std::shared_ptr 18 | getServiceRouterChannel(std::string_view serviceName); 19 | } 20 | 21 | template 22 | T getServiceRouterClient(std::string_view serviceName) { 23 | XCHECK(detail::getServiceRouterChannel); 24 | return T(detail::getServiceRouterChannel(serviceName)); 25 | } 26 | 27 | inline bool hasServiceRouter() { 28 | return !!detail::getServiceRouterChannel; 29 | } 30 | } // namespace facebook::memcache 31 | -------------------------------------------------------------------------------- /mcrouter/lib/network/SocketConnector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace facebook { 15 | namespace memcache { 16 | 17 | /** 18 | * Utility method to offload SSL handshakes to a separate threadpool. 19 | * The result is a future for a connected socket which is returned on 20 | * on the original evb. 21 | */ 22 | folly::Future connectSSLSocketWithAuxIO( 23 | folly::AsyncSSLSocket::UniquePtr socket, 24 | folly::SocketAddress address, 25 | int timeout, 26 | folly::SocketOptionMap options); 27 | 28 | } // namespace memcache 29 | } // namespace facebook 30 | -------------------------------------------------------------------------------- /mcrouter/lib/network/Utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | // Error message string indicating bad key type of errors 11 | const std::string_view kBadKeyMessage = "bad key"; 12 | -------------------------------------------------------------------------------- /mcrouter/lib/network/gen/Common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #pragma once 16 | 17 | #include "mcrouter/lib/network/gen/CommonMessages.h" 18 | -------------------------------------------------------------------------------- /mcrouter/lib/network/gen/CommonMessages.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #include "CommonMessages.h" 16 | 17 | namespace facebook { 18 | namespace memcache { 19 | 20 | constexpr const char* const McVersionRequest::name; 21 | 22 | constexpr const char* const McStatsRequest::name; 23 | 24 | constexpr const char* const McShutdownRequest::name; 25 | 26 | constexpr const char* const McQuitRequest::name; 27 | 28 | constexpr const char* const McExecRequest::name; 29 | 30 | constexpr const char* const GoAwayAcknowledgement::name; 31 | 32 | } // namespace memcache 33 | } // namespace facebook 34 | -------------------------------------------------------------------------------- /mcrouter/lib/network/gen/Memcache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #pragma once 16 | 17 | #include "mcrouter/lib/network/gen/MemcacheMessages.h" 18 | #include "mcrouter/lib/network/gen/MemcacheServer.h" 19 | -------------------------------------------------------------------------------- /mcrouter/lib/network/gen/MemcacheRouterInfo-AllFastestRoute.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #include "MemcacheRouterInfo.h" 16 | 17 | #include 18 | 19 | namespace facebook { 20 | namespace memcache { 21 | namespace mcrouter { 22 | 23 | template facebook::memcache::MemcacheRouterInfo::RouteHandlePtr 24 | makeAllFastestRoute( 25 | RouteHandleFactory& factory, 26 | const folly::dynamic& json); 27 | 28 | } // namespace mcrouter 29 | } // namespace memcache 30 | } // namespace facebook 31 | -------------------------------------------------------------------------------- /mcrouter/lib/network/gen/MemcacheRouterInfo-BuildExtraProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #include "MemcacheRouterInfo.h" 16 | 17 | #include 18 | 19 | using namespace facebook::memcache; 20 | using namespace facebook::memcache::mcrouter; 21 | 22 | namespace facebook { 23 | namespace memcache { 24 | 25 | /* static */ 26 | std::unique_ptr> 27 | MemcacheRouterInfo::buildExtraProvider() { 28 | return std::make_unique>(); 29 | } 30 | 31 | } // namespace memcache 32 | } // namespace facebook 33 | -------------------------------------------------------------------------------- /mcrouter/lib/network/gen/MemcacheRouterInfo-FailoverRoute.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #include "MemcacheRouterInfo.h" 16 | 17 | #include 18 | 19 | namespace facebook { 20 | namespace memcache { 21 | namespace mcrouter { 22 | 23 | template facebook::memcache::MemcacheRouterInfo::RouteHandlePtr 24 | makeFailoverRouteWithFailoverErrorSettings< 25 | facebook::memcache::MemcacheRouterInfo, 26 | FailoverRoute, 27 | FailoverErrorsSettings>( 28 | const folly::dynamic& json, 29 | std::vector children, 30 | FailoverErrorsSettings failoverErrors, 31 | const folly::dynamic* jFailoverPolicy); 32 | 33 | } // namespace mcrouter 34 | } // namespace memcache 35 | } // namespace facebook 36 | -------------------------------------------------------------------------------- /mcrouter/lib/network/gen/MemcacheRouterInfo-HashRoute.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #include "MemcacheRouterInfo.h" 16 | 17 | #include 18 | 19 | namespace facebook { 20 | namespace memcache { 21 | namespace mcrouter { 22 | 23 | template facebook::memcache::MemcacheRouterInfo::RouteHandlePtr 24 | createHashRoute( 25 | const folly::dynamic& json, 26 | std::vector rh, 27 | size_t threadId, 28 | ProxyBase& proxy); 29 | 30 | } // namespace mcrouter 31 | } // namespace memcache 32 | } // namespace facebook 33 | -------------------------------------------------------------------------------- /mcrouter/lib/network/test/.gitignore: -------------------------------------------------------------------------------- 1 | /mcrouter_network_test 2 | -------------------------------------------------------------------------------- /mcrouter/lib/network/test/RequestExpiryTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include "mcrouter/McReqUtil.h" 16 | #include "mcrouter/lib/network/gen/MemcacheMessages.h" 17 | #include "mcrouter/lib/network/test/gen/CarbonTestMessages.h" 18 | 19 | using namespace facebook::memcache; 20 | 21 | TEST(RequestExpiryTest, BasicTest) { 22 | facebook::memcache::test::McExpTestRequest req; 23 | McGetReply reply(carbon::Result::REMOTE_ERROR); 24 | 25 | const std::string message(1024, 'a'); 26 | reply.message_ref() = message; 27 | 28 | req.key_ref() = "abcd"; 29 | req.flags_ref() = 1; 30 | setRequestDeadline(req, 10); 31 | EXPECT_FALSE(isRequestDeadlineExceeded(req)); 32 | /* sleep override */ 33 | std::this_thread::sleep_for(std::chrono::milliseconds(11)); 34 | EXPECT_TRUE(isRequestDeadlineExceeded(req)); 35 | } 36 | -------------------------------------------------------------------------------- /mcrouter/lib/network/test/TestMcAsciiParserUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | namespace folly { 16 | class IOBuf; 17 | } // namespace folly 18 | 19 | namespace facebook { 20 | namespace memcache { 21 | 22 | /** 23 | * Given total data length and max piece size, generates all possible 24 | * combinations to split data in chunks. 25 | */ 26 | std::vector> genChunkedDataSets( 27 | size_t length, 28 | size_t maxPieceSize); 29 | 30 | /** 31 | * Given total data length and max piece size, returns number of 32 | * combinations to split data in chunks. 33 | */ 34 | size_t chunkedDataSetsCnt(size_t length, size_t maxPieceSize); 35 | 36 | std::unique_ptr chunkData( 37 | folly::IOBuf data, 38 | const std::vector& pieces); 39 | } // namespace memcache 40 | } // namespace facebook 41 | -------------------------------------------------------------------------------- /mcrouter/lib/network/test/gen/CarbonTest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #pragma once 16 | 17 | #include "mcrouter/lib/network/test/gen/CarbonTestMessages.h" 18 | -------------------------------------------------------------------------------- /mcrouter/lib/network/test/gen/CarbonTestMessages.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | * 7 | */ 8 | 9 | /* 10 | * THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN 11 | * VAIN. 12 | * 13 | * @generated 14 | */ 15 | #include "CarbonTestMessages.h" 16 | 17 | namespace facebook { 18 | namespace memcache { 19 | namespace test { 20 | 21 | } // namespace test 22 | } // namespace memcache 23 | } // namespace facebook 24 | -------------------------------------------------------------------------------- /mcrouter/lib/network/test/generate_keys.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | # we assume the generate_key-inl.sh is in the same dir as this script 8 | ROOT=$(dirname "$0") 9 | . "$ROOT/generate_keys-inl.sh" 10 | 11 | generateCert test Asox 127.0.0.1 ::1 12 | generateCert broken Asox 0.0.0.0 ::0 13 | 14 | # Clean up serial number 15 | rm "${CA_CERT_SRL}" 16 | -------------------------------------------------------------------------------- /mcrouter/lib/routes/DefaultShadowSelectorPolicy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | #include "mcrouter/lib/McResUtil.h" 15 | #include "mcrouter/lib/network/gen/MemcacheMessages.h" 16 | 17 | namespace facebook { 18 | namespace memcache { 19 | 20 | /** 21 | * Default shadow selector policy: send exactly the same request to shadow 22 | * as the original; send out shadow requests right away. 23 | */ 24 | class DefaultShadowSelectorPolicy { 25 | public: 26 | DefaultShadowSelectorPolicy() = default; 27 | 28 | template 29 | folly::Function makePostShadowReplyFn() const { 30 | return {}; 31 | } 32 | }; 33 | 34 | } // namespace memcache 35 | } // namespace facebook 36 | -------------------------------------------------------------------------------- /mcrouter/lib/test/.gitignore: -------------------------------------------------------------------------------- 1 | /mcrouter_lib_test 2 | -------------------------------------------------------------------------------- /mcrouter/lib/test/CompressionTestUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include "mcrouter/lib/CompressionCodecManager.h" 14 | 15 | namespace facebook { 16 | namespace memcache { 17 | namespace test { 18 | 19 | // Utility function used to create a random string of length size. 20 | std::string createBinaryData(size_t size); 21 | 22 | // Static CodecConfig map that can be used in tests to initialize a 23 | // CompressionCodecManager. 24 | std::unordered_map testCodecConfigs(); 25 | 26 | } // namespace test 27 | } // namespace memcache 28 | } // namespace facebook 29 | -------------------------------------------------------------------------------- /mcrouter/lib/test/HashTestUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace facebook { 16 | namespace memcache { 17 | namespace test { 18 | 19 | // Generate n endpoints. 20 | std::pair, std::vector> 21 | genEndpoints(int n); 22 | 23 | // Generate weight json for endpoints with the value weights. 24 | folly::dynamic genWeights(const std::vector& weights); 25 | 26 | } // namespace test 27 | } // namespace memcache 28 | } // namespace facebook 29 | -------------------------------------------------------------------------------- /mcrouter/lib/test/Main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | // Configure folly to enable INFO+ messages, and everything else to 14 | // enable WARNING+. 15 | // Set the default log handler to log asynchronously by default. 16 | FOLLY_INIT_LOGGING_CONFIG(".=WARNING,folly=INFO; default:async=true"); 17 | 18 | int main(int argc, char** argv) { 19 | ::testing::InitGoogleTest(&argc, argv); 20 | folly::init(&argc, &argv); 21 | return RUN_ALL_TESTS(); 22 | } 23 | -------------------------------------------------------------------------------- /mcrouter/lib/test/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | check_PROGRAMS = mcrouter_lib_test 7 | 8 | mcrouter_lib_test_SOURCES = \ 9 | Ch3HashTest.cpp \ 10 | CompressionTest.cpp \ 11 | CompressionTestUtil.cpp \ 12 | CompressionTestUtil.h \ 13 | Crc32HashTest.cpp \ 14 | HashTestUtil.cpp \ 15 | HashTestUtil.h \ 16 | Main.cpp \ 17 | MigrateRouteTest.cpp \ 18 | RandomRouteTest.cpp \ 19 | RendezvousHashTest.cpp \ 20 | RouteHandleTest.cpp \ 21 | WeightedChHashFuncBaseTest.cpp \ 22 | WeightedCh3HashFuncTest.cpp \ 23 | WeightedRendezvousHashTest.cpp \ 24 | observable_test.cpp \ 25 | runtime_vars_data_test.cpp 26 | 27 | mcrouter_lib_test_CPPFLAGS = \ 28 | -I$(top_srcdir)/.. \ 29 | -isystem $(top_srcdir)/lib/gtest/include 30 | 31 | mcrouter_lib_test_LDADD = \ 32 | $(top_builddir)/lib/libmcrouter.a \ 33 | $(top_builddir)/lib/libtestmain.la 34 | -------------------------------------------------------------------------------- /mcrouter/lib/test/McResUtilTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include "mcrouter/lib/McResUtil.h" 13 | 14 | namespace facebook { 15 | namespace memcache { 16 | namespace test { 17 | 18 | TEST(McResUtil, carbon_resultFromString) { 19 | const char* resStr1 = "mc_res_busy"; 20 | ASSERT_EQ(carbon::resultFromString(resStr1), carbon::Result::BUSY); 21 | 22 | const char* resStr2 = "bad_string"; 23 | ASSERT_EQ(carbon::resultFromString(resStr2), carbon::Result::UNKNOWN); 24 | 25 | std::string resStr3 = "mc_res_notfound"; 26 | ASSERT_EQ( 27 | carbon::resultFromString(resStr3.c_str()), carbon::Result::NOTFOUND); 28 | } 29 | 30 | } // namespace test 31 | } // namespace memcache 32 | } // namespace facebook 33 | -------------------------------------------------------------------------------- /mcrouter/lib/test/TestRouteHandle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "mcrouter/lib/network/gen/MemcacheRouteHandleIf.h" 11 | #include "mcrouter/lib/network/gen/MemcacheRouterInfo.h" 12 | 13 | namespace facebook { 14 | namespace memcache { 15 | 16 | using TestRouteHandleIf = MemcacheRouteHandleIf; 17 | using TestRouterInfo = MemcacheRouterInfo; 18 | 19 | template 20 | using TestRouteHandle = MemcacheRouteHandle; 21 | 22 | } // namespace memcache 23 | } // namespace facebook 24 | -------------------------------------------------------------------------------- /mcrouter/mcrouter_config-impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifndef HAVE_CONFIG_H 11 | static_assert(false, "mcrouter: invalid build"); 12 | #endif 13 | -------------------------------------------------------------------------------- /mcrouter/route.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | namespace mcrouter { 15 | 16 | /** 17 | * True if pattern (like "/foo/a*c/") matches a route (like "/foo/abc") 18 | */ 19 | bool match_pattern_route(folly::StringPiece pattern, folly::StringPiece route); 20 | } // namespace mcrouter 21 | } // namespace memcache 22 | } // namespace facebook 23 | -------------------------------------------------------------------------------- /mcrouter/routes/BigValueRouteIf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | namespace facebook { 11 | namespace memcache { 12 | namespace mcrouter { 13 | 14 | struct BigValueRouteOptions { 15 | constexpr explicit BigValueRouteOptions( 16 | size_t threshold_, 17 | size_t batchSize_, 18 | bool hideReplyFlags_) 19 | : threshold(threshold_), 20 | batchSize(batchSize_), 21 | hideReplyFlags(hideReplyFlags_) {} 22 | const size_t threshold; 23 | const size_t batchSize; 24 | const bool hideReplyFlags; 25 | }; 26 | 27 | } // namespace mcrouter 28 | } // namespace memcache 29 | } // namespace facebook 30 | -------------------------------------------------------------------------------- /mcrouter/routes/LatencyInjectionRoute.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "mcrouter/routes/LatencyInjectionRoute.h" 9 | 10 | #include 11 | #include 12 | 13 | namespace facebook::memcache::mcrouter { 14 | 15 | namespace { 16 | 17 | struct McrouterTimekeeperTag {}; 18 | folly::Singleton 19 | timekeeperHighResSingleton_; 20 | 21 | } // namespace 22 | 23 | namespace detail { 24 | folly::ReadMostlySharedPtr getTimekeeperHighResSingleton() { 25 | return timekeeperHighResSingleton_.try_get_fast(); 26 | } 27 | } // namespace detail 28 | 29 | } // namespace facebook::memcache::mcrouter 30 | -------------------------------------------------------------------------------- /mcrouter/routes/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | SUBDIRS = test 7 | -------------------------------------------------------------------------------- /mcrouter/routes/McBucketRoute-inl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "mcrouter/lib/fbi/cpp/ParsingUtil.h" 13 | 14 | namespace facebook::memcache::mcrouter { 15 | 16 | /* 17 | * McBucketRoute Config: 18 | * - bucketize(bool) - enable the bucketization 19 | * - total_buckets(int) - total number of buckets 20 | * - bucketization_keyspace - can be used to separate into multiple 21 | * bucketization domains decoupled from each other, 22 | * e.g. one keyspace for each Memache pool. 23 | */ 24 | template 25 | typename RouterInfo::RouteHandlePtr makeMcBucketRoute( 26 | typename RouterInfo::RouteHandlePtr rh, 27 | const folly::dynamic& json) { 28 | auto settings = parseMcBucketRouteSettings(json); 29 | return makeRouteHandleWithInfo( 30 | std::move(rh), settings); 31 | } 32 | } // namespace facebook::memcache::mcrouter 33 | -------------------------------------------------------------------------------- /mcrouter/routes/McImportResolver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "McImportResolver.h" 9 | 10 | #include "mcrouter/ConfigApiIf.h" 11 | #include "mcrouter/lib/config/ImportResolverIf.h" 12 | 13 | namespace facebook { 14 | namespace memcache { 15 | namespace mcrouter { 16 | 17 | McImportResolver::McImportResolver(ConfigApiIf& configApi) 18 | : configApi_(configApi) {} 19 | 20 | std::string McImportResolver::import(folly::StringPiece path) { 21 | std::string ret; 22 | if (!configApi_.get(ConfigType::ConfigImport, path.str(), ret)) { 23 | throw std::runtime_error("Can not read " + path.str()); 24 | } 25 | return ret; 26 | } 27 | } // namespace mcrouter 28 | } // namespace memcache 29 | } // namespace facebook 30 | -------------------------------------------------------------------------------- /mcrouter/routes/McImportResolver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | #include "mcrouter/lib/config/ImportResolverIf.h" 15 | 16 | namespace facebook { 17 | namespace memcache { 18 | namespace mcrouter { 19 | 20 | class ConfigApiIf; 21 | 22 | /** 23 | * ImportResolverIf implementation. Can load config files for 24 | * @import macro from configerator/file 25 | */ 26 | class McImportResolver : public ImportResolverIf { 27 | public: 28 | explicit McImportResolver(ConfigApiIf& configApi); 29 | 30 | /** 31 | * @throws std::runtime_error if can not load file 32 | */ 33 | std::string import(folly::StringPiece path) override; 34 | 35 | private: 36 | ConfigApiIf& configApi_; 37 | }; 38 | } // namespace mcrouter 39 | } // namespace memcache 40 | } // namespace facebook 41 | -------------------------------------------------------------------------------- /mcrouter/routes/McRouteHandleBuilder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "mcrouter/lib/config/RouteHandleBuilder.h" 11 | #include "mcrouter/routes/McrouterRouteHandle.h" 12 | 13 | namespace facebook { 14 | namespace memcache { 15 | namespace mcrouter { 16 | 17 | template < 18 | template 19 | class R, 20 | typename... RArgs, 21 | typename... Args> 22 | McrouterRouteHandlePtr makeMcrouterRouteHandle(Args&&... args) { 23 | return makeRouteHandle( 24 | std::forward(args)...); 25 | } 26 | 27 | template < 28 | template 29 | class R, 30 | typename... RArgs, 31 | typename... Args> 32 | McrouterRouteHandlePtr makeMcrouterRouteHandleWithInfo(Args&&... args) { 33 | return makeRouteHandleWithInfo( 34 | std::forward(args)...); 35 | } 36 | 37 | } // namespace mcrouter 38 | } // namespace memcache 39 | } // namespace facebook 40 | -------------------------------------------------------------------------------- /mcrouter/routes/McRouteHandleProvider-AllFastestRoute.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "mcrouter/routes/McRouteHandleProvider.h" 9 | 10 | #include 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | namespace mcrouter { 15 | 16 | template MemcacheRouterInfo::RouteHandlePtr 17 | makeAllFastestRoute( 18 | RouteHandleFactory& factory, 19 | const folly::dynamic& json); 20 | 21 | } // namespace mcrouter 22 | } // namespace memcache 23 | } // namespace facebook 24 | -------------------------------------------------------------------------------- /mcrouter/routes/McRouteHandleProvider-FailoverRoute.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "mcrouter/routes/McRouteHandleProvider.h" 9 | 10 | #include 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | namespace mcrouter { 15 | 16 | template MemcacheRouterInfo::RouteHandlePtr 17 | makeFailoverRouteWithFailoverErrorSettings< 18 | MemcacheRouterInfo, 19 | FailoverRoute, 20 | FailoverErrorsSettings>( 21 | const folly::dynamic& json, 22 | std::vector children, 23 | FailoverErrorsSettings failoverErrors, 24 | const folly::dynamic* jFailoverPolicy); 25 | 26 | } // namespace mcrouter 27 | } // namespace memcache 28 | } // namespace facebook 29 | -------------------------------------------------------------------------------- /mcrouter/routes/McRouteHandleProvider-HashRoute.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "mcrouter/routes/McRouteHandleProvider.h" 9 | 10 | #include 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | namespace mcrouter { 15 | 16 | template MemcacheRouterInfo::RouteHandlePtr createHashRoute( 17 | const folly::dynamic& json, 18 | std::vector rh, 19 | size_t threadId, 20 | ProxyBase& proxy); 21 | 22 | } // namespace mcrouter 23 | } // namespace memcache 24 | } // namespace facebook 25 | -------------------------------------------------------------------------------- /mcrouter/routes/McRouteHandleProvider-PoolRoute.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "mcrouter/routes/McRouteHandleProvider.h" 9 | 10 | namespace facebook { 11 | namespace memcache { 12 | namespace mcrouter { 13 | 14 | template std::tuple< 15 | std::vector, 16 | std::optional> 17 | McRouteHandleProvider::makePool( 18 | RouteHandleFactory& factory, 19 | const PoolFactory::PoolJson& json); 20 | 21 | template MemcacheRouterInfo::RouteHandlePtr 22 | McRouteHandleProvider::makePoolRoute( 23 | RouteHandleFactory& factory, 24 | const folly::dynamic& json); 25 | 26 | } // namespace mcrouter 27 | } // namespace memcache 28 | } // namespace facebook 29 | -------------------------------------------------------------------------------- /mcrouter/routes/NullRoute.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include "mcrouter/lib/routes/NullRoute.h" 11 | #include "mcrouter/routes/McrouterRouteHandle.h" 12 | 13 | namespace facebook { 14 | namespace memcache { 15 | namespace mcrouter { 16 | 17 | McrouterRouteHandlePtr makeNullRoute( 18 | RouteHandleFactory& factory, 19 | const folly::dynamic& json) { 20 | return makeNullRoute(factory, json); 21 | } 22 | 23 | McrouterRouteHandlePtr makeNullRoute() { 24 | return createNullRoute(); 25 | } 26 | } // namespace mcrouter 27 | } // namespace memcache 28 | } // namespace facebook 29 | -------------------------------------------------------------------------------- /mcrouter/routes/RendezvousRouteHelpers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace facebook { 16 | namespace memcache { 17 | namespace mcrouter { 18 | 19 | std::vector getTags( 20 | const folly::dynamic& json, 21 | size_t numRoutes, 22 | const std::string& nameForErrorMessage); 23 | 24 | } // namespace mcrouter 25 | } // namespace memcache 26 | } // namespace facebook 27 | -------------------------------------------------------------------------------- /mcrouter/routes/RouteSelectorMap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | namespace facebook { 15 | namespace memcache { 16 | namespace mcrouter { 17 | 18 | template 19 | class PrefixSelectorRoute; 20 | 21 | template 22 | using RouteSelectorMap = folly::F14NodeMap< 23 | std::string, 24 | std::shared_ptr>>; 25 | } // namespace mcrouter 26 | } // namespace memcache 27 | } // namespace facebook 28 | -------------------------------------------------------------------------------- /mcrouter/routes/ShadowRouteIf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "mcrouter/routes/McrouterRouteHandle.h" 15 | 16 | namespace facebook { 17 | namespace memcache { 18 | namespace mcrouter { 19 | 20 | class ShadowSettings; 21 | 22 | template 23 | using ShadowData = std::vector, 25 | std::shared_ptr>>; 26 | 27 | using McrouterShadowData = ShadowData; 28 | 29 | } // namespace mcrouter 30 | } // namespace memcache 31 | } // namespace facebook 32 | -------------------------------------------------------------------------------- /mcrouter/routes/TimeProviderFunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "mcrouter/config.h" 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | namespace mcrouter { 15 | 16 | /* Time Provider Func for Migrate route */ 17 | class TimeProviderFunc { 18 | public: 19 | time_t operator()() const { 20 | return nowWallSec(); 21 | } 22 | }; 23 | } // namespace mcrouter 24 | } // namespace memcache 25 | } // namespace facebook 26 | -------------------------------------------------------------------------------- /mcrouter/routes/test/.gitignore: -------------------------------------------------------------------------------- 1 | /mcrouter_routes_test 2 | -------------------------------------------------------------------------------- /mcrouter/routes/test/AllSyncCollectionRouteFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "mcrouter/lib/test/AllSyncCollectionRoute.h" 11 | #include "mcrouter/routes/CollectionRouteFactory.h" 12 | 13 | namespace facebook { 14 | namespace memcache { 15 | namespace mcrouter { 16 | 17 | template 18 | typename RouterInfo::RouteHandlePtr createAllSyncCollectionRoute( 19 | RouteHandleFactory& factory, 20 | const folly::dynamic& json) { 21 | return createCollectionRoute( 22 | factory, json); 23 | } 24 | 25 | } // end namespace mcrouter 26 | 27 | } // end namespace memcache 28 | } // end namespace facebook 29 | -------------------------------------------------------------------------------- /mcrouter/routes/test/BigValueRouteTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "mcrouter/routes/test/BigValueRouteTestBase.h" 9 | 10 | TEST(BigValueRouteTest, smallvalue) { 11 | facebook::memcache::mcrouter::testSmallvalue< 12 | facebook::memcache::MemcacheRouterInfo>(); 13 | } 14 | 15 | TEST(BigValueRouteTest, bigvalueWithFlag) { 16 | facebook::memcache::mcrouter::testBigvalueWithFlag< 17 | facebook::memcache::MemcacheRouterInfo>(); 18 | } 19 | 20 | TEST(BigValueRouteTest, bigvalueWithoutFlag) { 21 | facebook::memcache::mcrouter::testBigvalueWithoutFlag< 22 | facebook::memcache::MemcacheRouterInfo>(); 23 | } 24 | 25 | TEST(BigValueRouteTest, bigvalue) { 26 | facebook::memcache::mcrouter::testBigvalue< 27 | facebook::memcache::MemcacheRouterInfo>(); 28 | } 29 | -------------------------------------------------------------------------------- /mcrouter/routes/test/ConstShardHashFuncTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include "mcrouter/routes/ShardHashFunc.h" 11 | 12 | using namespace facebook::memcache; 13 | using namespace facebook::memcache::mcrouter; 14 | 15 | TEST(constShardHashFuncTest, picksRightShard) { 16 | ConstShardHashFunc func(4); 17 | 18 | EXPECT_EQ(3, func("b:3:meh")); 19 | EXPECT_EQ(2, func("bl:2:meh")); 20 | EXPECT_EQ(1, func("bla:1:meh")); 21 | EXPECT_EQ(0, func("blah:0:meh")); 22 | } 23 | 24 | TEST(constShardHashFuncTest, ch3Fallback) { 25 | ConstShardHashFunc func(4); 26 | 27 | // not valid keys, routed with Ch3 fallback 28 | EXPECT_EQ(2, func("blahmeh")); 29 | EXPECT_EQ(0, func("blah:meh")); 30 | EXPECT_EQ(1, func("blah::meh")); 31 | EXPECT_EQ(0, func("blah:12c34:meh")); 32 | EXPECT_EQ(3, func("blah:4:meh")); 33 | } 34 | -------------------------------------------------------------------------------- /mcrouter/routes/test/Main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | // Configure folly to enable INFO+ messages, and everything else to 16 | // enable WARNING+. 17 | // Set the default log handler to log asynchronously by default. 18 | FOLLY_INIT_LOGGING_CONFIG(".=WARNING,folly=INFO; default:async=true"); 19 | 20 | // for backward compatibility with gflags 21 | namespace gflags {} // namespace gflags 22 | namespace google { 23 | using namespace gflags; 24 | } // namespace google 25 | 26 | int main(int argc, char** argv) { 27 | ::testing::InitGoogleTest(&argc, argv); 28 | folly::init(&argc, &argv, true /* removeFlags */); 29 | int result = RUN_ALL_TESTS(); 30 | gflags::SetCommandLineOptionWithMode( 31 | "bm_min_iters", "100000", gflags::SET_FLAG_IF_DEFAULT); 32 | folly::runBenchmarksOnFlag(); 33 | return result; 34 | } 35 | -------------------------------------------------------------------------------- /mcrouter/routes/test/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | check_PROGRAMS = mcrouter_routes_test 7 | 8 | mcrouter_routes_test_SOURCES = \ 9 | BigValueRouteTest.cpp \ 10 | BigValueRouteTestBase.h \ 11 | ConstShardHashFuncTest.cpp \ 12 | FailoverWithExptimeRouteTest.cpp \ 13 | Main.cpp \ 14 | PoolRouteTest.cpp \ 15 | RateLimitRouteTest.cpp \ 16 | RouteHandleTestUtil.h \ 17 | ShadowRouteTest.cpp \ 18 | SlowWarmUpRouteTest.cpp \ 19 | WarmUpRouteTest.cpp 20 | 21 | mcrouter_routes_test_CPPFLAGS = \ 22 | -I$(top_srcdir)/.. \ 23 | -isystem $(top_srcdir)/lib/gtest/include 24 | 25 | mcrouter_routes_test_LDADD = \ 26 | $(top_builddir)/libmcroutercore.a \ 27 | $(top_builddir)/lib/libmcrouter.a \ 28 | $(top_builddir)/lib/libtestmain.la \ 29 | -lwangle \ 30 | -lfizz \ 31 | -lsodium \ 32 | -lfolly \ 33 | -lfollybenchmark 34 | -------------------------------------------------------------------------------- /mcrouter/scripts/clean_ubuntu_14.04.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | set -ex 8 | 9 | sudo apt-get install -y libdouble-conversion1 libgflags2 \ 10 | libboost-program-options1.54.0 libboost-filesystem1.54.0 \ 11 | libboost-system1.54.0 libboost-regex1.54.0 libboost-thread1.54.0 \ 12 | libboost-context1.54.0 libgoogle-glog0 libevent-2.0-5 libjemalloc1 13 | 14 | sudo apt-get purge -y gcc g++ ragel autoconf \ 15 | git libtool python-dev libssl-dev libevent-dev \ 16 | binutils-dev make libdouble-conversion-dev libgflags-dev \ 17 | libgoogle-glog-dev libjemalloc-dev 18 | 19 | sudo apt-get purge -y 'libboost.*-dev' 20 | sudo apt-get autoremove --purge -y 21 | sudo apt-get autoclean -y 22 | sudo apt-get clean -y 23 | 24 | if [[ "x$1" != "x" ]]; then 25 | PKG_DIR=$1/pkgs 26 | INSTALL_DIR=$1/install 27 | strip "$INSTALL_DIR"/bin/mcrouter 28 | rm -rf "$PKG_DIR" 29 | rm -rf "$INSTALL_DIR"/lib/*.a 30 | rm -rf "$INSTALL_DIR"/include 31 | fi 32 | -------------------------------------------------------------------------------- /mcrouter/scripts/common.sh: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | set -ex 7 | 8 | function die { printf "%s: %s\n" "$0" "$@"; exit 1; } 9 | 10 | [ -n "$1" ] || die "PKG_DIR missing" 11 | [ -n "$2" ] || die "INSTALL_DIR missing" 12 | 13 | PKG_DIR="$1" 14 | INSTALL_DIR="$2" 15 | INSTALL_AUX_DIR="$3" 16 | shift $# 17 | MAKE_ARGS="$@ -j$(nproc)" 18 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 19 | 20 | mkdir -p "$PKG_DIR" "$INSTALL_DIR" 21 | 22 | if [ -n "$3" ]; then 23 | mkdir -p "$INSTALL_AUX_DIR" 24 | fi 25 | 26 | cd "$PKG_DIR" || die "cd fail" 27 | -------------------------------------------------------------------------------- /mcrouter/scripts/docker/ubuntu/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.1-experimental 2 | 3 | FROM ubuntu:focal 4 | 5 | ENV MCROUTER_DIR /usr/local/mcrouter 6 | ENV MCROUTER_REPO https://github.com/facebook/mcrouter.git 7 | ENV DEBIAN_FRONTEND noninteractive 8 | 9 | ENV PKG_DIR $MCROUTER_DIR/pkgs 10 | ENV INSTALL_DIR $MCROUTER_DIR/install 11 | 12 | RUN --mount=type=bind,target=/tmp/scripts,source=scripts /tmp/scripts/deps.sh 13 | RUN --mount=type=bind,target=/tmp/scripts,source=scripts /tmp/scripts/build.sh 14 | 15 | ENV DEBIAN_FRONTEND newt 16 | -------------------------------------------------------------------------------- /mcrouter/scripts/docker/ubuntu/scripts/deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | apt -y update 8 | apt -y install apt-transport-https \ 9 | ca-certificates \ 10 | tzdata \ 11 | git 12 | apt clean all 13 | -------------------------------------------------------------------------------- /mcrouter/scripts/get_and_build_by_make.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | set -ex 8 | 9 | MAKE_FILE="$1" 10 | TARGET="$2" 11 | PKG_DIR="${3%/}"/pkgs 12 | INSTALL_DIR="${3%/}"/install 13 | INSTALL_AUX_DIR="${3%/}"/install/aux 14 | 15 | [ -n "$MAKE_FILE" ] || ( echo "Make file missing"; exit 1 ) 16 | [ -n "$TARGET" ] || ( echo "Target missing"; exit 1 ) 17 | 18 | mkdir -p "$PKG_DIR" "$INSTALL_DIR" "$INSTALL_AUX_DIR" 19 | 20 | cd "$(dirname "$0")" || ( echo "cd fail"; exit 1 ) 21 | 22 | REPO_BASE_DIR="$(cd ../../ && pwd)" || die "Couldn't determine repo top dir" 23 | export REPO_BASE_DIR 24 | 25 | export LDFLAGS="-ljemalloc $LDFLAGS" 26 | 27 | make "$TARGET" -j3 -f "$MAKE_FILE" PKG_DIR="$PKG_DIR" INSTALL_DIR="$INSTALL_DIR" INSTALL_AUX_DIR="$INSTALL_AUX_DIR" 28 | 29 | printf "%s\n" "make $TARGET for $MAKE_FILE done" 30 | -------------------------------------------------------------------------------- /mcrouter/scripts/get_and_build_everything.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | set -ex 8 | 9 | ORDER="$1" 10 | PKG_DIR="${2%/}"/pkgs 11 | INSTALL_DIR="${2%/}"/install 12 | INSTALL_AUX_DIR="${2%/}"/install/aux 13 | shift 2 14 | 15 | mkdir -p "$PKG_DIR" "$INSTALL_DIR" "$INSTALL_AUX_DIR" 16 | 17 | cd "$(dirname "$0")" || ( echo "cd fail"; exit 1 ) 18 | 19 | REPO_BASE_DIR="$(cd ../../ && pwd)" || die "Couldn't determine repo top dir" 20 | export REPO_BASE_DIR 21 | 22 | export LDFLAGS="-ljemalloc $LDFLAGS" 23 | 24 | for script in $(ls "order_$ORDER/" | egrep '^[0-9]+_.*[^~]$' | sort -n); do 25 | "./order_$ORDER/$script" "$PKG_DIR" "$INSTALL_DIR" "$INSTALL_AUX_DIR" "$@" 26 | done 27 | 28 | printf "%s\n" "Mcrouter installed in $INSTALL_DIR/bin/mcrouter" 29 | -------------------------------------------------------------------------------- /mcrouter/scripts/install_ubuntu_15.04.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | set -ex 8 | 9 | [ -n "$1" ] || ( echo "Install dir missing"; exit 1 ) 10 | 11 | sudo apt-get update 12 | 13 | sudo apt-get install -y \ 14 | autoconf \ 15 | binutils-dev \ 16 | bison \ 17 | cmake \ 18 | flex \ 19 | g++ \ 20 | gcc \ 21 | git \ 22 | libboost1.55-all-dev \ 23 | libbz2-dev \ 24 | libdouble-conversion-dev \ 25 | libevent-dev \ 26 | libgflags-dev \ 27 | libgoogle-glog-dev \ 28 | libjemalloc-dev \ 29 | liblz4-dev \ 30 | liblzma-dev \ 31 | liblzma5 \ 32 | libsnappy-dev \ 33 | libsodium-dev \ 34 | libssl-dev \ 35 | libtool \ 36 | make \ 37 | pkg-config \ 38 | python-dev \ 39 | ragel 40 | 41 | cd "$(dirname "$0")" || ( echo "cd fail"; exit 1 ) 42 | 43 | ./get_and_build_everything.sh ubuntu-15.04 "$@" 44 | -------------------------------------------------------------------------------- /mcrouter/scripts/install_ubuntu_16.04.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | set -ex 8 | 9 | [ -n "$1" ] || ( echo "Install dir missing"; exit 1 ) 10 | 11 | sudo apt-get update 12 | 13 | # Note libzstd-dev is not available on stock Ubuntu 14.04 or 15.04. 14 | sudo apt-get install -y \ 15 | autoconf \ 16 | binutils-dev \ 17 | bison \ 18 | cmake \ 19 | flex \ 20 | g++ \ 21 | gcc \ 22 | git \ 23 | libboost1.58-all-dev \ 24 | libbz2-dev \ 25 | libdouble-conversion-dev \ 26 | libevent-dev \ 27 | libgflags-dev \ 28 | libgoogle-glog-dev \ 29 | libjemalloc-dev \ 30 | liblz4-dev \ 31 | liblzma-dev \ 32 | liblzma5 \ 33 | libsnappy-dev \ 34 | libsodium-dev \ 35 | libssl-dev \ 36 | libtool \ 37 | libunwind8-dev \ 38 | make \ 39 | pkg-config \ 40 | python-dev \ 41 | ragel 42 | 43 | cd "$(dirname "$0")" || ( echo "cd fail"; exit 1 ) 44 | 45 | ./get_and_build_everything.sh ubuntu-16.04 "$@" 46 | -------------------------------------------------------------------------------- /mcrouter/scripts/order_centos-7.2/10_folly: -------------------------------------------------------------------------------- 1 | ../recipes/folly.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_centos-7.2/11_fizz: -------------------------------------------------------------------------------- 1 | ../recipes/fizz.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_centos-7.2/12_wangle: -------------------------------------------------------------------------------- 1 | ../recipes/wangle.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_centos-7.2/15_fbthrift: -------------------------------------------------------------------------------- 1 | ../recipes/fbthrift.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_centos-7.2/20_mcrouter: -------------------------------------------------------------------------------- 1 | ../recipes/mcrouter.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-14.04/09_openssl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # only needed for ubuntu 14.04 4 | source common.sh 5 | 6 | if [[ ! -d "openssl-1.0.2n" ]]; then 7 | curl -O https://www.openssl.org/source/openssl-1.0.2n.tar.gz 8 | tar -xzf openssl-1.0.2n.tar.gz 9 | cd openssl-1.0.2n 10 | ./config --prefix="$INSTALL_DIR" --openssldir="$INSTALL_DIR" && make && make install 11 | fi 12 | -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-14.04/10_folly: -------------------------------------------------------------------------------- 1 | ../recipes/folly.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-14.04/11_fizz: -------------------------------------------------------------------------------- 1 | ../recipes/fizz.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-14.04/12_wangle: -------------------------------------------------------------------------------- 1 | ../recipes/wangle.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-14.04/13_rsocket-yarpl: -------------------------------------------------------------------------------- 1 | ../recipes/rsocket-yarpl.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-14.04/14_fmt: -------------------------------------------------------------------------------- 1 | ../recipes/fmtlib.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-14.04/15_fbthrift: -------------------------------------------------------------------------------- 1 | ../recipes/fbthrift.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-14.04/16_gtest: -------------------------------------------------------------------------------- 1 | ../recipes/gtest.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-14.04/20_mcrouter: -------------------------------------------------------------------------------- 1 | ../recipes/mcrouter.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-15.04/10_folly: -------------------------------------------------------------------------------- 1 | ../recipes/folly.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-15.04/11_fizz: -------------------------------------------------------------------------------- 1 | ../recipes/fizz.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-15.04/12_wangle: -------------------------------------------------------------------------------- 1 | ../recipes/wangle.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-15.04/13_rsocket-yarpl: -------------------------------------------------------------------------------- 1 | ../recipes/rsocket-yarpl.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-15.04/14_fmt: -------------------------------------------------------------------------------- 1 | ../recipes/fmtlib.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-15.04/15_fbthrift: -------------------------------------------------------------------------------- 1 | ../recipes/fbthrift.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-15.04/16_gtest: -------------------------------------------------------------------------------- 1 | ../recipes/gtest.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-15.04/20_mcrouter: -------------------------------------------------------------------------------- 1 | ../recipes/mcrouter.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-16.04/10_folly: -------------------------------------------------------------------------------- 1 | ../recipes/folly.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-16.04/11_fizz: -------------------------------------------------------------------------------- 1 | ../recipes/fizz.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-16.04/12_wangle: -------------------------------------------------------------------------------- 1 | ../recipes/wangle.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-16.04/13_rsocket-yarpl: -------------------------------------------------------------------------------- 1 | ../recipes/rsocket-yarpl.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-16.04/14_fmt: -------------------------------------------------------------------------------- 1 | ../recipes/fmtlib.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-16.04/15_fbthrift: -------------------------------------------------------------------------------- 1 | ../recipes/fbthrift.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-16.04/16_gtest: -------------------------------------------------------------------------------- 1 | ../recipes/gtest.sh -------------------------------------------------------------------------------- /mcrouter/scripts/order_ubuntu-16.04/20_mcrouter: -------------------------------------------------------------------------------- 1 | ../recipes/mcrouter.sh -------------------------------------------------------------------------------- /mcrouter/scripts/recipes/fbthrift.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | source common.sh 8 | 9 | if [[ ! -d "$PKG_DIR/fbthrift" ]]; then 10 | git clone https://github.com/facebook/fbthrift 11 | cd "$PKG_DIR/fbthrift" || die "cd fail" 12 | if [[ -f "$REPO_BASE_DIR/mcrouter/FBTHRIFT_COMMIT" ]]; then 13 | FBTHRIFT_COMMIT="$(head -n 1 "$REPO_BASE_DIR/mcrouter/FBTHRIFT_COMMIT")" 14 | echo "FBTHRIFT_COMMIT file found: using fbthrift commit $FBTHRIFT_COMMIT" 15 | git checkout "$FBTHRIFT_COMMIT" 16 | else 17 | echo "No FBTHRIFT_COMMIT file, using fbthrift HEAD=$(git rev-parse HEAD)" 18 | fi 19 | fi 20 | 21 | cd "$PKG_DIR/fbthrift/build" || die "cd fbthrift failed" 22 | 23 | CXXFLAGS="$CXXFLAGS -fPIC" \ 24 | cmake .. -G Ninja -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" 25 | cmake --build . && cmake --install . 26 | -------------------------------------------------------------------------------- /mcrouter/scripts/recipes/fizz.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | source common.sh 8 | 9 | if [[ ! -d fizz ]]; then 10 | git clone https://github.com/facebookincubator/fizz 11 | cd "$PKG_DIR/fizz" || die "cd fail" 12 | if [[ -f "$REPO_BASE_DIR/mcrouter/FIZZ_COMMIT" ]]; then 13 | FIZZ_COMMIT="$(head -n 1 "$REPO_BASE_DIR/mcrouter/FIZZ_COMMIT")" 14 | echo "FIZZ_COMMIT file found: using fizz commit $FIZZ_COMMIT" 15 | git checkout "$FIZZ_COMMIT" 16 | else 17 | echo "No FIZZ_COMMIT file, using fizz HEAD=$(git rev-parse HEAD)" 18 | fi 19 | fi 20 | 21 | cd "$PKG_DIR/fizz/fizz/" || die "cd fail" 22 | 23 | cmake . -G Ninja -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -DBUILD_TESTS=OFF 24 | cmake --build . && cmake --install . 25 | -------------------------------------------------------------------------------- /mcrouter/scripts/recipes/fmtlib.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | source common.sh 8 | 9 | if [[ ! -d "$PKG_DIR/fmt" ]]; then 10 | git clone --depth 1 -b 11.0.2 https://github.com/fmtlib/fmt.git 11 | cd "$PKG_DIR/fmt" || die "cd failed" 12 | mkdir "$PKG_DIR/fmt/build" 13 | fi 14 | 15 | cd "$PKG_DIR/fmt/build" || die "cd fmt failed" 16 | 17 | CXXFLAGS="$CXXFLAGS -fPIC" \ 18 | cmake .. -G Ninja -DFMT_TEST=Off -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" 19 | cmake --build . && cmake --install . 20 | -------------------------------------------------------------------------------- /mcrouter/scripts/recipes/folly.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | source common.sh 8 | 9 | if [[ ! -d folly ]]; then 10 | git clone https://github.com/facebook/folly 11 | cd "$PKG_DIR/folly" || die "cd fail" 12 | if [[ -f "$REPO_BASE_DIR/mcrouter/FOLLY_COMMIT" ]]; then 13 | FOLLY_COMMIT="$(head -n 1 "$REPO_BASE_DIR/mcrouter/FOLLY_COMMIT")" 14 | echo "FOLLY_COMMIT file found: using folly commit $FOLLY_COMMIT" 15 | git checkout "$FOLLY_COMMIT" 16 | else 17 | echo "No FOLLY_COMMIT file, using folly HEAD=$(git rev-parse HEAD)" 18 | fi 19 | fi 20 | 21 | cd "$PKG_DIR/folly/folly/" || die "cd fail" 22 | 23 | CXXFLAGS="$CXXFLAGS -fPIC" \ 24 | LD_LIBRARY_PATH="$INSTALL_DIR/lib:$LD_LIBRARY_PATH" \ 25 | LD_RUN_PATH="$INSTALL_DIR/lib:$LD_RUN_PATH" \ 26 | cmake .. \ 27 | -G Ninja \ 28 | -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \ 29 | -DCMAKE_INCLUDE_PATH="$INSTALL_DIR/lib" \ 30 | -DCMAKE_LIBRARY_PATH="$INSTALL_DIR/lib" 31 | cmake --build . && cmake --install . 32 | -------------------------------------------------------------------------------- /mcrouter/scripts/recipes/glog.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | source common.sh 8 | 9 | if [ ! -d "$PKG_DIR/glog" ]; then 10 | git clone https://github.com/google/glog.git 11 | cd "$PKG_DIR/glog" || die "cd fail" 12 | 13 | autoreconf --install 14 | LDFLAGS="-Wl,-rpath=$INSTALL_DIR/lib,--enable-new-dtags \ 15 | -L$INSTALL_DIR/lib $LDFLAGS" \ 16 | CPPFLAGS="-I$INSTALL_DIR/include -DGOOGLE_GLOG_DLL_DECL='' $CPPFLAGS" \ 17 | ./configure --prefix="$INSTALL_DIR" && \ 18 | make $MAKE_ARGS && make install $MAKE_ARGS 19 | fi 20 | -------------------------------------------------------------------------------- /mcrouter/scripts/recipes/gtest.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | source common.sh 8 | 9 | if [ ! -d "$PKG_DIR/glog" ]; then 10 | git clone https://github.com/google/googletest.git "$PKG_DIR/gtest" \ 11 | --branch v1.10.x --depth 1 12 | cd "$PKG_DIR/gtest" || die "cd fail" 13 | 14 | cmake . \ 15 | -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \ 16 | -DCMAKE_INSTALL_LIBDIR="lib" 17 | make $MAKE_ARGS && make install $MAKE_ARGS 18 | fi 19 | -------------------------------------------------------------------------------- /mcrouter/scripts/recipes/mcrouter.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | source common.sh 8 | 9 | cd "$SCRIPT_DIR/../.." || die "cd fail" 10 | 11 | autoreconf --install 12 | LD_LIBRARY_PATH="$INSTALL_DIR/lib:$LD_LIBRARY_PATH" \ 13 | LD_RUN_PATH="$INSTALL_DIR/lib:$LD_RUN_PATH" \ 14 | LDFLAGS="-L$INSTALL_DIR/lib $LDFLAGS" \ 15 | CPPFLAGS="-I$INSTALL_DIR/include $CPPFLAGS" \ 16 | FBTHRIFT_BIN="$INSTALL_DIR/bin/" \ 17 | ./configure --prefix="$INSTALL_DIR" 18 | make $MAKE_ARGS && make install $MAKE_ARGS 19 | -------------------------------------------------------------------------------- /mcrouter/scripts/recipes/mvfst.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | source common.sh 8 | 9 | if [ ! -d "$PKG_DIR/mvfst" ]; then 10 | git clone https://github.com/facebook/mvfst.git "$PKG_DIR/mvfst" 11 | cd "$PKG_DIR/mvfst" || die "cd fail" 12 | 13 | cmake . \ 14 | -G Ninja -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -DBUILD_TESTS=OFF 15 | cmake --build . && cmake --install . 16 | fi 17 | -------------------------------------------------------------------------------- /mcrouter/scripts/recipes/python.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | source common.sh 8 | 9 | grab http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz 10 | tar xf Python-2.7.6.tar.xz 11 | cd Python-2.7.6 12 | ./configure --prefix="$INSTALL_DIR" --enable-unicode=ucs4 --enable-shared \ 13 | LDFLAGS="-Wl,-rpath /usr/local/lib" && make $MAKE_ARGS && make altinstall $MAKE_ARGS 14 | -------------------------------------------------------------------------------- /mcrouter/scripts/recipes/wangle.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | source common.sh 8 | 9 | if [[ ! -d wangle ]]; then 10 | git clone https://github.com/facebook/wangle 11 | cd "$PKG_DIR/wangle" || die "cd fail" 12 | if [[ -f "$REPO_BASE_DIR/mcrouter/WANGLE_COMMIT" ]]; then 13 | WANGLE_COMMIT="$(head -n 1 "$REPO_BASE_DIR/mcrouter/WANGLE_COMMIT")" 14 | echo "WANGLE_COMMIT file found: using wangle commit $WANGLE_COMMIT" 15 | git checkout "$WANGLE_COMMIT" 16 | else 17 | echo "No WANGLE_COMMIT file, using wangle HEAD=$(git rev-parse HEAD)" 18 | fi 19 | fi 20 | 21 | cd "$PKG_DIR/wangle/wangle/" || die "cd fail" 22 | 23 | cmake . -G Ninja -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -DBUILD_TESTS=OFF 24 | cmake --build . && cmake --install . 25 | -------------------------------------------------------------------------------- /mcrouter/standalone_options.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "mcrouter/options.h" 13 | 14 | namespace facebook { 15 | namespace memcache { 16 | namespace mcrouter { 17 | 18 | /* 19 | ** Observation of mcrouter in production indicates that 20 | ** that delta(RSS) / delta(outstanding reqs) is just under 21 | ** 3K. 22 | */ 23 | #define OUTSTANDING_REQ_BYTES (3 * 1024) 24 | #define DEFAULT_MAX_CLIENT_OUTSTANDING_REQS \ 25 | (uint32_t)((1024 * 1024 * 100) / OUTSTANDING_REQ_BYTES) 26 | 27 | #define OPTIONS_FILE "mcrouter/standalone_options_list.h" 28 | #define OPTIONS_NAME McrouterStandaloneOptions 29 | #include "mcrouter/options-template.h" 30 | 31 | #undef OPTIONS_FILE 32 | #undef OPTIONS_NAME 33 | 34 | } // namespace mcrouter 35 | } // namespace memcache 36 | } // namespace facebook 37 | -------------------------------------------------------------------------------- /mcrouter/test/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/mcrouter/1f17a1926a19d121caf4818e22636d73657ce675/mcrouter/test/.gitignore -------------------------------------------------------------------------------- /mcrouter/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/mcrouter/1f17a1926a19d121caf4818e22636d73657ce675/mcrouter/test/__init__.py -------------------------------------------------------------------------------- /mcrouter/test/cpp_unit_tests/.gitignore: -------------------------------------------------------------------------------- 1 | /mcrouter_test 2 | -------------------------------------------------------------------------------- /mcrouter/test/cpp_unit_tests/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | check_PROGRAMS = mcrouter_test 7 | 8 | mcrouter_test_SOURCES = \ 9 | main.cpp \ 10 | awriter_test.cpp \ 11 | config_api_test.cpp \ 12 | exponential_smooth_data_test.cpp \ 13 | file_observer_test.cpp \ 14 | flavor_test.cpp \ 15 | LeaseTokenMapTest.cpp \ 16 | mc_route_handle_provider_test.cpp \ 17 | McrouterClientUsage.cpp \ 18 | observable_test.cpp \ 19 | options_test.cpp \ 20 | pool_factory_test.cpp \ 21 | ProxyRequestContextTest.cpp \ 22 | route_test.cpp 23 | 24 | mcrouter_test_CPPFLAGS = \ 25 | -I$(top_srcdir)/.. \ 26 | -isystem $(top_srcdir)/lib/gtest/include 27 | 28 | mcrouter_test_LDADD = \ 29 | $(top_builddir)/libmcroutercore.a \ 30 | $(top_builddir)/lib/libmcrouter.a \ 31 | $(top_builddir)/lib/libtestmain.la \ 32 | $(top_builddir)/lib/network/libtest_util.a \ 33 | -lwangle \ 34 | -lfizz \ 35 | -lsodium \ 36 | -lfolly 37 | -------------------------------------------------------------------------------- /mcrouter/test/cpp_unit_tests/files/already_replied.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "127.0.0.1:4242" ] 5 | } 6 | }, 7 | "route": "PoolRoute|A" 8 | } 9 | -------------------------------------------------------------------------------- /mcrouter/test/cpp_unit_tests/files/libmcrouter_invalid_pools.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ 5 | "localhost:11400", 6 | {"totally" : "invalid"} 7 | ] 8 | } 9 | }, 10 | "route": "PoolRoute|A" 11 | } 12 | -------------------------------------------------------------------------------- /mcrouter/test/cpp_unit_tests/files/memcache_local_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "localhost:PORT" ] 5 | } 6 | }, 7 | "route": "PoolRoute|A" 8 | } 9 | -------------------------------------------------------------------------------- /mcrouter/test/cpp_unit_tests/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | // Configure folly to enable INFO+ messages, and everything else to 11 | // enable WARNING+. 12 | // Set the default log handler to log asynchronously by default. 13 | FOLLY_INIT_LOGGING_CONFIG(".=WARNING,folly=INFO; default:async=true"); 14 | -------------------------------------------------------------------------------- /mcrouter/test/cpp_unit_tests/test_foreach_client.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { "servers": [ "localhost:12345" ] }, 4 | "B": { "servers": [ "localhost:12346" ] }, 5 | "C": { "servers": [ "localhost:12347" ] } 6 | }, 7 | "route": { 8 | "type": "PrefixSelectorRoute", 9 | "policies": { 10 | "a": { 11 | "type": "PoolRoute", 12 | "pool": "A", 13 | "shard_splits": { "1": 3 }, 14 | "shadows": [ 15 | { 16 | "target": "PoolRoute|C", 17 | "index_range": [0, 1], 18 | "key_fraction_range": [0, 1], 19 | "shard_splits": {} 20 | } 21 | ] 22 | }, 23 | "b": { 24 | "type": "FailoverWithExptimeRoute", 25 | "normal": { 26 | "type": "PoolRoute", 27 | "pool": "B", 28 | "shard_splits": { "2": 10 } 29 | }, 30 | "failover": "PoolRoute|A" 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /mcrouter/test/invalid_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.wildcard": { 4 | "servers": [ "127.0.0.1:11615" ] 5 | } 6 | }, 7 | "route": "PoolRoute|A.pho" 8 | } 9 | -------------------------------------------------------------------------------- /mcrouter/test/mcrouter_config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | 8 | # Dummy Thrift client 9 | class ThriftTestClient: 10 | def __init__(self, addr, port) -> None: 11 | raise NotImplementedError 12 | 13 | def sendVersion(self) -> str: 14 | raise NotImplementedError 15 | 16 | 17 | class McrouterGlobals: 18 | @staticmethod 19 | def binPath(name): 20 | bins = { 21 | "mcrouter": "./mcrouter/mcrouter", 22 | "mcpiper": "./mcrouter/tools/mcpiper/mcpiper", 23 | "mockmc": "./mcrouter/lib/network/test/mock_mc_server", 24 | "prodmc": "./mcrouter/lib/network/test/mock_mc_server", 25 | } 26 | return bins[name] 27 | 28 | @staticmethod 29 | def preprocessArgs(args): 30 | return args 31 | 32 | @staticmethod 33 | def useThriftClient(): 34 | return False 35 | 36 | @staticmethod 37 | def createThriftTestClient(addr, port) -> ThriftTestClient: 38 | raise NotImplementedError 39 | -------------------------------------------------------------------------------- /mcrouter/test/mcrouter_test_basic_1_1_1.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "foo": { 4 | "servers": [ "localhost:12345" ] 5 | } 6 | }, 7 | "route": "PoolRoute|foo" 8 | } 9 | -------------------------------------------------------------------------------- /mcrouter/test/mcrouter_test_basic_2_1_1.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.wildcard": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "B.wildcard": { 7 | "servers": [ "localhost:12346" ] 8 | } 9 | }, 10 | "routes": [ 11 | { 12 | "aliases": [ "/a/a/" ], 13 | "route": "PoolRoute|A.wildcard" 14 | }, 15 | { 16 | "aliases": [ "/b/b/" ], 17 | "route": "PoolRoute|B.wildcard" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /mcrouter/test/mcrouter_test_basic_3_1_1.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "foo": { 4 | "servers": [ "localhost:12345" ] 5 | } 6 | }, 7 | "route": { 8 | "type": "PoolRoute", 9 | "pool": "foo" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /mcrouter/test/mcrouter_test_bucketized_poolroute_bucketized.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "foo": { 4 | "servers": [ "localhost:12345", "localhost:12346", "localhost:12347", "localhost:12348", "localhost:12349" ], 5 | "weights": [0.5, 0.5, 0.5, 0.5, 0.5] 6 | } 7 | }, 8 | "route": { 9 | "type": "PoolRoute", 10 | "pool": "foo", 11 | "bucketize": true, 12 | "total_buckets": 1000, 13 | "bucketization_keyspace": "test", 14 | "hash": "WeightedCh3" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mcrouter/test/mcrouter_test_bucketized_poolroute_nonbucketized.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "foo": { 4 | "servers": [ "localhost:12345", "localhost:12346", "localhost:12347", "localhost:12348", "localhost:12349" ] 5 | } 6 | }, 7 | "route": { 8 | "type": "PoolRoute", 9 | "pool": "foo", 10 | "bucketize": false 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /mcrouter/test/mcrouter_test_portoverride.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "foo": { 4 | "servers": [ "localhost" ], 5 | "port_override": "@int(%PORT%)" 6 | } 7 | }, 8 | "route": "PoolRoute|foo" 9 | } 10 | -------------------------------------------------------------------------------- /mcrouter/test/routing_prefix_test_custom.json: -------------------------------------------------------------------------------- 1 | { 2 | "macros": { 3 | "route": { 4 | "type": "macroDef", 5 | "params": [ "a", "b" ], 6 | "result": { 7 | "aliases": [ "/%a%/%b%/" ], 8 | "route": "PoolRoute|%a%%b%" 9 | } 10 | } 11 | }, 12 | "pools": { 13 | "aa": { 14 | "servers": [ "127.0.0.1:12345" ] 15 | }, 16 | "ab": { 17 | "servers": [ "127.0.0.1:12346" ] 18 | }, 19 | "ba": { 20 | "servers": [ "127.0.0.1:12347" ] 21 | }, 22 | "bb": { 23 | "servers": [ "127.0.0.1:12348" ] 24 | } 25 | }, 26 | "routes": [ 27 | "@route(a, a)", 28 | "@route(a, b)", 29 | "@route(b, a)", 30 | "@route(b, b)" 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /mcrouter/test/routing_prefix_test_fallback_route.json: -------------------------------------------------------------------------------- 1 | { 2 | "macros": { 3 | "route": { 4 | "type": "macroDef", 5 | "params": [ "a", "b" ], 6 | "result": { 7 | "aliases": [ "/%a%/%b%/" ], 8 | "route": "PoolRoute|%a%%b%" 9 | } 10 | }, 11 | "fallbackRoute": { 12 | "type": "macroDef", 13 | "params": [ "a", "b" ], 14 | "result": { 15 | "aliases": [ "/%a%/fallback/" ], 16 | "route": "PoolRoute|%a%%b%" 17 | } 18 | } 19 | }, 20 | "pools": { 21 | "aa": { 22 | "servers": [ "127.0.0.1:12345" ] 23 | }, 24 | "ab": { 25 | "servers": [ "127.0.0.1:12346" ] 26 | }, 27 | "ba": { 28 | "servers": [ "127.0.0.1:12347" ] 29 | }, 30 | "bb": { 31 | "servers": [ "127.0.0.1:12348" ] 32 | } 33 | }, 34 | "routes": [ 35 | "@route(a, a)", 36 | "@route(a, b)", 37 | "@fallbackRoute(a, a)", 38 | "@route(b, a)", 39 | "@route(b, b)", 40 | "@fallbackRoute(b, a)" 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /mcrouter/test/run_cpp_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | ROOT_PATH="$(pwd)" 8 | SCRIPT_PATH="$(dirname "$0")" 9 | cd "$SCRIPT_PATH"/../.. && "$ROOT_PATH/$1" 10 | -------------------------------------------------------------------------------- /mcrouter/test/run_python_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | PYTHON_PATH="$1" 8 | TEST_NAME="$(basename "$2")" 9 | TEST_MODULE="${TEST_NAME%.*}" 10 | SCRIPT_PATH="$(dirname "$0")" 11 | cd "$SCRIPT_PATH"/../.. && $PYTHON_PATH -B -m unittest -q mcrouter.test."$TEST_MODULE" 12 | -------------------------------------------------------------------------------- /mcrouter/test/runtime_vars_file.json: -------------------------------------------------------------------------------- 1 | { 2 | "index_range_0": [0, 1], 3 | "key_fraction_range_0": [0.4, 0.5] 4 | } 5 | -------------------------------------------------------------------------------- /mcrouter/test/test_additional_fields.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | # pyre-unsafe 8 | 9 | from mcrouter.test.MCProcess import Memcached 10 | from mcrouter.test.McrouterTestCase import McrouterTestCase 11 | 12 | 13 | class TestAdditionalFields(McrouterTestCase): 14 | config = "./mcrouter/test/test_basic_caret.json" 15 | 16 | def setUp(self): 17 | self.mc = self.add_server(Memcached()) 18 | self.mcrouter = self.add_mcrouter(self.config) 19 | 20 | def test_basic(self): 21 | self.assertTrue(self.mcrouter.set("abc", "def")) 22 | self.assertEqual(self.mcrouter.get("abc"), "def") 23 | -------------------------------------------------------------------------------- /mcrouter/test/test_ascii_gut.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "127.0.0.1:11540" ], 5 | "protocol": "ascii" 6 | } 7 | }, 8 | "route": "PoolRoute|A" 9 | } 10 | -------------------------------------------------------------------------------- /mcrouter/test/test_axon_log.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "localhost:12345"], 5 | "weights": [1.0] 6 | } 7 | }, 8 | "route": { 9 | "type": "PoolRoute", 10 | "pool": "A", 11 | "protocol": "thrift", 12 | "bucketize": true, 13 | "bucketization_keyspace": "test", 14 | "total_buckets": 1000, 15 | "hash": "WeightedCh3", 16 | "axonlog": true, 17 | "axonlog_tier": "axon.dl_memcache", 18 | "axonlog_keyspace": 4, 19 | "axonlog_all_delete": false, 20 | "axonlog_default_region_filter": "georgia" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mcrouter/test/test_axon_log_alldelete.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "localhost:12345"], 5 | "weights": [1.0] 6 | } 7 | }, 8 | "route": { 9 | "type": "PoolRoute", 10 | "pool": "A", 11 | "protocol": "thrift", 12 | "bucketize": true, 13 | "bucketization_keyspace": "test", 14 | "total_buckets": 1000, 15 | "hash": "WeightedCh3", 16 | "axonlog": true, 17 | "axonlog_tier": "axon.dl_memcache", 18 | "axonlog_keyspace": 4, 19 | "axonlog_all_delete": true, 20 | "axonlog_default_region_filter": "georgia" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mcrouter/test/test_basic_all_first.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.wildcard": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "B.wildcard": { 7 | "servers": [ "localhost:12346" ] 8 | }, 9 | "C.wildcard": { 10 | "servers": [ "localhost:12347" ] 11 | } 12 | }, 13 | "route": { 14 | "type": "AllFastestRoute", 15 | "children": [ 16 | "PoolRoute|A.wildcard", 17 | "PoolRoute|B.wildcard", 18 | "PoolRoute|C.wildcard" 19 | ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mcrouter/test/test_basic_all_majority.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.wildcard": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "B.wildcard": { 7 | "servers": [ "localhost:12346" ] 8 | }, 9 | "C.wildcard": { 10 | "servers": [ "localhost:12347" ] 11 | }, 12 | "D.wildcard": { 13 | "servers": [ "localhost:12348" ] 14 | } 15 | }, 16 | "route": { 17 | "type": "AllMajorityRoute", 18 | "children": [ 19 | "PoolRoute|A.wildcard", 20 | "PoolRoute|B.wildcard", 21 | "PoolRoute|C.wildcard", 22 | "PoolRoute|D.wildcard" 23 | ] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /mcrouter/test/test_basic_all_sync.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.wildcard": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "B.wildcard": { 7 | "servers": [ "localhost:12346" ] 8 | }, 9 | "C.wildcard": { 10 | "servers": [ "localhost:12347" ] 11 | } 12 | }, 13 | "route": { 14 | "type": "AllSyncRoute", 15 | "children": [ 16 | "PoolRoute|A.wildcard", 17 | "PoolRoute|B.wildcard", 18 | "PoolRoute|C.wildcard" 19 | ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mcrouter/test/test_basic_caret.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "foo": { 4 | "servers": [ "localhost:12345" ], 5 | "protocol": "caret" 6 | } 7 | }, 8 | "route": "PoolRoute|foo" 9 | } 10 | 11 | -------------------------------------------------------------------------------- /mcrouter/test/test_basic_failover.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.wildcard": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "B.wildcard": { 7 | "servers": [ "localhost:12346" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "FailoverWithExptimeRoute", 12 | "failover": "PoolRoute|B.wildcard", 13 | "normal": "PoolRoute|A.wildcard" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mcrouter/test/test_basic_failover_least_failures.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.wildcard": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "B.wildcard": { 7 | "servers": [ "localhost:12346" ] 8 | }, 9 | "C.wildcard": { 10 | "servers": [ "localhost:12347" ] 11 | }, 12 | "D.wildcard": { 13 | "servers": [ "localhost:12348" ] 14 | } 15 | }, 16 | "route": { 17 | "type": "FailoverRoute", 18 | "children": ["PoolRoute|A.wildcard", 19 | "PoolRoute|B.wildcard", 20 | "PoolRoute|C.wildcard", 21 | "PoolRoute|D.wildcard"], 22 | "failover_policy": { 23 | "type": "LeastFailuresPolicy", 24 | "max_tries": 3 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mcrouter/test/test_basic_failover_override.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.wildcard": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "B.wildcard": { 7 | "servers": [ "localhost:12346" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "FailoverWithExptimeRoute", 12 | "failover": "PoolRoute|B.wildcard", 13 | "normal": "PoolRoute|A.wildcard", 14 | "failover_errors": { 15 | "updates": [] 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mcrouter/test/test_basic_l1_l2.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "B": { 7 | "servers": [ "localhost:12346" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "L1L2CacheRoute", 12 | "l1": "PoolRoute|A", 13 | "l2": "PoolRoute|B", 14 | "upgradingL1Exptime": 0 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mcrouter/test/test_basic_l1_l2_ncache.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "B": { 7 | "servers": [ "localhost:12346" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "L1L2CacheRoute", 12 | "l1": "PoolRoute|A", 13 | "l2": "PoolRoute|B", 14 | "upgradingL1Exptime": 0, 15 | "ncacheExptime": 3600, 16 | "ncacheUpdatePeriod": 5 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mcrouter/test/test_basic_l1_l2_sizesplit.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "localhost:12345:caret" ] 5 | }, 6 | "B": { 7 | "servers": [ "localhost:12346:caret" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "L1L2SizeSplitRoute", 12 | "l1": "PoolRoute|A", 13 | "l2": "PoolRoute|B", 14 | "threshold": 8, 15 | "both_full_set": false 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mcrouter/test/test_basic_l1_l2_sizesplit_bothset.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "localhost:12345:caret" ] 5 | }, 6 | "B": { 7 | "servers": [ "localhost:12346:caret" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "L1L2SizeSplitRoute", 12 | "l1": "PoolRoute|A", 13 | "l2": "PoolRoute|B", 14 | "threshold": 8, 15 | "both_full_set": true 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mcrouter/test/test_basic_l1_l2_sizesplit_retry_invalid.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "localhost:12345:caret" ] 5 | }, 6 | "B": { 7 | "servers": [ "localhost:12346:caret" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "L1L2SizeSplitRoute", 12 | "l1": "PoolRoute|A", 13 | "l2": "PoolRoute|B", 14 | "threshold": 8, 15 | "both_full_set": false, 16 | "retries": 100 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mcrouter/test/test_basic_l1_l2_sizesplit_retry_valid.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "localhost:12345:caret" ] 5 | }, 6 | "B": { 7 | "servers": [ "localhost:12346:caret" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "L1L2SizeSplitRoute", 12 | "l1": "PoolRoute|A", 13 | "l2": "PoolRoute|B", 14 | "threshold": 8, 15 | "both_full_set": false, 16 | "retries": 3 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mcrouter/test/test_basic_l1_multiple_l2_sizesplit.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "localhost:12345:caret" ] 5 | }, 6 | "B": { 7 | "servers": [ "localhost:12346:caret", "localhost:12347:caret", "localhost:12348:caret" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "L1L2SizeSplitRoute", 12 | "l1": "PoolRoute|A", 13 | "l2": "PoolRoute|B", 14 | "threshold": 8, 15 | "both_full_set": false 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mcrouter/test/test_bigvalue.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "foo": { 4 | "servers": [ 5 | "[::1]:10001" 6 | ] 7 | } 8 | }, 9 | "route": "PoolRoute|foo" 10 | } 11 | -------------------------------------------------------------------------------- /mcrouter/test/test_caret_server.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | /* We need this port for the test case to ignore */ 4 | "mc": { 5 | "protocol": "caret", 6 | "servers": [ "localhost:11002" ] 7 | }, 8 | "mcr": { 9 | "protocol": "caret", 10 | "servers": [ "localhost:11003" ] 11 | } 12 | }, 13 | "route": "PoolRoute|mcr" 14 | } 15 | -------------------------------------------------------------------------------- /mcrouter/test/test_config_params.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "localhost:%PORT%" ] 5 | } 6 | }, 7 | "route": "PoolRoute|%POOL%" 8 | } -------------------------------------------------------------------------------- /mcrouter/test/test_const_shard_hash.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A-foo": { 4 | "servers": [ 5 | "127.0.0.1:11610", 6 | "127.0.0.1:11611" 7 | ] 8 | } 9 | }, 10 | "route": { 11 | "type": "PoolRoute", 12 | "pool": "A-foo", 13 | "hash": "ConstShard" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mcrouter/test/test_const_shard_hash.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | # pyre-unsafe 8 | 9 | from mcrouter.test.MCProcess import Memcached 10 | from mcrouter.test.McrouterTestCase import McrouterTestCase 11 | 12 | 13 | class TestConstShardHash(McrouterTestCase): 14 | config = "./mcrouter/test/test_const_shard_hash.json" 15 | extra_args = [] 16 | 17 | def test_const_shard_hash(self): 18 | mc1 = self.add_server(Memcached()) 19 | mc2 = self.add_server(Memcached()) 20 | mcrouter = self.add_mcrouter(self.config, extra_args=self.extra_args) 21 | 22 | key = "foo:0:test" 23 | value = "value0" 24 | mcrouter.set(key, value) 25 | self.assertEqual(mc1.get(key), value) 26 | self.assertIsNone(mc2.get(key)) 27 | key = "foo:1:test" 28 | value = "value1" 29 | mcrouter.set(key, value) 30 | self.assertIsNone(mc1.get(key)) 31 | self.assertEqual(mc2.get(key), value) 32 | -------------------------------------------------------------------------------- /mcrouter/test/test_custom_failover.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.wildcard": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "B.wildcard": { 7 | "servers": [ "localhost:12346" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "FailoverRoute", 12 | "children": ["PoolRoute|A.wildcard", "PoolRoute|B.wildcard"], 13 | "failover_errors": ["remote_error"] 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mcrouter/test/test_custom_failover_override.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.wildcard": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "B.wildcard": { 7 | "servers": [ "localhost:12346" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "FailoverRoute", 12 | "children": ["PoolRoute|A.wildcard", "PoolRoute|B.wildcard"], 13 | "failover_errors": { 14 | "gets": ["remote_error"], 15 | "updates": [] 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mcrouter/test/test_deterministic_failover5.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "pools": { 4 | "A.wildcard": { 5 | "servers": [ "localhost:5001", 6 | "localhost:5002", 7 | "localhost:5003", 8 | "localhost:5004", 9 | "localhost:5005", 10 | "localhost:5006", 11 | "localhost:5007", 12 | "localhost:5008", 13 | "localhost:5009", 14 | "localhost:5010"] 15 | } 16 | }, 17 | "route": { 18 | "type": "FailoverRoute", 19 | "children": ["PoolRoute|A.wildcard", 20 | { 21 | "type":"Pool", 22 | "name":"B1", 23 | "protocol":"caret", 24 | "servers": [ "localhost:5011"] 25 | } 26 | ], 27 | "failover_policy": { 28 | "type": "DeterministicOrderPolicy", 29 | "max_tries": 2, 30 | "max_error_tries": 2, 31 | "ignore_normal_reply_index": true 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /mcrouter/test/test_dev_null.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.good": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "A.wildcard": { 7 | "servers": [ "localhost:12347" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "PrefixSelectorRoute", 12 | "policies": { 13 | "good": "PoolRoute|A.good", 14 | "null": "DevNullRoute" 15 | }, 16 | "wildcard": "PoolRoute|A.wildcard" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mcrouter/test/test_dump_config_invalid.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "foo": { 4 | "servers": [ "localhost:12345" ] 5 | } 6 | }, 7 | "route": "-PoolRoute|foo" 8 | } 9 | -------------------------------------------------------------------------------- /mcrouter/test/test_duplicate_servers.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.wildcard": { 4 | "servers": [ 5 | "localhost:12345", 6 | "localhost:12345" 7 | ] 8 | }, 9 | "B.wildcard": { 10 | "servers": [ 11 | "localhost:12345", 12 | "localhost:12345" 13 | ] 14 | } 15 | }, 16 | "routes": [ 17 | { 18 | "aliases": [ "/a/a/" ], 19 | "route": "PoolRoute|A.wildcard" 20 | }, 21 | { 22 | "aliases": [ "/b/b/" ], 23 | "route": "PoolRoute|B.wildcard" 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /mcrouter/test/test_duplicate_servers_difftimeouts.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.wildcard": { 4 | "server_timeout": 1000, 5 | "servers": [ 6 | "localhost:12345", 7 | "localhost:12345" 8 | ] 9 | }, 10 | "B.wildcard": { 11 | "server_timeout": 2000, 12 | "servers": [ 13 | "localhost:12345", 14 | "localhost:12345" 15 | ] 16 | } 17 | }, 18 | "routes": [ 19 | { 20 | "aliases": [ "/a/a/" ], 21 | "route": "PoolRoute|A.wildcard" 22 | }, 23 | { 24 | "aliases": [ "/b/b/" ], 25 | "route": "PoolRoute|B.wildcard" 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /mcrouter/test/test_empty_pool.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A-foo": { 4 | "servers": [] 5 | } 6 | }, 7 | "route": { 8 | "type": "AllSyncRoute", 9 | "children": [ 10 | "AllAsyncRoute|Pool|A-foo", 11 | "AllFastestRoute|Pool|A-foo", 12 | "AllInitialRoute|Pool|A-foo", 13 | "AllMajorityRoute|Pool|A-foo", 14 | "AllSyncRoute|Pool|A-foo", 15 | "FailoverRoute|Pool|A-foo", 16 | "HashRoute|Pool|A-foo", 17 | "HostIdRoute|Pool|A-foo", 18 | "LatestRoute|Pool|A-foo", 19 | "MissFailoverRoute|Pool|A-foo", 20 | "PoolRoute|A-foo", 21 | "RandomRoute|Pool|A-foo" 22 | ] 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /mcrouter/test/test_empty_pool.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | # pyre-unsafe 8 | 9 | from mcrouter.test.McrouterTestCase import McrouterTestCase 10 | 11 | 12 | class TestEmptyPool(McrouterTestCase): 13 | config = "./mcrouter/test/test_empty_pool.json" 14 | extra_args = [] 15 | 16 | def get_mcrouter(self, extra_args=()): 17 | return self.add_mcrouter(self.config, extra_args=self.extra_args) 18 | 19 | def test_empty_pool(self): 20 | # Start a mcrouter without route handles 21 | key = "foo" 22 | mcrouter_w_rh = self.get_mcrouter() 23 | self.assertIn( 24 | "SERVER_ERROR HashRoute with empty children", mcrouter_w_rh.get(key) 25 | ) 26 | -------------------------------------------------------------------------------- /mcrouter/test/test_failover_limit.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.gut": { 4 | "servers": [ "localhost:12345" ] 5 | } 6 | }, 7 | "route": { 8 | "type": "FailoverRoute", 9 | "children": [ 10 | { 11 | "type": "ErrorRoute", 12 | "enable_logging": false, 13 | "result": "mc_res_busy" 14 | }, 15 | "PoolRoute|A.gut" 16 | ], 17 | "failover_limit": { 18 | "rate": 0.2, 19 | "burst": 9.8 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mcrouter/test/test_failover_limit_error.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.gut": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "B.gut": { 7 | "servers": [ "localhost:23456" ] 8 | }, 9 | "C.gut": { 10 | "servers": [ "localhost:34567" ] 11 | } 12 | }, 13 | "route": { 14 | "type": "FailoverRoute", 15 | "children": [ 16 | { 17 | "type": "ErrorRoute", 18 | "enable_logging": false, 19 | "result": "mc_res_busy" 20 | }, 21 | "PoolRoute|A.gut", 22 | "PoolRoute|B.gut", 23 | "PoolRoute|C.gut" 24 | ], 25 | "failover_limit": { 26 | "rate": 0.2, 27 | "burst": 9.8 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /mcrouter/test/test_get_failover.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.gut": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "A.wildcard": { 7 | "servers": [ "localhost:12346" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "FailoverWithExptimeRoute", 12 | "failover": "PoolRoute|A.gut", 13 | "normal": "PoolRoute|A.wildcard", 14 | "failover_exptime": 3 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mcrouter/test/test_get_failover_with_failover_tag.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.gut": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "A.wildcard": { 7 | "servers": [ "localhost:12346" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "FailoverWithExptimeRoute", 12 | "failover": "PoolRoute|A.gut", 13 | "normal": "PoolRoute|A.wildcard", 14 | "failover_exptime": 3, 15 | "failover_tag": true 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mcrouter/test/test_largeobj.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.wildcard": { 4 | "servers": [ "[localhost]:11132" ] 5 | } 6 | }, 7 | "route": "PoolRoute|A.wildcard" 8 | } 9 | -------------------------------------------------------------------------------- /mcrouter/test/test_largeobj.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | # pyre-unsafe 8 | 9 | from mcrouter.test.McrouterTestCase import McrouterTestCase 10 | from mcrouter.test.mock_servers import StoreServer 11 | 12 | 13 | class TestLargeObj(McrouterTestCase): 14 | config = "./mcrouter/test/test_largeobj.json" 15 | extra_args = [] 16 | value_size = 1024 * 1024 * 2 + 1 17 | 18 | def setUp(self): 19 | self.add_server(StoreServer("test_largeobj", "x" * self.value_size)) 20 | self.mcrouter = self.add_mcrouter(self.config, extra_args=self.extra_args) 21 | 22 | def test_largeobj(self): 23 | string_x = "x" * self.value_size 24 | resp = self.mcrouter.set("test_largeobj", string_x) 25 | self.assertTrue(resp) 26 | -------------------------------------------------------------------------------- /mcrouter/test/test_latency_injection_after.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "127.0.0.1:11610" ], 5 | "protocol": "caret" 6 | } 7 | }, 8 | "route": { 9 | "type": "LatencyInjectionRoute", 10 | "child": "PoolRoute|A", 11 | "after_latency_ms": 1000 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /mcrouter/test/test_latency_injection_before.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "127.0.0.1:11610" ], 5 | "protocol": "caret" 6 | } 7 | }, 8 | "route": { 9 | "type": "LatencyInjectionRoute", 10 | "child": "PoolRoute|A", 11 | "before_latency_ms": 2000 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /mcrouter/test/test_latency_injection_total.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "127.0.0.1:11610" ], 5 | "protocol": "caret" 6 | } 7 | }, 8 | "route": { 9 | "type": "LatencyInjectionRoute", 10 | "child": "PoolRoute|A", 11 | "total_latency_ms": 2000 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /mcrouter/test/test_lease_pairing_basic.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ 5 | "localhost:11130", 6 | "localhost:11131" 7 | ] 8 | } 9 | }, 10 | "route": { 11 | "type": "FailoverRoute", 12 | "name": "01", 13 | "enable_lease_pairing": true, 14 | "children": "Pool|A" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mcrouter/test/test_lease_pairing_disabled.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ 5 | "localhost:11130", 6 | "localhost:11131" 7 | ] 8 | } 9 | }, 10 | "route": "FailoverRoute|Pool|A" 11 | } 12 | -------------------------------------------------------------------------------- /mcrouter/test/test_lease_pairing_nested.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ 5 | "localhost:11130", 6 | "localhost:11131" 7 | ] 8 | }, 9 | "B": { 10 | "servers": [ 11 | "localhost:11132", 12 | "localhost:11133" 13 | ] 14 | } 15 | }, 16 | "named_handles": [ 17 | { 18 | "type": "FailoverRoute", 19 | "name": "childA", 20 | "enable_lease_pairing": true, 21 | "children": "Pool|A" 22 | }, 23 | { 24 | "type": "FailoverRoute", 25 | "name": "childB", 26 | "enable_lease_pairing": true, 27 | "children": "Pool|B" 28 | } 29 | ], 30 | "route": { 31 | "type": "FailoverRoute", 32 | "name": "parent", 33 | "enable_lease_pairing": true, 34 | "children": [ 35 | "childA", 36 | "childB" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mcrouter/test/test_loadbalancer_route.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.wildcard": { 4 | "servers": [ 5 | "127.0.0.1:11610", 6 | "127.0.0.1:11611", 7 | "127.0.0.1:11612", 8 | "127.0.0.1:11613", 9 | "127.0.0.1:11614", 10 | "127.0.0.1:11615", 11 | "127.0.0.1:11616", 12 | "127.0.0.1:11617" 13 | ], 14 | "protocol": "caret" 15 | } 16 | }, 17 | "route": { 18 | "type": "PoolRoute", 19 | "pool": "A.wildcard", 20 | "hash": { 21 | "hash_func": "LoadBalancer", 22 | "load_ttl_ms": 100, 23 | "default_server_load_percent": 50 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /mcrouter/test/test_loadbalancer_route_thrift.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.wildcard": { 4 | "servers": [ 5 | "127.0.0.1:11610", 6 | "127.0.0.1:11611", 7 | "127.0.0.1:11612", 8 | "127.0.0.1:11613", 9 | "127.0.0.1:11614", 10 | "127.0.0.1:11615", 11 | "127.0.0.1:11616", 12 | "127.0.0.1:11617" 13 | ], 14 | "protocol": "thrift" 15 | } 16 | }, 17 | "route": { 18 | "type": "PoolRoute", 19 | "pool": "A.wildcard", 20 | "hash": { 21 | "hash_func": "LoadBalancer", 22 | "load_ttl_ms": 100, 23 | "enable_thrift_server_load": true 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /mcrouter/test/test_logging_route_mc.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "mc": { 4 | "servers": [ "localhost:11000" ] 5 | } 6 | }, 7 | "route": "PoolRoute|mc" 8 | } 9 | -------------------------------------------------------------------------------- /mcrouter/test/test_logging_route_server.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "mc": { 4 | "protocol": "caret", 5 | "servers": [ "localhost:11000" ] 6 | }, 7 | "mcr": { 8 | "protocol": "caret", 9 | "servers": [ "localhost:11001" ] 10 | } 11 | }, 12 | "route": "PoolRoute|mcr" 13 | } 14 | -------------------------------------------------------------------------------- /mcrouter/test/test_logical_routing_policies.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A-foo": { 4 | "servers": [ "127.0.0.1:11610" ] 5 | } 6 | }, 7 | "routes": [ 8 | { 9 | "aliases": [ 10 | "/region1/cluster1/", 11 | "/region1/cluster2/", 12 | "/region2/cluster3/" 13 | ], 14 | "route": "PoolRoute|A-foo" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /mcrouter/test/test_max_shadow_requests.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "main": { 4 | "servers": [ "127.0.0.1:12345" ] 5 | }, 6 | "shadow": { 7 | "servers": [ "127.0.0.1:12346" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "PoolRoute", 12 | "pool": "main", 13 | "shadows": [ 14 | { 15 | "target": "PoolRoute|shadow", 16 | "index_range": [0, 1], 17 | "key_fraction_range": [0.0, 1.0] 18 | } 19 | ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mcrouter/test/test_mcrefill.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "foo": { 4 | "servers": [ "127.0.0.1:5000" ] 5 | }, 6 | "baz": { 7 | "servers": [ "127.0.0.1:5001" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "McRefillRoute", 12 | "primary": "PoolRoute|foo", 13 | "refill": "PoolRoute|baz" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mcrouter/test/test_mcrouter_to_mcrouter_tko.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "foo": { 4 | "protocol": "caret", 5 | "servers": [ "localhost:12345" ] 6 | } 7 | }, 8 | "route": "AllSyncRoute|Pool|foo" 9 | } 10 | -------------------------------------------------------------------------------- /mcrouter/test/test_memcache_router.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | # pyre-unsafe 8 | 9 | from mcrouter.test.MCProcess import Memcached 10 | from mcrouter.test.McrouterTestCase import McrouterTestCase 11 | 12 | 13 | class TestMemcacheRouter(McrouterTestCase): 14 | config = "./mcrouter/test/test_basic_caret.json" 15 | extra_args = ["--carbon-router-name", "Memcache"] 16 | 17 | def setUp(self) -> None: 18 | self.mc = self.add_server(Memcached()) 19 | self.mcrouter = self.add_mcrouter(self.config, extra_args=self.extra_args) 20 | 21 | def test_basic(self) -> None: 22 | self.assertTrue(self.mcrouter.set("abc", "def")) 23 | self.assertEqual(self.mcrouter.get("abc"), "def") 24 | -------------------------------------------------------------------------------- /mcrouter/test/test_migrated_failover.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A-old": { 4 | "servers": [ "127.0.0.1:11610" ] 5 | }, 6 | "A-new": { 7 | "servers": [ "127.0.0.1:11611" ] 8 | }, 9 | "B-old": { 10 | "servers": [ "127.0.0.1:11612" ] 11 | }, 12 | "B-new": { 13 | "servers": [ "127.0.0.1:11613" ] 14 | } 15 | }, 16 | "route": { 17 | "type": "FailoverWithExptimeRoute", 18 | "normal": { 19 | "type": "MigrateRoute", 20 | "from": "PoolRoute|A-old", 21 | "to": "PoolRoute|A-new", 22 | "start_time": 0, 23 | "interval": 120 24 | }, 25 | "failover": { 26 | "type": "MigrateRoute", 27 | "from": "PoolRoute|B-old", 28 | "to": "PoolRoute|B-new", 29 | "start_time": 0, 30 | "interval": 120 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mcrouter/test/test_migrated_pools.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "wildcard-new": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "wildcard-old": { 7 | "servers": [ "localhost:12346" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "MigrateRoute", 12 | "from": "PoolRoute|wildcard-old", 13 | "to": "PoolRoute|wildcard-new", 14 | "start_time": START_TIME, 15 | "interval": 4 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mcrouter/test/test_migrated_pools_failover.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A-new": { 4 | "servers": [ "localhost:12345" ] 5 | }, 6 | "A-old": { 7 | "servers": [ "localhost:12346" ] 8 | }, 9 | "B-new": { 10 | "servers": [ "localhost:12347" ] 11 | }, 12 | "B-old": { 13 | "servers": [ "localhost:12348" ] 14 | } 15 | }, 16 | "route": { 17 | "type": "FailoverWithExptimeRoute", 18 | "failover": { 19 | "type": "MigrateRoute", 20 | "from": "PoolRoute|B-old", 21 | "to": "PoolRoute|B-new", 22 | "start_time": START_TIME, 23 | "interval": 4 24 | }, 25 | "normal": { 26 | "type": "MigrateRoute", 27 | "from": "PoolRoute|A-old", 28 | "to": "PoolRoute|A-new", 29 | "start_time": START_TIME, 30 | "interval": 4 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mcrouter/test/test_miss_on_error_arith_ops.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A-foo": { 4 | "servers": [ "127.0.0.1:11610" ] 5 | } 6 | }, 7 | "route": { 8 | "type": "PrefixSelectorRoute", 9 | "policies": { 10 | "foo": "PoolRoute|A-foo" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /mcrouter/test/test_modify_exptime.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "localhost:12345" ] 5 | } 6 | }, 7 | "route": { 8 | "type": "PrefixSelectorRoute", 9 | "policies": { 10 | "a": { 11 | "type": "ModifyExptimeRoute", 12 | "target": "Pool|A", 13 | "exptime": -1 14 | }, 15 | "b": { 16 | "type": "ModifyExptimeRoute", 17 | "target": "Pool|A", 18 | "exptime": 0 19 | }, 20 | "c": { 21 | "type": "ModifyExptimeRoute", 22 | "target": "Pool|A", 23 | "action": "set", 24 | "exptime": 2 25 | }, 26 | "d": { 27 | "type": "ModifyExptimeRoute", 28 | "target": "Pool|A", 29 | "action": "min", 30 | "exptime": 2 31 | } 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /mcrouter/test/test_named_handles_list.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { "servers": [ "localhost:12345" ] }, 4 | "B": { "servers": [ "localhost:12346" ] } 5 | }, 6 | "named_handles": [ 7 | { 8 | "type": "PoolRoute", 9 | "name": "route:A", 10 | "pool": "A" 11 | }, 12 | { 13 | "type": "PoolRoute", 14 | "name": "route:B", 15 | "pool": "B" 16 | }, 17 | { 18 | "type": "AllSyncRoute", 19 | "name": "route:C", 20 | "children": "NullRoute" 21 | }, 22 | { 23 | "type": "AllSyncRoute", 24 | "name": "route:all", 25 | "children": [ "route:A", "route:B", "route:C" ] 26 | } 27 | ], 28 | "route": "route:all" 29 | } 30 | -------------------------------------------------------------------------------- /mcrouter/test/test_named_handles_obj.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { "servers": [ "localhost:12345" ] }, 4 | "B": { "servers": [ "localhost:12346" ] } 5 | }, 6 | "named_handles": { 7 | "route:all": { 8 | "type": "AllSyncRoute", 9 | "children": [ "route:A", "route:B", "route:C", "route:D" ] 10 | }, 11 | "route:A": { 12 | "type": "PoolRoute", 13 | "pool": "A" 14 | }, 15 | "null": "NullRoute", 16 | "route:B": "PoolRoute|B", 17 | "route:C": { 18 | "type": "AllSyncRoute", 19 | "children": "null" 20 | }, 21 | "route:D": "AllSyncRoute|route:C" 22 | }, 23 | "route": "route:all" 24 | } 25 | -------------------------------------------------------------------------------- /mcrouter/test/test_noreply.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "127.0.0.1:10001" ] 5 | } 6 | }, 7 | "route": "PoolRoute|A" 8 | } 9 | -------------------------------------------------------------------------------- /mcrouter/test/test_nullroute.json: -------------------------------------------------------------------------------- 1 | { 2 | "route": "NullRoute" 3 | } 4 | -------------------------------------------------------------------------------- /mcrouter/test/test_operation_selector_route.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "127.0.0.1:11111" ], 5 | "protocol": "caret" 6 | }, 7 | "B": { 8 | "servers": [ "127.0.0.1:22222" ], 9 | "protocol": "caret" 10 | }, 11 | "C": { 12 | "servers": [ "127.0.0.1:33333" ], 13 | "protocol": "caret" 14 | } 15 | }, 16 | "route": { 17 | "type": "OperationSelectorRoute", 18 | "default_policy": "ErrorRoute|A", 19 | "operation_policies": { 20 | "get": "PoolRoute|A", 21 | "set": "PoolRoute|B", 22 | "delete": "PoolRoute|C" 23 | } 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /mcrouter/test/test_pool_server_errors.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { "servers": [ { "type": "ErrorRoute" } ] }, 4 | "B": { 5 | "servers": [ 6 | "127.0.0.1:12345", 7 | { "type": "ErrorRoute" }, 8 | "127.0.0.1:12346" 9 | ] 10 | } 11 | }, 12 | "routes": { 13 | "/a/a/": "Pool|A", 14 | "/b/b/": "HashRoute|Pool|B" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mcrouter/test/test_poolstats_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "stats_enabled_pools" : [ 3 | "twmemcache.CI.west", 4 | "twmemcache.CI.east", 5 | "twmemcache.CI.north", 6 | "twmemcache.CI.south"] 7 | } 8 | -------------------------------------------------------------------------------- /mcrouter/test/test_probe_timeout.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "foo": { 4 | "servers": [ "localhost:12345" ] 5 | } 6 | }, 7 | "route": "PoolRoute|foo" 8 | } -------------------------------------------------------------------------------- /mcrouter/test/test_probe_timeout_reconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "foo": { 4 | "servers": [ "localhost:0" ] 5 | } 6 | }, 7 | "route": "PoolRoute|foo" 8 | } -------------------------------------------------------------------------------- /mcrouter/test/test_rendezvous_failover.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A.wildcard": { 4 | "servers": [ "localhost:5001", 5 | "localhost:5002", 6 | "localhost:5003", 7 | "localhost:5004", 8 | "localhost:5005"] 9 | } 10 | }, 11 | "route": { 12 | "type": "FailoverRoute", 13 | "children": ["PoolRoute|A.wildcard", 14 | { 15 | "type":"Pool", 16 | "name":"failover-test.pool.name", 17 | "protocol":"caret", 18 | "servers": [ "localhost:5001", 19 | "localhost:5002", 20 | "localhost:5003", 21 | "localhost:5004", 22 | "localhost:5005"] 23 | } 24 | ], 25 | "failover_policy": { 26 | "type": "RendezvousPolicy", 27 | "tags": [ "localhost:5001", 28 | "localhost:5002", 29 | "localhost:5003", 30 | "localhost:5004", 31 | "localhost:5005"] 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /mcrouter/test/test_routing_group_route.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": ["127.0.0.1:11111"], 5 | "protocol": "caret" 6 | }, 7 | "B": { 8 | "servers": ["127.0.0.1:22222"], 9 | "protocol": "caret" 10 | }, 11 | "C": { 12 | "servers": ["127.0.0.1:33333"], 13 | "protocol": "caret" 14 | }, 15 | "D": { 16 | "servers": ["127.0.0.1:44444"], 17 | "protocol": "caret" 18 | } 19 | }, 20 | "route": { 21 | "type": "RoutingGroupRoute", 22 | "default_policy": "ErrorRoute|A", 23 | "routing_group_policies": { 24 | "get_like": "PoolRoute|A", 25 | "update_like": "PoolRoute|B", 26 | "delete_like": "PoolRoute|C", 27 | "arithmetic_like": "PoolRoute|D" 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /mcrouter/test/test_routing_group_route_incomplete.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": ["127.0.0.1:11111"], 5 | "protocol": "caret" 6 | }, 7 | "B": { 8 | "servers": ["127.0.0.1:22222"], 9 | "protocol": "caret" 10 | } 11 | }, 12 | "route": { 13 | "type": "RoutingGroupRoute", 14 | "default_policy": "PoolRoute|A", 15 | "routing_group_policies": { 16 | "get_like": "PoolRoute|B", 17 | "update_like": "PoolRoute|B" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mcrouter/test/test_send_to_all_hosts.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "poolA": { 4 | "servers": [ "127.0.0.1:11810" ] 5 | }, 6 | "poolB": { 7 | "servers": [ 8 | "127.0.0.1:11811", 9 | "127.0.0.1:11812" 10 | ] 11 | } 12 | }, 13 | "route": { 14 | "type": "PrefixSelectorRoute", 15 | "policies": { 16 | "a": { 17 | "type": "AllSyncRoute", 18 | "children": [ 19 | "Pool|poolA", 20 | "AllSyncRoute|Pool|poolB" 21 | ] 22 | } 23 | }, 24 | "wildcard": "PoolRoute|poolA" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /mcrouter/test/test_server_stats_pending.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "foo": { 4 | "servers": [ "localhost:12345" ] 5 | } 6 | }, 7 | "route": "AllAsyncRoute|PoolRoute|foo" 8 | } 9 | 10 | -------------------------------------------------------------------------------- /mcrouter/test/test_service_info.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "127.0.0.1:11610" ] 5 | }, 6 | "B": { 7 | "servers": [ "127.0.0.1:11611" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "AllSyncRoute", 12 | "children": [ 13 | "PoolRoute|A", 14 | "PoolRoute|B" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mcrouter/test/test_shadow_with_file.json: -------------------------------------------------------------------------------- 1 | { 2 | "macros": { 3 | "pool": { 4 | "type": "macroDef", 5 | "params": [ "name" ], 6 | "result": { 7 | "type": "select", 8 | "key": "%name%", 9 | "dictionary": { 10 | "type": "merge", 11 | "params": [ 12 | { 13 | "%name%": "PoolRoute|%name%" 14 | }, 15 | "@import(test_shadow_with_file_config.json)" 16 | ] 17 | } 18 | } 19 | } 20 | }, 21 | "pools": { 22 | "foo": { 23 | "server_timeout": 3500, 24 | "servers": [ 25 | "127.0.0.1:%PORT_1%", 26 | "127.0.0.1:%PORT_2%" 27 | ] 28 | } 29 | }, 30 | "route": "@pool(foo)" 31 | } 32 | -------------------------------------------------------------------------------- /mcrouter/test/test_shadow_with_file_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "foo": { 3 | "type": "PoolRoute", 4 | "pool": "foo", 5 | "shadows": [ 6 | { 7 | "target": { 8 | "type": "PoolRoute", 9 | "pool": { 10 | "name": "foo-shadow", 11 | "servers": [ "127.0.0.1:%PORT_SHADOW%" ] 12 | } 13 | }, 14 | "index_range": [0, 2], 15 | "key_fraction_range": [0.0, 0.1] 16 | } 17 | ] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mcrouter/test/test_shard_splits.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ 5 | "127.0.0.1:11610", 6 | "127.0.0.1:11611", 7 | "127.0.0.1:11612" 8 | ] 9 | } 10 | }, 11 | "route": { 12 | "type": "PrefixSelectorRoute", 13 | "policies": { 14 | "a": { 15 | "type": "PoolRoute", 16 | "pool": "A", 17 | "shard_splits": { 18 | "1": 3, 19 | "2": 10000 20 | } 21 | }, 22 | "b": { 23 | "type": "PoolRoute", 24 | "pool": "A", 25 | "shard_splits": { 26 | "1": 2, 27 | "2": 1 28 | } 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /mcrouter/test/test_slow_warmup.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": ["localhost:11130"] 5 | } 6 | }, 7 | "route": { 8 | "type": "PoolRoute", 9 | "pool": "A", 10 | "slow_warmup": { 11 | "failoverTarget": "NullRoute", 12 | "settings": { 13 | "enable_threshold": 0.7, 14 | "disable_threshold": 0.9 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mcrouter/test/test_thrift_gut.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "127.0.0.1:11540" ], 5 | "protocol": "thrift" 6 | } 7 | }, 8 | "route": "PoolRoute|A" 9 | } 10 | -------------------------------------------------------------------------------- /mcrouter/test/test_tko_inactive.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | # pyre-unsafe 8 | 9 | import time 10 | 11 | from mcrouter.test.McrouterTestCase import McrouterTestCase 12 | 13 | from mcrouter.test.mock_servers import SleepServer 14 | 15 | 16 | class TestTkoInactive(McrouterTestCase): 17 | config = "./mcrouter/test/mcrouter_test_basic_1_1_1.json" 18 | extra_args = [ 19 | "--timeouts-until-tko", 20 | "1", 21 | "--reset-inactive-connection-interval", 22 | "750", 23 | "--server-timeout", 24 | "500", 25 | "--probe-timeout-initial", 26 | "500", 27 | ] 28 | 29 | def setUp(self): 30 | self.add_server(SleepServer()) 31 | self.mcrouter = self.add_mcrouter(self.config, extra_args=self.extra_args) 32 | 33 | def test_tko_inactive(self): 34 | self.assertIn("SERVER_ERROR", self.mcrouter.get("hit")) 35 | time.sleep(3) 36 | self.assertTrue(self.mcrouter.is_alive()) 37 | -------------------------------------------------------------------------------- /mcrouter/test/test_tko_reconfigure1.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "127.0.0.1:12345" ], 5 | "server_timeout": 12345 6 | } 7 | }, 8 | "route": "PoolRoute|A" 9 | } 10 | -------------------------------------------------------------------------------- /mcrouter/test/test_tko_reconfigure2.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A": { 4 | "servers": [ "127.0.0.1:12345" ], 5 | "server_timeout": 12346 6 | } 7 | }, 8 | "route": "PoolRoute|A" 9 | } 10 | -------------------------------------------------------------------------------- /mcrouter/test/test_unknown_name_handle.json: -------------------------------------------------------------------------------- 1 | { 2 | "named_handles": [ 3 | { 4 | "hash": { 5 | "salt": "gut.texas" 6 | }, 7 | "name" : "B", 8 | "pool": { 9 | "name" : "B4", 10 | "inherit" : "smc:twmemcache.gut.texas", 11 | "protocol": "thrift", 12 | "security_mech": "tls_to_plain", 13 | "port_override": 11322, 14 | "port_override_cross_dc": 11322, 15 | "qos": { 16 | "class": 2, 17 | "path": 2 18 | }, 19 | "port_override_within_dc": 11322 20 | }, 21 | "type": "PoolRoute" 22 | } 23 | ], 24 | 25 | "route": { 26 | "type": "FailoverRoute", 27 | "children": [ 28 | "D", 29 | "B" 30 | ] 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /mcrouter/test/test_warmup.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A-warm": { 4 | "servers": [ "127.0.0.1:11610" ] 5 | }, 6 | "A-cold": { 7 | "servers": [ "127.0.0.1:11611" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "PrefixSelectorRoute", 12 | "policies": { 13 | "foo": { 14 | "type": "MigrateRoute", 15 | "from": "PoolRoute|A-warm", 16 | "to": { 17 | "type": "WarmUpRoute", 18 | "cold": "PoolRoute|A-cold", 19 | "warm": "PoolRoute|A-warm", 20 | "exptime": 20000 21 | }, 22 | "start_time": 1380331354, 23 | "interval": 1 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mcrouter/test/test_warmup2.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": { 3 | "A-warm": { 4 | "servers": [ "127.0.0.1:11610" ] 5 | }, 6 | "A-cold": { 7 | "servers": [ "127.0.0.1:11611" ] 8 | } 9 | }, 10 | "route": { 11 | "type": "WarmUpRoute", 12 | "cold": "PoolRoute|A-cold", 13 | "warm": "PoolRoute|A-warm" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mcrouter/tools/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | SUBDIRS = mcpiper 7 | -------------------------------------------------------------------------------- /mcrouter/tools/mcpiper/AnsiColorCodeStream-inl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | namespace facebook { 11 | namespace memcache { 12 | 13 | template 14 | void AnsiColorCodeEncoder::writePlain(const T& t) { 15 | if (!isReset_) { 16 | reset(); 17 | } 18 | 19 | out_ << t; 20 | } 21 | } // namespace memcache 22 | } // namespace facebook 23 | -------------------------------------------------------------------------------- /mcrouter/tools/mcpiper/Color.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | 15 | enum class Color : uint8_t { 16 | DEFAULT, 17 | BLACK, 18 | BLUE, 19 | DARKBLUE, 20 | CYAN, 21 | DARKCYAN, 22 | GRAY, 23 | DARKGRAY, 24 | GREEN, 25 | DARKGREEN, 26 | MAGENTA, 27 | DARKMAGENTA, 28 | RED, 29 | DARKRED, 30 | WHITE, 31 | YELLOW, 32 | DARKYELLOW 33 | }; 34 | } 35 | } // namespace facebook 36 | -------------------------------------------------------------------------------- /mcrouter/tools/mcpiper/PrettyFormat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "mcrouter/tools/mcpiper/Color.h" 11 | 12 | namespace facebook { 13 | namespace memcache { 14 | 15 | /** 16 | * Pretty format, used to color StyledString. 17 | */ 18 | struct PrettyFormat { 19 | Color attrColor = Color::MAGENTA; 20 | Color dataOpColor = Color::DARKYELLOW; 21 | Color dataKeyColor = Color::YELLOW; 22 | Color dataValueColor = Color::DARKCYAN; 23 | Color headerColor = Color::WHITE; 24 | Color matchColor = Color::RED; 25 | Color msgAttrColor = Color::GREEN; 26 | }; 27 | } // namespace memcache 28 | } // namespace facebook 29 | --------------------------------------------------------------------------------