Skip to content

Commit be45cfa

Browse files
Joshua Pollackmeta-codesync[bot]
authored andcommitted
Add thrift-listen-sock-fd standalone option
Summary: Let the standalone mcrouter thrift server adopt a caller-provided, pre-bound listening socket instead of binding a port itself, mirroring the existing pre-bound-socket path used by AsyncMcServer. Existing port-based behavior is unchanged by default. Differential Revision: D112156692 fbshipit-source-id: 10d51ca95819f7c1009c1abae5d1963dea7efccc
1 parent 936cc70 commit be45cfa

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

mcrouter/Server-inl.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,15 @@ bool runServerDual(
394394
std::make_shared<ThriftAcceptorFactory>(
395395
*thriftServer, std::move(aclCheckerThrift), qos));
396396

397-
// Set listening port for cleartext and SSL connections
398-
if (standaloneOpts.thrift_port > 0) {
397+
// Set listening socket for cleartext and SSL connections
398+
if (standaloneOpts.thrift_listen_sock_fd >= 0) {
399+
thriftServer->useExistingSocket(standaloneOpts.thrift_listen_sock_fd);
400+
// A single adopted socket can only be bound by one acceptor.
401+
thriftServer->setNumAcceptThreads(1);
402+
} else if (standaloneOpts.thrift_port > 0) {
399403
thriftServer->setPort(standaloneOpts.thrift_port);
400404
} else {
401-
LOG(ERROR) << "Must specify thrift port";
405+
LOG(ERROR) << "Must specify thrift port or thrift listen socket fd";
402406
router->shutdown();
403407
freeAllRouters();
404408
return false;

mcrouter/StandaloneUtils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ bool areOptionsValid(
139139
LOG(ERROR) << "invalid ports";
140140
return false;
141141
}
142+
if (standaloneOpts.use_thrift && standaloneOpts.listen_sock_fd >= 0 &&
143+
standaloneOpts.thrift_listen_sock_fd >= 0 &&
144+
standaloneOpts.listen_sock_fd == standaloneOpts.thrift_listen_sock_fd) {
145+
LOG(ERROR) << "listen-sock-fd and thrift-listen-sock-fd must be different";
146+
return false;
147+
}
142148

143149
if (opts.keepalive_idle_s <= 0 || opts.keepalive_interval_s <= 0 ||
144150
opts.keepalive_cnt < 0) {

mcrouter/standalone_options_list.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ MCROUTER_OPTION_INTEGER(
285285
no_short,
286286
"Thrift Port to listen on")
287287

288+
MCROUTER_OPTION_INTEGER(
289+
int,
290+
thrift_listen_sock_fd,
291+
-1,
292+
"thrift-listen-sock-fd",
293+
no_short,
294+
"Thrift listen socket to take over")
295+
288296
MCROUTER_OPTION_DOUBLE(
289297
double,
290298
core_multiplier,

0 commit comments

Comments
 (0)