Fix master/slave mode breakage in 2.7.2
authorTatsuo Ishii <ishii at sraoss.co.jp>
Tue, 14 Feb 2006 08:19:06 +0000 (08:19 +0000)
committerTatsuo Ishii <ishii at sraoss.co.jp>
Tue, 14 Feb 2006 08:19:06 +0000 (08:19 +0000)
Fix bug with master/slave mode and prepared query

child.c
pool.h
pool_process_query.c

diff --git a/child.c b/child.c
index 036ee96f84ec514c0d8ee5adc67817ce252bfe44..640d292b0b54be0cfcb063f09468286723e7e798 100644 (file)
--- a/child.c
+++ b/child.c
@@ -81,7 +81,7 @@ void do_child(int unix_fd, int inet_fd)
        struct timeval timeout;
        static int connected;
        int connections_count = 0;      /* used if child_max_connections > 0 */
-
+       int first_ready_for_query_received;             /* for master/slave mode */
 
        pool_debug("I am %d", getpid());
 
@@ -217,6 +217,8 @@ void do_child(int unix_fd, int inet_fd)
                 * we need to connect to the backend and send the startup packet.
                 */
 
+               first_ready_for_query_received = 0;             /* for master/slave mode */
+
                /* look for existing connection */
                if ((backend = pool_get_cp(sp->user, sp->database, sp->major)) == NULL)
                {
@@ -225,7 +227,15 @@ void do_child(int unix_fd, int inet_fd)
 
                        if ((backend = connect_backend(sp, frontend)) == NULL)
                                continue;
+
+                       /* in master/slave mode, the first "ready for query"
+                        * packet should be treated as if we were not in the
+                        * mode
+                        */
+                       if (MASTER_SLAVE)
+                               first_ready_for_query_received = 1;
                }
+
                else
                {
                        /* we don't need Startup Packet info anymore */
@@ -281,7 +291,7 @@ void do_child(int unix_fd, int inet_fd)
                {
                        POOL_STATUS status;
 
-                       status = pool_process_query(frontend, backend, 0);
+                       status = pool_process_query(frontend, backend, 0, first_ready_for_query_received);
 
                        sp = MASTER_CONNECTION(backend)->sp;
 
@@ -308,7 +318,7 @@ void do_child(int unix_fd, int inet_fd)
                                                POOL_STATUS status1;
 
                                                /* send reset request to backend */
-                                               status1 = pool_process_query(frontend, backend, 1);
+                                               status1 = pool_process_query(frontend, backend, 1, 0);
                                                pool_close(frontend);
 
                                                /* if we detect errors on resetting connection, we need to discard
diff --git a/pool.h b/pool.h
index d9985548d878d71335b0b6a8a5a83b3ed5184052..5304653e82bc7ed069d68e9433e5985414e68cf1 100644 (file)
--- a/pool.h
+++ b/pool.h
@@ -266,7 +266,8 @@ extern void do_child(int unix_fd, int inet_fd);
 extern int pool_init_cp(void);
 extern POOL_STATUS pool_process_query(POOL_CONNECTION *frontend,
                                                                          POOL_CONNECTION_POOL *backend,
-                                                                         int connection_reuse);
+                                                                         int connection_reuse,
+                                                                         int first_ready_for_query_received);
 
 extern POOL_CONNECTION *pool_open(int fd);
 extern void pool_close(POOL_CONNECTION *cp);
index 180e70e2f3ef393b7c019178df38c544e6075382..ce240bea06fa2cd530ee42a84489fcc3bf33a9a4 100644 (file)
@@ -119,7 +119,8 @@ static int is_drop_database(char *query);           /* returns non 0 if this is a DROP DA
 
 POOL_STATUS pool_process_query(POOL_CONNECTION *frontend, 
                                                           POOL_CONNECTION_POOL *backend,
-                                                          int connection_reuse)
+                                                          int connection_reuse,
+                                                          int first_ready_for_query_received)
 {
        char kind, kind1;       /* packet kind (backend) */
        char fkind;     /* packet kind (frontend) */
@@ -315,7 +316,7 @@ POOL_STATUS pool_process_query(POOL_CONNECTION *frontend,
                }
 
                /* this is the synchronous point */
-               if (REPLICATION)
+               if (REPLICATION || first_ready_for_query_received)
                {
                        if (kind == 0)
                        {
@@ -349,6 +350,8 @@ POOL_STATUS pool_process_query(POOL_CONNECTION *frontend,
                                }
                        }
 
+                       first_ready_for_query_received = 0;
+
                        if (kind == '\0' || kind != kind1)
                        {
                                int sts;
@@ -1660,6 +1663,13 @@ static POOL_STATUS ProcessFrontendResponse(POOL_CONNECTION *frontend,
                default:
                        if (MAJOR(backend) == PROTO_MAJOR_V3)
                        {
+                               if (MASTER_SLAVE)
+                               {
+                                       master_slave_was_enabled = 1;
+                                       MASTER_SLAVE = 0;
+                                       master_slave_dml = 1;
+                               }
+
                                status = SimpleForwardToBackend(fkind, frontend, backend);
                                if (pool_flush(MASTER(backend)))
                                        status = POOL_ERROR;