Fix pcp_attach_node command so that it emits error message while
authorToshihiro Kitagawa <kitagawa at sraoss.co.jp>
Fri, 12 Aug 2011 16:27:49 +0000 (16:27 +0000)
committerToshihiro Kitagawa <kitagawa at sraoss.co.jp>
Fri, 12 Aug 2011 16:27:49 +0000 (16:27 +0000)
doing failover.

main.c
pcp_child.c
pool.h

diff --git a/main.c b/main.c
index 2719f89a0740c53c9ed85ed5ab5197b1f00fa1d4..b1164d1936536fd445599f9723efb748e517550b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -520,6 +520,7 @@ int main(int argc, char **argv)
        memset(Req_info->node_id, -1, sizeof(int) * MAX_NUM_BACKENDS);
        Req_info->master_node_id = get_next_master_node();
        Req_info->conn_counter = 0;
+       Req_info->switching = false;
 
        InRecovery = pool_shared_memory_create(sizeof(int));
        if (InRecovery == NULL)
@@ -1524,6 +1525,7 @@ static void failover(void)
         */
        pool_debug("failover_handler: starting to select new master node");
        switching = 1;
+       Req_info->switching = true;
        node_id = Req_info->node_id[0];
 
        /* failback request? */
@@ -1539,6 +1541,7 @@ static void failover(void)
                                           BACKEND_INFO(node_id).backend_status, MAX_NUM_BACKENDS);
                        kill(pcp_pid, SIGUSR2);
                        switching = 0;
+                       Req_info->switching = false;
                        return;
                }
 
@@ -1563,6 +1566,7 @@ static void failover(void)
                        pool_semaphore_unlock(REQUEST_INFO_SEM);
                        kill(pcp_pid, SIGUSR2);
                        switching = 0;
+                       Req_info->switching = false;
                        return;
                }
        }
@@ -1593,6 +1597,7 @@ static void failover(void)
                        pool_semaphore_unlock(REQUEST_INFO_SEM);
                        kill(pcp_pid, SIGUSR2);
                        switching = 0;
+                       Req_info->switching = false;
                        return;
                }
        }
@@ -1644,8 +1649,10 @@ static void failover(void)
 
                        pool_semaphore_unlock(REQUEST_INFO_SEM);
                        switching = 0;
+                       Req_info->switching = false;
                        kill(pcp_pid, SIGUSR2);
                        switching = 0;
+                       Req_info->switching = false;
                        return;
                }
        }
@@ -1813,6 +1820,7 @@ static void failover(void)
        }
 
        switching = 0;
+       Req_info->switching = false;
 
        /* kick wakeup_handler in pcp_child to notice that
         * failover/failback done
index 44f11adb7e7bd6b6ab507093bb81a15b5d46a40f..6a3eb3f4c642ec7f6c11c33db8b6c5ac43ecee37 100644 (file)
@@ -198,6 +198,32 @@ pcp_do_child(int unix_fd, int inet_fd, char *pcp_conf_file)
 
                set_ps_display("PCP: processing a request", false);
 
+               if (tos == 'C' || tos == 'd' || tos == 'D' || tos == 'j' ||
+                       tos == 'J' || tos == 'O' || tos == 'T')
+               {
+                       if (Req_info->switching)
+                       {
+                               int len;
+                               int wsize;
+                               char *msg;
+
+                               if (Req_info->kind == NODE_UP_REQUEST)
+                                       msg = "FailbackInProgress";
+                               else if (Req_info->kind == NODE_DOWN_REQUEST)
+                                       msg = "FailoverInProgress";
+                               else if (Req_info->kind == PROMOTE_NODE_REQUEST)
+                                       msg = "PromotionInProgress";
+                               else
+                                       msg = "OperationInProgress";
+
+                               len = strlen(msg) + 1;
+                               pcp_write(frontend, "e", 1);
+                               wsize = htonl(sizeof(int) + len);
+                               pcp_write(frontend, &wsize, sizeof(int));
+                               pcp_write(frontend, msg, len);
+                       }
+               }
+
                switch (tos)
                {
                        case 'R':                       /* authentication */
diff --git a/pool.h b/pool.h
index 10f6276ebac71a2312f444acdd43434f79ec92f3..05201c368000e1363c954c2cfc7965e622283ae9 100644 (file)
--- a/pool.h
+++ b/pool.h
@@ -360,6 +360,7 @@ typedef struct {
        int master_node_id;     /* the youngest node id which is not in down status */
        int primary_node_id;    /* the primary node id in streaming replication mode */
        int conn_counter;
+       bool switching; /* it true, failover or failback is in progress */
 } POOL_REQUEST_INFO;
 
 /* description of row. corresponding to RowDescription message */