Fix do_command so that it doesn't call pool_read function after it detects
authorToshihiro Kitagawa <kitagawa at sraoss.co.jp>
Fri, 20 Aug 2010 02:04:28 +0000 (02:04 +0000)
committerToshihiro Kitagawa <kitagawa at sraoss.co.jp>
Fri, 20 Aug 2010 02:04:28 +0000 (02:04 +0000)
PANIC or FATAL error.
Change is_panic_or_fatal_error so that it supports V2 protocol.

pool_process_query.c

index 2514f98225c1625c4f65ca8f173b3c6142641104..734f7a803f63d3b53b340b4833ef8ea9d2d4e062 100644 (file)
@@ -69,7 +69,7 @@ static int is_cache_empty(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backe
 static POOL_STATUS ParallelForwardToFrontend(char kind, POOL_CONNECTION *frontend, POOL_CONNECTION *backend, char *database, bool send_to_frontend);
 static void query_cache_register(char kind, POOL_CONNECTION *frontend, char *database, char *data, int data_len);
 static int extract_ntuples(char *message);
-static bool is_panic_or_fatal_error(const char *message);
+static bool is_panic_or_fatal_error(const char *message, int major);
 static int detect_error(POOL_CONNECTION *master, char *error_code, int major, char class, bool unread);
 static int detect_postmaster_down_error(POOL_CONNECTION *master, int major);
 
@@ -1301,7 +1301,7 @@ POOL_STATUS SimpleForwardToFrontend(char kind, POOL_CONNECTION *frontend,
                 * the message and exit since the backend will close the
                 * channel immediately.
                 */
-               if (is_panic_or_fatal_error(p))
+               if (is_panic_or_fatal_error(p, MAJOR(backend)))
                {
                        pool_flush(frontend);
                        return POOL_END;
@@ -1971,6 +1971,15 @@ POOL_STATUS do_command(POOL_CONNECTION *frontend, POOL_CONNECTION *backend,
                                        backend->tstate = 'I';
                        }
                }
+
+               if(kind == 'E')
+               {
+                       if (is_panic_or_fatal_error(string, protoMajor))
+                       {
+                               pool_error("do_command: %s", string);
+                               return POOL_END;
+                       }
+               }
        }
 
 /*
@@ -3835,27 +3844,34 @@ static int extract_ntuples(char *message)
 
 /*
  * Returns true if error message contains PANIC or FATAL.
- * This function works for V3 only.
  */
-static bool is_panic_or_fatal_error(const char *message)
+static bool is_panic_or_fatal_error(const char *message, int major)
 {
-       for (;;)
+       if (major == PROTO_MAJOR_V3)
        {
-               char id;
+               for (;;)
+               {
+                       char id;
 
-               id = *message++;
-               if (id == '\0')
-                       break;
+                       id = *message++;
+                       if (id == '\0')
+                               break;
 
-               if (id == 'S' && (strcasecmp("PANIC", message) == 0 || strcasecmp("FATAL", message) == 0))
-                       return true;
-               else
-               {
-                       while (*message++)
-                               ;
-                       continue;
+                       if (id == 'S' && (strcasecmp("PANIC", message) == 0 || strcasecmp("FATAL", message) == 0))
+                               return true;
+                       else
+                       {
+                               while (*message++)
+                                       ;
+                               continue;
+                       }
                }
        }
+       else
+       {
+               if (strncmp(message, "PANIC", 5) == 0 || strncmp(message, "FATAL", 5) == 0)
+                       return true;
+       }
        return false;
 }