Fix CommandComplete.
authorTatsuo Ishii <[email protected]>
Tue, 28 Feb 2017 01:42:37 +0000 (10:42 +0900)
committerTatsuo Ishii <[email protected]>
Wed, 29 Mar 2017 04:15:55 +0000 (13:15 +0900)
It still used sync map, now which is obsoleted. This gives strange
errors upon receiving command complete message.

Fix do_query(). It did not popd up saved messages in certain cases. I
guess this was one of the cause of occasional regression failures.

src/protocol/CommandComplete.c
src/protocol/pool_process_query.c

index c7543a7802c6d8493b5b6233e494387bd23afca2..d05033653390a744e83dbb4bfc1ee2e0b65fdcfd 100644 (file)
@@ -47,9 +47,9 @@ POOL_STATUS CommandComplete(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *bac
 {
        int len, len1;
        char *p, *p1;
+       int i;
        POOL_SESSION_CONTEXT *session_context;
        POOL_CONNECTION *con;
-       int slot_id;
 
        /* Get session context */
        session_context = pool_get_session_context(false);
@@ -61,60 +61,51 @@ POOL_STATUS CommandComplete(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *bac
                handle_query_context(backend);
 
        /*
-        * Read backend data from the first valid node using sync map if operated
-        * in streaming replication mode with extended protocol.
+        * If operated in streaming replication mode and doing an extended query,
+        * read backend message according to the query context.
         */
-       if      (STREAM && pool_is_doing_extended_query_message())
+       if (STREAM && pool_is_doing_extended_query_message())
        {
-               slot_id =  pool_get_nth_sync_map(0);
-               if (slot_id < 0)
-                       return POOL_END;        /* this should not happen */
+               for (i=0;i<NUM_BACKENDS;i++)
+               {
+                       if (VALID_BACKEND(i))
+                       {
+                               con = CONNECTION(backend, i);
+
+                               if (pool_read(con, &len, sizeof(len)) < 0)
+                                       return POOL_END;
+
+                               len = ntohl(len);
+                               len -= 4;
+                               len1 = len;
 
-               con = backend->slots[slot_id]->con;
+                               p = pool_read2(con, len);
+                               if (p == NULL)
+                                       return POOL_END;
+                               p1 = palloc(len);
+                               memcpy(p1, p, len);
+                       }
+               }
        }
        /*
-        * Oterwise read from "MASTER" node.
+        * Otherwise just read from master node.
         */
        else
        {
                con = MASTER(backend);
-       }
-
-       if (pool_read(con, &len, sizeof(len)) < 0)
-               return POOL_END;
-
-       len = ntohl(len);
-       len -= 4;
-       len1 = len;
-
-       p = pool_read2(con, len);
-       if (p == NULL)
-               return POOL_END;
-       p1 = palloc(len);
-       memcpy(p1, p, len);
 
-       /*
-        * If operated in streaming replication mode and extended query mode, we
-        * may need to read data from other node if any (SET or transaction
-        * statements).
-        */
-       if      (STREAM && pool_is_doing_extended_query_message())
-       {
-               slot_id =  pool_get_nth_sync_map(1);
-               if (slot_id >= 0)
-               {
-                       con = backend->slots[slot_id]->con;
+               if (pool_read(con, &len, sizeof(len)) < 0)
+                       return POOL_END;
 
-                       if (pool_read(con, &len, sizeof(len)) < 0)
-                               return POOL_END;
+               len = ntohl(len);
+               len -= 4;
+               len1 = len;
 
-                       len = ntohl(len);
-                       len -= 4;
-
-                       p = pool_read2(con, len);
-                       if (p == NULL)
-                               return POOL_END;
-               }
+               p = pool_read2(con, len);
+               if (p == NULL)
+                       return POOL_END;
+               p1 = palloc(len);
+               memcpy(p1, p, len);
        }
 
        /*
index aac4a672c7d4da15f9ff54e85738550602eb2c17..2191bb64044611e5cc4b895c476e1cf68c3cbfbb 100644 (file)
@@ -2438,19 +2438,18 @@ void do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT **result
                {
                        ereport(DEBUG1,
                                        (errmsg("do_query: all state completed. returning")));
-
-                       if (data_pushed)
-                       {
-                               int poplen;
-
-                               pool_pop(backend, &poplen);
-                               ereport(DEBUG1,
-                                               (errmsg("do_query: popped data len:%d", poplen)));
-                       }
-
                        break;
                }
        }
+
+       if (data_pushed)
+       {
+               int poplen;
+
+               pool_pop(backend, &poplen);
+               ereport(DEBUG1,
+                               (errmsg("do_query: popped data len:%d", poplen)));
+       }
 }
 
 /*