pgpool2.git / summary / log / commit / refs

commit    6ca2a3b7f7cd21565f2680b0fb55873ca01d4619
Author:   Tatsuo Ishii <ishii@postgresql.org>
Date:     Sun Mar 04 02:19:55 2012 +0000

    Add "role" which represents "primary" or "standby" iin streaming
    replication mode for example to "show pool_nodes" command.


doc/pgpool-en.html | 14 +++++++------- doc/pgpool-ja.html | 12 ++++++------ pcp/libpcp_ext.h | 3 ++- pool_process_reporting.c | 35 +++++++++++++++++++++++++++++------ 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/doc/pgpool-en.html b/doc/pgpool-en.html index 99cdb1f13..338066d42 100644 --- a/doc/pgpool-en.html +++ b/doc/pgpool-en.html @@ -7,7 +7,7 @@ </head> <!-- hhmts start --> -Last modified: Sun Feb 19 20:58:54 JST 2012 +Last modified: Sun Mar 4 11:18:24 JST 2012 <!-- hhmts end --> <body bgcolor="#ffffff"> @@ -2526,15 +2526,15 @@ benchs2=# show pool_status; </p> <h2>pool_nodes</h2> <p>"SHOW pool_nodes" sends back a list of all configured nodes. It -displays the node id, the hostname, the port, the status, and the weight (only meaningful -if you use the load balancing mode). The possible values in the status column +displays the node id, the hostname, the port, the status, the weight (only meaningful +if you use the load balancing mode) and the role. The possible values in the status column are explained in the <a href="#pcp_node_info">pcp_node_info reference</a>. <pre> benchs2=# show pool_nodes; - id | hostname | port | status | lb_weight -------+-------------+------+--------+----------- - 0 | 127.0.0.1 | 5432 | 2 | 0.5 - 1 | 192.168.1.7 | 5432 | 3 | 0.5 + id | hostname | port | status | lb_weight | role +------+-------------+------+--------+-----------+--------- + 0 | 127.0.0.1 | 5432 | 2 | 0.5 | primary + 1 | 192.168.1.7 | 5432 | 3 | 0.5 | standby (2 lignes) </pre> </p> diff --git a/doc/pgpool-ja.html b/doc/pgpool-ja.html index 79f35efcb..72c1db27a 100644 --- a/doc/pgpool-ja.html +++ b/doc/pgpool-ja.html @@ -8,7 +8,7 @@ <body> <!-- hhmts start --> -Last modified: Mon Feb 20 07:53:48 JST 2012 +Last modified: Sun Mar 4 11:19:30 JST 2012 <!-- hhmts end --> <body bgcolor="#ffffff"> @@ -2437,14 +2437,14 @@ benchs2=# show pool_status; </p> <h2>pool_nodes</h2> <p>"SHOW pool_nodes"$B$O!"(BDB$B%N!<%I$N%j%9%H$rI=<($7$^$9!#(B -$B%[%9%HL>!"%]!<%HHV9f!">uBV!"=E$_(B($B%m!<%I%P%i%s%9%b!<%I$G1?MQ$7$F$$$k$H$-$K$N$_0UL#$,$"$j$^$9(B)$B$,I=<($5$l$^$9!#(B +$B%[%9%HL>!"%]!<%HHV9f!">uBV!"=E$_(B($B%m!<%I%P%i%s%9%b!<%I$G1?MQ$7$F$$$k$H$-$K$N$_0UL#$,$"$j$^$9(B)$B!"%N!<%I$NLr3d$,I=<($5$l$^$9!#(B $B>uBV(B(status)$B$N0UL#$K$D$$$F$O!"(B<a href="#pcp_node_info">pcp_node_info$B%j%U%!%l%s%9(B</a>$B$G@bL@$5$l$F$$$^$9!#(B <pre> benchs2=# show pool_nodes; - id | hostname | port | status | lb_weight -------+-------------+------+--------+----------- - 0 | 127.0.0.1 | 5432 | 2 | 0.5 - 1 | 192.168.1.7 | 5432 | 3 | 0.5 + id | hostname | port | status | lb_weight | role +------+-------------+------+--------+-----------+--------- + 0 | 127.0.0.1 | 5432 | 2 | 0.5 | primary + 1 | 192.168.1.7 | 5432 | 3 | 0.5 | standby (2 lignes) </pre> </p> diff --git a/pcp/libpcp_ext.h b/pcp/libpcp_ext.h index 4c79bebd5..84fca6156 100644 --- a/pcp/libpcp_ext.h +++ b/pcp/libpcp_ext.h @@ -179,11 +179,12 @@ typedef struct { /* nodes report struct */ typedef struct { - char node_id[POOLCONFIG_MAXSTATLEN+1]; + char node_id[POOLCONFIG_MAXSTATLEN+1]; char hostname[POOLCONFIG_MAXIDENTLEN+1]; char port[POOLCONFIG_MAXIDENTLEN+1]; char status[POOLCONFIG_MAXSTATLEN+1]; char lb_weight[POOLCONFIG_MAXWEIGHTLEN+1]; + char role[POOLCONFIG_MAXWEIGHTLEN+1]; } POOL_REPORT_NODES; /* processes report struct */ diff --git a/pool_process_reporting.c b/pool_process_reporting.c index 3d9ec356e..08f616d0d 100644 --- a/pool_process_reporting.c +++ b/pool_process_reporting.c @@ -5,7 +5,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2011 PgPool Global Development Group + * Copyright (c) 2003-2012 PgPool Global Development Group * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -760,22 +760,35 @@ POOL_REPORT_NODES* get_nodes(int *nrows) { bi = pool_get_node_info(i); - snprintf(nodes[i].node_id, POOLCONFIG_MAXSTATLEN, "%d", i); + snprintf(nodes[i].node_id, POOLCONFIG_MAXSTATLEN, "%d", i); strncpy(nodes[i].hostname, bi->backend_hostname, strlen(bi->backend_hostname)+1); snprintf(nodes[i].port, POOLCONFIG_MAXIDENTLEN, "%d", bi->backend_port); snprintf(nodes[i].status, POOLCONFIG_MAXSTATLEN, "%d", bi->backend_status); snprintf(nodes[i].lb_weight, POOLCONFIG_MAXWEIGHTLEN, "%f", bi->backend_weight/RAND_MAX); + + if (MASTER_SLAVE && !strcmp(pool_config->master_slave_sub_mode, MODE_STREAMREP)) + if (i == REAL_PRIMARY_NODE_ID) + snprintf(nodes[i].role, POOLCONFIG_MAXWEIGHTLEN, "%s", "primary"); + else + snprintf(nodes[i].role, POOLCONFIG_MAXWEIGHTLEN, "%s", "standby"); + else + { + if (i == REAL_MASTER_NODE_ID) + snprintf(nodes[i].role, POOLCONFIG_MAXWEIGHTLEN, "%s", "master"); + else + snprintf(nodes[i].role, POOLCONFIG_MAXWEIGHTLEN, "%s", "slave"); + } } *nrows = i; return nodes; - } +} void nodes_reporting(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend) - { - static short num_fields = 5; - static char *field_names[] = {"node_id","hostname", "port", "status", "lb_weight"}; +{ + static char *field_names[] = {"node_id","hostname", "port", "status", "lb_weight", "role"}; + short num_fields = sizeof(field_names)/sizeof(char *); int i; short s; int len; @@ -821,6 +834,11 @@ void nodes_reporting(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend) hsize = htonl(size+4); pool_write(frontend, &hsize, sizeof(hsize)); pool_write(frontend, nodes[i].lb_weight, size); + + size = strlen(nodes[i].role); + hsize = htonl(size+4); + pool_write(frontend, &hsize, sizeof(hsize)); + pool_write(frontend, nodes[i].role, size); } } else @@ -835,6 +853,7 @@ void nodes_reporting(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend) len += 4 + strlen(nodes[i].port); /* int32 + data; */ len += 4 + strlen(nodes[i].status); /* int32 + data; */ len += 4 + strlen(nodes[i].lb_weight); /* int32 + data; */ + len += 4 + strlen(nodes[i].role); /* int32 + data; */ len = htonl(len); pool_write(frontend, &len, sizeof(len)); s = htons(num_fields); @@ -859,6 +878,10 @@ void nodes_reporting(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend) len = htonl(strlen(nodes[i].lb_weight)); pool_write(frontend, &len, sizeof(len)); pool_write(frontend, nodes[i].lb_weight, strlen(nodes[i].lb_weight)); + + len = htonl(strlen(nodes[i].role)); + pool_write(frontend, &len, sizeof(len)); + pool_write(frontend, nodes[i].role, strlen(nodes[i].role)); } } [parent: 40719d076ddf]