pgpool2.git / summary / log / commit / refs

commit    726cb5d3b18cc669c1eb63dcbce39a161a08b8f8
Author:   Tatsuo Ishii <ishii@postgresql.org>
Date:     Tue Jul 12 02:35:39 2016 +0000

    Do not update status file if all backend nodes are in down status.
    
    pgpool_status will always reflect the last set of nodes to which any
    data was written.  Upon restart, if the up-to-date (previously "up")
    node is in fact down (regardless of whether the stale ("down") node is
    back up), pgpool will detect this in its health check and will fail;
    if the up-to-date (previously "up") node is back up, then pgpool will
    commence using it.  See [pgpool-general: 4721] for more discussion.
    
    Also fix incorrect pool_config global variable checking. Before it was
    checked *after* pool_config was used.


src/main/pgpool_main.c | 122 ++++++++++++++++++++++++++++++------------------- 1 file changed, 75 insertions(+), 47 deletions(-) diff --git a/src/main/pgpool_main.c b/src/main/pgpool_main.c index eb454d45f..59ae420db 100644 --- a/src/main/pgpool_main.c +++ b/src/main/pgpool_main.c @@ -3165,8 +3165,41 @@ int write_status_file() FILE *fd; int fdnum; char fnamebuf[POOLMAXPATHLEN]; + char buf[10]; int i; + if (!pool_config) + { + ereport(WARNING, + (errmsg("pool_config is not set"))); + return 0; + } + + /* Check to see if all nodes are down status. + * If so, skip writing status file. + * So pgpool_status will + * always reflect the last set of nodes to which any data was written. + * Upon restart, if the up-to-date (previously "up") node is in fact down + * (regardless of whether the stale ("down") node is back up), pgpool + * will detect this in its health check and will fail; if the up-to-date + * (previously "up") node is back up, then pgpool will commence using it. + * + * See [pgpool-general: 4721] for more discussion. + */ + for (i=0;i< pool_config->backend_desc->num_backends;i++) + { + if (BACKEND_INFO(i).backend_status != CON_DOWN) + break; + } + + if (i && i == pool_config->backend_desc->num_backends) + { + ereport(WARNING, + (errmsg("All the DB nodes are in down status and skip writing status file."))); + + return 0; + } + snprintf(fnamebuf, sizeof(fnamebuf), "%s/%s", pool_config->logdir, STATUS_FILE_NAME); fd = fopen(fnamebuf, "w"); if (!fd) @@ -3177,65 +3210,60 @@ int write_status_file() return -1; } - if(pool_config) - { - char buf[10]; - - for (i=0;i< pool_config->backend_desc->num_backends;i++) - { - char* status; + for (i=0;i< pool_config->backend_desc->num_backends;i++) + { + char* status; - if (BACKEND_INFO(i).backend_status == CON_UP || - BACKEND_INFO(i).backend_status == CON_CONNECT_WAIT) - status = "up"; - else if (BACKEND_INFO(i).backend_status == CON_DOWN) - status = "down"; - else - status = "unused"; + if (BACKEND_INFO(i).backend_status == CON_UP || + BACKEND_INFO(i).backend_status == CON_CONNECT_WAIT) + status = "up"; + else if (BACKEND_INFO(i).backend_status == CON_DOWN) + status = "down"; + else + status = "unused"; - sprintf(buf, "%s\n", status); - if (fwrite(buf, 1, strlen(buf), fd) != strlen(buf)) - { - ereport(WARNING, + sprintf(buf, "%s\n", status); + if (fwrite(buf, 1, strlen(buf), fd) != strlen(buf)) + { + ereport(WARNING, (errmsg("failed to write status file at: \"%s\"",fnamebuf), - errdetail("\"%s\"",strerror(errno)))); - fclose(fd); - return -1; - } + errdetail("\"%s\"",strerror(errno)))); + fclose(fd); + return -1; } + } - if (fflush(fd) != 0) - { - ereport(WARNING, + if (fflush(fd) != 0) + { + ereport(WARNING, (errmsg("failed to write status file at: \"%s\"",fnamebuf), - errdetail("\"%s\"",strerror(errno)))); - fclose(fd); - return -1; - } - fdnum = fileno(fd); - if (fdnum < 0) - { - ereport(WARNING, + errdetail("\"%s\"",strerror(errno)))); + fclose(fd); + return -1; + } + fdnum = fileno(fd); + if (fdnum < 0) + { + ereport(WARNING, (errmsg("failed to get file number. fsync() will not be performed: \"%s\"",fnamebuf), - errdetail("\"%s\"",strerror(errno)))); - fclose(fd); - return -1; - } - if (fsync(fdnum) != 0) - { - ereport(WARNING, + errdetail("\"%s\"",strerror(errno)))); + fclose(fd); + return -1; + } + if (fsync(fdnum) != 0) + { + ereport(WARNING, (errmsg("failed to fsync(): \"%s\"",fnamebuf), - errdetail("\"%s\"",strerror(errno)))); - fclose(fd); - return -1; - } + errdetail("\"%s\"",strerror(errno)))); + fclose(fd); + return -1; + } + + fclose(fd); - fclose(fd); - } return 0; } - static void reload_config(void) { ereport(LOG, [parent: e245587de0dd]