summaryrefslogtreecommitdiff
path: root/proto_proxy.c
diff options
context:
space:
mode:
authordormando <dormando@rydia.net>2022-09-23 12:18:22 -0700
committerdormando <dormando@rydia.net>2022-10-20 14:42:20 -0700
commitcedaf5586883ffd2323307f45f90f4d70e94ecc2 (patch)
treecfbbd3addb6622a1908b22514ef071faa63a92ce /proto_proxy.c
parent8d573b00a7c518dde1645e5f15f85e860931b763 (diff)
downloadmemcached-cedaf5586883ffd2323307f45f90f4d70e94ecc2.tar.gz
proxy: backend connection improvement
Improvements to handling of new and failed backend socket connections. Previously connections were initiated immediately, and initially from the config thread, yet completion of opening sockets wouldn't happen until a request tried to use that backend. Now we open connections via the IO thread, as well as validate new connections with a "version\r\n" command. Also fixes a couple of error conditions (parsing, backend disconnect) where clients could hang waiting for a retry time in certain conditions. Now connections should re-establish immediately and dead backends should flip into a bad fast-fail state quicker.
Diffstat (limited to 'proto_proxy.c')
-rw-r--r--proto_proxy.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/proto_proxy.c b/proto_proxy.c
index d39b7b1..a654b92 100644
--- a/proto_proxy.c
+++ b/proto_proxy.c
@@ -146,6 +146,11 @@ void *proxy_init(bool use_uring) {
perror("failed to create backend notify eventfd");
exit(1);
}
+ t->be_event_fd = eventfd(0, EFD_NONBLOCK);
+ if (t->be_event_fd == -1) {
+ perror("failed to create backend notify eventfd");
+ exit(1);
+ }
#else
int fds[2];
if (pipe(fds)) {
@@ -155,11 +160,19 @@ void *proxy_init(bool use_uring) {
t->notify_receive_fd = fds[0];
t->notify_send_fd = fds[1];
+
+ if (pipe(fds)) {
+ perror("can't create proxy backend connection notify pipe");
+ exit(1);
+ }
+ t->be_notify_receive_fd = fds[0];
+ t->be_notify_send_fd = fds[1];
#endif
proxy_init_evthread_events(t);
// incoming request queue.
STAILQ_INIT(&t->io_head_in);
+ STAILQ_INIT(&t->beconn_head_in);
pthread_mutex_init(&t->mutex, NULL);
pthread_cond_init(&t->cond, NULL);