/* * Discard connection and memory allocated by * make_persistent_db_connection(). */ void discard_persistent_db_connection(POOL_CONNECTION_POOL_SLOT *cp) { int len; if(cp == NULL) return; pool_write(cp->con, "X", 1); len = htonl(4); pool_write(cp->con, &len, sizeof(len)); /* * XXX we cannot call pool_flush() here since backend may already * close the socket and pool_flush() automatically invokes fail * over handler. This could happen in copy command (remember the * famous "lost synchronization with server, resetting * connection" message) */ pool_set_nonblock(cp->con->fd); pool_flush_it(cp->con); pool_unset_nonblock(cp->con->fd); pool_close(cp->con); free(cp->sp->startup_packet); free(cp->sp->database); free(cp->sp->user); free(cp->sp); free(cp); }
/* * flush write buffer and degenerate/failover if error occurs */ int pool_flush(POOL_CONNECTION *cp) { if (pool_flush_it(cp) == -1) { if (cp->isbackend) { /* if fail_over_on_backend_erro is true, then trigger failover */ if (pool_config->fail_over_on_backend_error) { notice_backend_error(cp->db_node_id); child_exit(1); } else return -1; } else { /* * ignore error on frontend. we need to continue the * processing with backends */ return 0; } } return 0; }
/* * flush write buffer and degenerate/failover if error occurs */ int pool_flush(POOL_CONNECTION *cp) { if (pool_flush_it(cp) == -1) { if (cp->isbackend) { /* if fail_over_on_backend_erro is true, then trigger failover */ if (pool_config->fail_over_on_backend_error) { notice_backend_error(cp->db_node_id); child_exit(1); } else return -1; } else { /* * If we are in replication mode, we need to continue the * processing with backends to keep consistency among * backends, thus ignore error. */ if (REPLICATION) return 0; else return -1; } } return 0; }
/* * write len bytes to cp the write buffer. * returns 0 on success otherwise -1. */ int pool_write(POOL_CONNECTION *cp, void *buf, int len) { if (len < 0) { pool_error("pool_write: invalid request size: %d", len); return -1; } if (cp->no_forward) return 0; while (len > 0) { int remainder = WRITEBUFSZ - cp->wbufpo; if (cp->wbufpo >= WRITEBUFSZ) { /* * Write buffer is full. so flush buffer. * wbufpo is reset in pool_flush_it(). */ if (pool_flush_it(cp) == -1) return -1; remainder = WRITEBUFSZ; } /* check buffer size */ if (remainder >= len) { /* OK, buffer size is enough. */ remainder = len; } memcpy(cp->wbuf+cp->wbufpo, buf, remainder); cp->wbufpo += remainder; buf += remainder; len -= remainder; } return 0; }