pgpool2.git / summary / log / commit / refs

commit    8c85d8292b95694cf59a4fdb787c12e2209d0c35
Author:   Muhammad Usama <m.usama@gmail.com>
Date:     Tue Jun 17 13:30:37 2014 +0000

    do_accept() function was replaced with wait_for_new_connections()
    by exception manager checkin and is no longer needed but it still
    resides in the code.
    This checkin removes the dead code of obsolete function.


src/protocol/child.c | 325 +-------------------------------------------------- 1 file changed, 3 insertions(+), 322 deletions(-) diff --git a/src/protocol/child.c b/src/protocol/child.c index 563e2cd1c..92e6f62dd 100644 --- a/src/protocol/child.c +++ b/src/protocol/child.c @@ -60,7 +60,6 @@ #include "auth/md5.h" #include "auth/pool_passwd.h" -static POOL_CONNECTION *do_accept(int unix_fd, int inet_fd, struct timeval *timeout); static StartupPacket *read_startup_packet(POOL_CONNECTION *cp); static POOL_CONNECTION_POOL *connect_backend(StartupPacket *sp, POOL_CONNECTION *frontend); static RETSIGTYPE die(int sig); @@ -458,327 +457,9 @@ backend_cleanup(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL* volatile backen } /* - * perform accept() and return new fd - */ -static POOL_CONNECTION *do_accept(int unix_fd, int inet_fd, struct timeval *timeout) -{ - return NULL; - fd_set readmask; - int fds; - int save_errno; - - SockAddr saddr; - int fd = 0; - int afd; - int inet = 0; - POOL_CONNECTION *cp; -#ifdef ACCEPT_PERFORMANCE - struct timeval now1, now2; - static long atime; - static int cnt; -#endif - struct timeval *timeoutval; - struct timeval tv1, tv2, tmback = {0, 0}; - - set_ps_display("wait for connection request", false); - - /* Destroy session context for just in case... */ - pool_session_context_destroy(); - - FD_ZERO(&readmask); - FD_SET(unix_fd, &readmask); - if (inet_fd) - FD_SET(inet_fd, &readmask); - - if (timeout->tv_sec == 0 && timeout->tv_usec == 0) - timeoutval = NULL; - else - { - timeoutval = timeout; - tmback.tv_sec = timeout->tv_sec; - tmback.tv_usec = timeout->tv_usec; - gettimeofday(&tv1, NULL); - -#ifdef DEBUG - pool_log("before select = {%d, %d}", timeoutval->tv_sec, timeoutval->tv_usec); - pool_log("g:before select = {%d, %d}", tv1.tv_sec, tv1.tv_usec); -#endif - } - - fds = select(Max(unix_fd, inet_fd)+1, &readmask, NULL, NULL, timeoutval); - - save_errno = errno; - /* check backend timer is expired */ - if (backend_timer_expired) - { - pool_backend_timer(); - backend_timer_expired = 0; - } - - /* - * following code fragment computes remaining timeout val in a - * portable way. Linux does this automatically but other platforms do not. - */ - if (timeoutval) - { - gettimeofday(&tv2, NULL); - - tmback.tv_usec -= tv2.tv_usec - tv1.tv_usec; - tmback.tv_sec -= tv2.tv_sec - tv1.tv_sec; - - if (tmback.tv_usec < 0) - { - tmback.tv_sec--; - if (tmback.tv_sec < 0) - { - timeout->tv_sec = 0; - timeout->tv_usec = 0; - } - else - { - tmback.tv_usec += 1000000; - timeout->tv_sec = tmback.tv_sec; - timeout->tv_usec = tmback.tv_usec; - } - } -#ifdef DEBUG - pool_log("g:after select = {%d, %d}", tv2.tv_sec, tv2.tv_usec); - pool_log("after select = {%d, %d}", timeout->tv_sec, timeout->tv_usec); -#endif - } - - errno = save_errno; - - if (fds == -1) - { - if (errno == EAGAIN || errno == EINTR) - return NULL; - - pool_error("select() failed. reason %s", strerror(errno)); - return NULL; - } - - /* timeout */ - if (fds == 0) - { - return NULL; - } - - if (FD_ISSET(unix_fd, &readmask)) - { - fd = unix_fd; - } - - if (FD_ISSET(inet_fd, &readmask)) - { - fd = inet_fd; - inet++; - } - - /* - * Note that some SysV systems do not work here. For those - * systems, we need some locking mechanism for the fd. - */ - memset(&saddr, 0, sizeof(saddr)); - saddr.salen = sizeof(saddr.addr); - -#ifdef ACCEPT_PERFORMANCE - gettimeofday(&now1,0); -#endif - - retry_accept: - - /* wait if recovery is started */ - while (*InRecovery == 1) - { - pause(); - } - - afd = accept(fd, (struct sockaddr *)&saddr.addr, &saddr.salen); - - save_errno = errno; - /* check backend timer is expired */ - if (backend_timer_expired) - { - pool_backend_timer(); - backend_timer_expired = 0; - } - errno = save_errno; - if (afd < 0) - { - if (errno == EINTR && *InRecovery) - goto retry_accept; - - /* - * "Resource temporarily unavailable" (EAGAIN or EWOULDBLOCK) - * can be silently ignored. And EINTR can be ignored. - */ - if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) - pool_error("accept() failed. reason: %s", strerror(errno)); - return NULL; - } -#ifdef ACCEPT_PERFORMANCE - gettimeofday(&now2,0); - atime += (now2.tv_sec - now1.tv_sec)*1000000 + (now2.tv_usec - now1.tv_usec); - cnt++; - if (cnt % 100 == 0) - { - pool_log("cnt: %d atime: %ld", cnt, atime); - } -#endif - - check_config_reload(); - - connection_count_up(); - accepted = 1; - - if (pool_config->parallel_mode) - { - /* - * do not accept new connection if any of DB node or SystemDB is down when operating in - * parallel mode - */ - int i; - - for (i=0;i<NUM_BACKENDS;i++) - { - if (BACKEND_INFO(i).backend_status == CON_DOWN || SYSDB_STATUS == CON_DOWN) - { - StartupPacket *sp; - char *msg = "pgpool is not available in parallel query mode"; - - if (SYSDB_STATUS == CON_DOWN) - pool_log("Cannot accept() new connection. SystemDB is down"); - else - pool_log("Cannot accept() new connection. %d th backend is down", i); - - if ((cp = pool_open(afd,true)) == NULL) - { - close(afd); - child_exit(1); - } - - sp = read_startup_packet(cp); - if (sp == NULL) - { - /* failed to read the startup packet. return to the accept() loop */ - pool_close(cp); - child_exit(1); - } - - pool_debug("do_accept: send error message to frontend"); - - if (sp->major == PROTO_MAJOR_V3) - { - char buf[256]; - - if (SYSDB_STATUS == CON_DOWN) - snprintf(buf, sizeof(buf), "SystemDB is down"); - else - snprintf(buf, sizeof(buf), "%d th backend is down", i); - - pool_send_error_message(cp, sp->major, "08S01", - msg, - buf, - ((SYSDB_STATUS == CON_DOWN) ? "repair the SystemDB and restart pgpool" - : "repair the backend and restart pgpool"), - __FILE__, - __LINE__); - } - else - { - pool_send_error_message(cp, sp->major, - 0, - msg, - "", - "", - "", - 0); - } - pool_close(cp); - child_exit(1); - } - } - } - else - { - /* - * do not accept new connection if all DB nodes are down when operating in - * non parallel mode - */ - int i; - int found = 0; - - for (i=0;i<NUM_BACKENDS;i++) - { - if (VALID_BACKEND(i)) - { - found = 1; - } - } - - if (found == 0) - { - ereport(FATAL, - (errmsg("Cannot accept() new connection. all backends are down"))); - } - } - - pool_debug("I am %d accept fd %d", getpid(), afd); - - pool_getnameinfo_all(&saddr, remote_host, remote_port); - print_process_status(remote_host,remote_port); - - set_ps_display("accept connection", false); - - /* log who is connecting */ - if (pool_config->log_connections) - { - pool_log("connection received: host=%s%s%s", - remote_host, remote_port[0] ? " port=" : "", remote_port); - } - - /* set NODELAY and KEEPALIVE options if INET connection */ - if (inet) - { - int on = 1; - - if (setsockopt(afd, IPPROTO_TCP, TCP_NODELAY, - (char *) &on, - sizeof(on)) < 0) - { - pool_error("do_accept: setsockopt() failed: %s", strerror(errno)); - close(afd); - return NULL; - } - if (setsockopt(afd, SOL_SOCKET, SO_KEEPALIVE, - (char *) &on, - sizeof(on)) < 0) - { - pool_error("do_accept: setsockopt() failed: %s", strerror(errno)); - close(afd); - return NULL; - } - } - - if ((cp = pool_open(afd,true)) == NULL) - { - close(afd); - return NULL; - } - - /* save ip address for hba */ - memcpy(&cp->raddr, &saddr, sizeof(SockAddr)); - if (cp->raddr.addr.ss_family == 0) - cp->raddr.addr.ss_family = AF_UNIX; - - return cp; -} - -/* -* Read startup packet -* -* Read the startup packet and parse the contents. + * Read startup packet + * + * Read the startup packet and parse the contents. */ static StartupPacket *read_startup_packet(POOL_CONNECTION *cp) { [parent: 5b42a13ef207]