pgpool2.git / summary / log / commit / refs

commit    7cfa04b59fba9ee481c22dbd187b89ab355fd518
Author:   Tatsuo Ishii <ishii at sraoss.co.jp>
Date:     Fri Jul 23 09:40:19 2010 +0000

    Allow to online recovery standby node in streaming replication
    mode. Primary node is not allowed, however.


pcp_child.c | 22 +++++++++++++++++---- recovery.c | 66 +++++++++++++++++++++++++++++++++---------------------------- 2 files changed, 54 insertions(+), 34 deletions(-) diff --git a/pcp_child.c b/pcp_child.c index 508931e5f..97b90bd4a 100644 --- a/pcp_child.c +++ b/pcp_child.c @@ -744,18 +744,32 @@ pcp_do_child(int unix_fd, int inet_fd, char *pcp_conf_file) char code[] = "CommandComplete"; int r; - if (!REPLICATION) + node_id = atoi(buf); + + if ((!REPLICATION && + !(MASTER_SLAVE && + !strcmp(pool_config->master_slave_sub_mode, MODE_STREAMREP))) || + (MASTER_SLAVE && + !strcmp(pool_config->master_slave_sub_mode, MODE_STREAMREP) && + node_id == REAL_MASTER_NODE_ID)) { - int len = strlen("recovery request is accepted only in replication mode. ") + 1; + int len; + char *msg; + + if (MASTER_SLAVE && !strcmp(pool_config->master_slave_sub_mode, MODE_STREAMREP)) + msg = "primary server cannot be recovered by online recovery."; + else + msg = "recovery request is accepted only in replication mode or stereaming replication mode. "; + + len = strlen(msg)+1; pcp_write(frontend, "e", 1); wsize = htonl(sizeof(int) + len); pcp_write(frontend, &wsize, sizeof(int)); - pcp_write(frontend, "recovery request is accepted only in replication mode. ", len); + pcp_write(frontend, msg, len); } else { pool_debug("pcp_child: start online recovery"); - node_id = atoi(buf); r = start_recovery(node_id); finish_recovery(); diff --git a/recovery.c b/recovery.c index d395d5d79..f5af4920d 100644 --- a/recovery.c +++ b/recovery.c @@ -76,15 +76,17 @@ int start_recovery(int recovery_node) } /* 1st stage */ - if (exec_checkpoint(conn) != 0) + if (REPLICATION) { - PQfinish(conn); - pool_error("start_recovery: CHECKPOINT failed"); - return 1; + if (exec_checkpoint(conn) != 0) + { + PQfinish(conn); + pool_error("start_recovery: CHECKPOINT failed"); + return 1; + } + pool_log("CHECKPOINT in the 1st stage done"); } - pool_log("CHECKPOINT in the 1st stage done"); - if (exec_recovery(conn, recovery_backend, FIRST_STAGE) != 0) { PQfinish(conn); @@ -93,33 +95,37 @@ int start_recovery(int recovery_node) pool_log("1st stage is done"); - pool_log("starting 2nd stage"); - - /* 2nd stage */ - *InRecovery = 1; - if (wait_connection_closed() != 0) + if (REPLICATION) { - PQfinish(conn); - pool_error("start_recovery: timeover for waiting connection closed"); - return 1; + pool_log("starting 2nd stage"); + + /* 2nd stage */ + *InRecovery = 1; + if (wait_connection_closed() != 0) + { + PQfinish(conn); + pool_error("start_recovery: timeover for waiting connection closed"); + return 1; + } + + pool_log("all connections from clients have been closed"); + + if (exec_checkpoint(conn) != 0) + { + PQfinish(conn); + pool_error("start_recovery: CHECKPOINT failed"); + return 1; + } + + pool_log("CHECKPOINT in the 2nd stage done"); + + if (exec_recovery(conn, recovery_backend, SECOND_STAGE) != 0) + { + PQfinish(conn); + return 1; + } } - pool_log("all connections from clients have been closed"); - - if (exec_checkpoint(conn) != 0) - { - PQfinish(conn); - pool_error("start_recovery: CHECKPOINT failed"); - return 1; - } - - pool_log("CHECKPOINT in the 2nd stage done"); - - if (exec_recovery(conn, recovery_backend, SECOND_STAGE) != 0) - { - PQfinish(conn); - return 1; - } if (exec_remote_start(conn, recovery_backend) != 0) { PQfinish(conn); [parent: f785e3eb2420]