pgpool2.git / summary / log / commit / refs

commit    5bb72e45ce436bab4d104ff2f3edb3fc6aba523d
Author:   Toshihiro Kitagawa <kitagawa at sraoss.co.jp>
Date:     Fri Aug 12 16:27:49 2011 +0000

    Fix pcp_attach_node command so that it emits error message while
    doing failover.


main.c | 8 ++++++++ pcp_child.c | 26 ++++++++++++++++++++++++++ pool.h | 1 + 3 files changed, 35 insertions(+) diff --git a/main.c b/main.c index 2719f89a0..b1164d193 100644 --- 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 diff --git a/pcp_child.c b/pcp_child.c index 44f11adb7..6a3eb3f4c 100644 --- a/pcp_child.c +++ b/pcp_child.c @@ -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 10f6276eb..05201c368 100644 --- 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 */ [parent: 876aa5433ace]