MCPcopy Create free account
hub / github.com/F-Stack/f-stack / clusterAcceptHandler

Function clusterAcceptHandler

app/redis-6.2.6/src/cluster.c:676–727  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

674
675#define MAX_CLUSTER_ACCEPTS_PER_CALL 1000
676void clusterAcceptHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
677 int cport, cfd;
678 int max = MAX_CLUSTER_ACCEPTS_PER_CALL;
679 char cip[NET_IP_STR_LEN];
680 UNUSED(el);
681 UNUSED(mask);
682 UNUSED(privdata);
683
684 /* If the server is starting up, don't accept cluster connections:
685 * UPDATE messages may interact with the database content. */
686 if (server.masterhost == NULL && server.loading) return;
687
688 while(max--) {
689 cfd = anetTcpAccept(server.neterr, fd, cip, sizeof(cip), &cport);
690 if (cfd == ANET_ERR) {
691 if (errno != EWOULDBLOCK)
692 serverLog(LL_VERBOSE,
693 "Error accepting cluster node: %s", server.neterr);
694 return;
695 }
696
697 connection *conn = server.tls_cluster ?
698 connCreateAcceptedTLS(cfd, TLS_CLIENT_AUTH_YES) : connCreateAcceptedSocket(cfd);
699
700 /* Make sure connection is not in an error state */
701 if (connGetState(conn) != CONN_STATE_ACCEPTING) {
702 serverLog(LL_VERBOSE,
703 "Error creating an accepting connection for cluster node: %s",
704 connGetLastError(conn));
705 connClose(conn);
706 return;
707 }
708 connNonBlock(conn);
709 connEnableTcpNoDelay(conn);
710 connKeepAlive(conn,server.cluster_node_timeout * 2);
711
712 /* Use non-blocking I/O for cluster messages. */
713 serverLog(LL_VERBOSE,"Accepting cluster node connection from %s:%d", cip, cport);
714
715 /* Accept the connection now. connAccept() may call our handler directly
716 * or schedule it for later depending on connection implementation.
717 */
718 if (connAccept(conn, clusterConnAcceptHandler) == C_ERR) {
719 if (connGetState(conn) == CONN_STATE_ERROR)
720 serverLog(LL_VERBOSE,
721 "Error accepting cluster node connection: %s",
722 connGetLastError(conn));
723 connClose(conn);
724 return;
725 }
726 }
727}
728
729/* Return the approximated number of sockets we are using in order to
730 * take the cluster bus connections. */

Callers

nothing calls this directly

Calls 10

anetTcpAcceptFunction · 0.85
connCreateAcceptedTLSFunction · 0.85
connCreateAcceptedSocketFunction · 0.85
connGetStateFunction · 0.85
connGetLastErrorFunction · 0.85
connCloseFunction · 0.85
connNonBlockFunction · 0.85
connEnableTcpNoDelayFunction · 0.85
connKeepAliveFunction · 0.85
connAcceptFunction · 0.85

Tested by

no test coverage detected