[pgpool-hackers: 1732] Re: Feature Request with Patch
Muhammad Usama
m.usama at gmail.com
Thu Jul 28 00:48:31 JST 2016
Hi
I have modified the patch a little and also included the changes for "show
pool_nodes", "show pool_status" and English documentation.
More specifically the changes from the original version are. First, Since
this is a new feature that will only go out in next pgpool-II major release
so instead of adding a command line argument in the pcp_node_info for
displaying the human readable status string, I have included it in the
standard output of the utility and updated the documentation accordingly.
Second, As the pgpool admin extension already shows the human readable node
status so I don't think we need to touch that.
Suggestions and comments.
Best regards
Muhammad Usama
On Tue, May 10, 2016 at 8:26 AM, Tatsuo Ishii <ishii at postgresql.org> wrote:
> You can either 1) concentrate on working on pcp_node_info and leave
> the rest of work (i.e. show pool_nodes) to someone else, or 2) take
> care of all the commands including pcp_node_info and show pool_nodes.
>
> Either is fine for me. The choice is up to you.
>
> BTW, your coding style is a little bit different from ours. We
> strictly follow the PostgreSQL style. For example,
>
> if (....) {
> ....
> } else {
> ....
> }
>
> is not a recommended coding style. We prefer followings:
>
> if (....)
> {
> ....
> }
> else
> {
> ....
> }
>
> Best regards,
> --
> Tatsuo Ishii
> SRA OSS, Inc. Japan
> English: http://www.sraoss.co.jp/index_en.php
> Japanese:http://www.sraoss.co.jp
>
> > I can agree that keeping things consistent is a good idea. I'm busy this
> > week, but I should have time next week to code that up. Any other
> > suggestion you want me to get while I"m doing that, because I don't
> think I
> > have used all the commands. I'll look though the doc's to see what I find
> > as well, but I wanted to ask in case there is something specific you want
> > me to do.
> >
> >
> > On May 9, 2016 3:52 AM, "Tatsuo Ishii" <ishii at postgresql.org> wrote:
> >
> >> > Hey everybody,
> >> > I use pgpool and I noticed that pcp_node_info usually requires that
> I
> >> > have the pgpool docs open in order to interpret the output. As a
> result I
> >> > would like to propose a '-r --readable' option (-h for human-readable
> is
> >> > taken by host). I posted the small patch needed to do this
> >> > http://www.pgpool.net/mantisbt/view.php?id=192 . I am willing to do
> more
> >> > work on this if it is requested. Let me know what the opinion on this
> is.
> >>
> >> If we were going to change pcp_node_info, we might want to change other
> >> places for consistency sake (for example, "show pool_nodes"). What do
> >> you think?
> >>
> >> Best regards,
> >> --
> >> Tatsuo Ishii
> >> SRA OSS, Inc. Japan
> >> English: http://www.sraoss.co.jp/index_en.php
> >> Japanese:http://www.sraoss.co.jp
> >>
> _______________________________________________
> pgpool-hackers mailing list
> pgpool-hackers at pgpool.net
> http://www.pgpool.net/mailman/listinfo/pgpool-hackers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.sraoss.jp/pipermail/pgpool-hackers/attachments/20160727/57e5bf60/attachment-0001.html>
-------------- next part --------------
diff --git a/doc/pgpool-en.html b/doc/pgpool-en.html
index b96fcfb..c2c195d 100644
--- a/doc/pgpool-en.html
+++ b/doc/pgpool-en.html
@@ -3442,12 +3442,15 @@ if you use the load balancing mode), the role, the SELECT query counts issued to
are explained in the <a href="#pcp_node_info">pcp_node_info reference</a>.
If the hostname is something like "/tmp", that means pgpool-II is connecting to backend by using UNIX domain sockets. The SELECT count does not include internal queries used by pgoool-II. Also the counters are reset to zero upon starting up of pgpool-II.
</p>
+<p>
+Please note that since pgpool-II <span class="version">3.6</span>, The status column shows the human readable status instead of status code
+</p>
<pre>
benchs2=# show pool_nodes;
node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node
---------+----------+-------+--------+-----------+---------+------------+-------------------
- 0 | /tmp | 11002 | 2 | 0.500000 | primary | 9231 | true
- 1 | /tmp | 11003 | 2 | 0.500000 | standby | 9469 | false
+ 0 | /tmp | 11002 | up | 0.500000 | primary | 9231 | true
+ 1 | /tmp | 11003 | up | 0.500000 | standby | 9469 | false
(2 rows)
</pre>
@@ -5093,6 +5096,10 @@ Shows help for the command line arguments, then exit.
<dt>Description:</dt>
<dd>
<p>Displays the information on the given node ID.</p>
+ <p>
+ Please note that since pgpool-II <span class="version">3.6</span>, The output also contains the human readable node status
+ </p>
+
</dd>
<dt>Options:</dt>
<dd>
@@ -5111,7 +5118,7 @@ Shows help for the command line arguments, then exit.
<dd>
<pre>
$ pcp_node_info -h localhost -U postgres 0
-host1 5432 1 1073741823.500000
+host1 5432 1 1073741823.500000 waiting
</pre>
<p>The result is in the following order:</p>
@@ -5120,6 +5127,7 @@ host1 5432 1 1073741823.500000
<li>port number</li>
<li>status</li>
<li>load balance weight</li>
+<li>status name</li>
</ol>
<p>Status is represented by a digit from [0 to 3].</p>
@@ -5135,10 +5143,11 @@ host1 5432 1 1073741823.500000
<pre>
$ pcp_node_info --verbose -h localhost -U postgres 0
-Hostname: host1
-Port : 5432
-Status : 1
-Weight : 0.5
+Hostname : host1
+Port : 5432
+Status : 1
+Weight : 0.5
+Status Name: waiting
</pre>
</dd>
</dl>
diff --git a/src/config/pool_config.c b/src/config/pool_config.c
index 0d0012b..0fdd695 100644
--- a/src/config/pool_config.c
+++ b/src/config/pool_config.c
@@ -2265,4 +2265,36 @@ char *pool_flag_to_str(unsigned short flag)
return buf;
}
+/*
+ * Translate the BACKEND_STATUS enum value to string.
+ * the function returns the constant string so should not be freed
+ */
+char* backend_status_to_str(BACKEND_STATUS status)
+{
+ char *statusName;
+
+ switch (status) {
+
+ case CON_UNUSED:
+ statusName = BACKEND_STATUS_CON_UNUSED;
+ break;
+
+ case CON_CONNECT_WAIT:
+ statusName = BACKEND_STATUS_CON_CONNECT_WAIT;
+ break;
+
+ case CON_UP:
+ statusName = BACKEND_STATUS_CON_UP;
+ break;
+
+ case CON_DOWN:
+ statusName = BACKEND_STATUS_CON_DOWN;
+ break;
+
+ default:
+ statusName = "unknown";
+ break;
+ }
+ return statusName;
+}
diff --git a/src/config/pool_config.l b/src/config/pool_config.l
index 6a84007..0f45734 100644
--- a/src/config/pool_config.l
+++ b/src/config/pool_config.l
@@ -540,3 +540,35 @@ char *pool_flag_to_str(unsigned short flag)
return buf;
}
+/*
+ * Translate the BACKEND_STATUS enum value to string.
+ * the function returns the constant string so should not be freed
+ */
+char* backend_status_to_str(BACKEND_STATUS status)
+{
+ char *statusName;
+
+ switch (status) {
+
+ case CON_UNUSED:
+ statusName = BACKEND_STATUS_CON_UNUSED;
+ break;
+
+ case CON_CONNECT_WAIT:
+ statusName = BACKEND_STATUS_CON_CONNECT_WAIT;
+ break;
+
+ case CON_UP:
+ statusName = BACKEND_STATUS_CON_UP;
+ break;
+
+ case CON_DOWN:
+ statusName = BACKEND_STATUS_CON_DOWN;
+ break;
+
+ default:
+ statusName = "unknown";
+ break;
+ }
+ return statusName;
+}
diff --git a/src/include/pcp/libpcp_ext.h b/src/include/pcp/libpcp_ext.h
index 42e83f2..99cb385 100644
--- a/src/include/pcp/libpcp_ext.h
+++ b/src/include/pcp/libpcp_ext.h
@@ -42,12 +42,18 @@
#define MAX_PATH_LENGTH 256
typedef enum {
- CON_UNUSED, /* unused slot */
- CON_CONNECT_WAIT, /* waiting for connection starting */
- CON_UP, /* up and running */
- CON_DOWN /* down, disconnected */
+ CON_UNUSED, /* unused slot */
+ CON_CONNECT_WAIT, /* waiting for connection starting */
+ CON_UP, /* up and running */
+ CON_DOWN /* down, disconnected */
} BACKEND_STATUS;
+/* backend status name strings */
+#define BACKEND_STATUS_CON_UNUSED "unused"
+#define BACKEND_STATUS_CON_CONNECT_WAIT "waiting"
+#define BACKEND_STATUS_CON_UP "up"
+#define BACKEND_STATUS_CON_DOWN "down"
+
/*
* PostgreSQL backend descriptor. Placed on shared memory area.
*/
@@ -123,7 +129,7 @@ typedef struct {
#define POOLCONFIG_MAXDESCLEN 80
#define POOLCONFIG_MAXIDENTLEN 63
#define POOLCONFIG_MAXPORTLEN 6
-#define POOLCONFIG_MAXSTATLEN 2
+#define POOLCONFIG_MAXSTATLEN 8
#define POOLCONFIG_MAXWEIGHTLEN 20
#define POOLCONFIG_MAXDATELEN 128
#define POOLCONFIG_MAXCOUNTLEN 16
diff --git a/src/include/pool_config.h b/src/include/pool_config.h
index e170a00..643176a 100644
--- a/src/include/pool_config.h
+++ b/src/include/pool_config.h
@@ -340,6 +340,7 @@ extern int pool_init_config(void);
extern bool pool_get_config(const char *config_file, ConfigContext context);
extern int eval_logical(const char *str);
extern char *pool_flag_to_str(unsigned short flag);
+extern char* backend_status_to_str(BACKEND_STATUS status);
/* methods used for regexp support */
extern int add_regex_pattern(const char *type, char *s);
diff --git a/src/include/utils/pool_process_reporting.h b/src/include/utils/pool_process_reporting.h
index d4a0fc5..08af51d 100644
--- a/src/include/utils/pool_process_reporting.h
+++ b/src/include/utils/pool_process_reporting.h
@@ -43,4 +43,5 @@ extern void cache_reporting(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *bac
extern void send_config_var_detail_row(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend, const char* name, const char* value, const char* description);
extern void send_config_var_value_only_row(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend, const char* value);
+extern char* get_backend_status_string(BACKEND_STATUS status);
#endif
diff --git a/src/test/regression/tests/003.failover/create_expected.sql b/src/test/regression/tests/003.failover/create_expected.sql
index 342b06a..cf8635e 100644
--- a/src/test/regression/tests/003.failover/create_expected.sql
+++ b/src/test/regression/tests/003.failover/create_expected.sql
@@ -10,10 +10,10 @@ CREATE TEMP TABLE tmp (
mode text);
INSERT INTO tmp VALUES
-('0',:dir,'11002','2','0.500000','primary','0','false','s'),
-('1',:dir,'11003','3','0.500000','standby','0','false','s'),
-('0',:dir,'11002','2','0.500000','master','0','false','r'),
-('1',:dir,'11003','3','0.500000','slave','0','false','r');
+('0',:dir,'11002','up','0.500000','primary','0','false','s'),
+('1',:dir,'11003','down','0.500000','standby','0','false','s'),
+('0',:dir,'11002','up','0.500000','master','0','false','r'),
+('1',:dir,'11003','down','0.500000','slave','0','false','r');
SELECT node_id,hostname,port,status,lb_weight,role,select_cnt,load_balance_node
FROM tmp
diff --git a/src/tools/pcp/pcp_frontend_client.c b/src/tools/pcp/pcp_frontend_client.c
index a140508..2961aa1 100644
--- a/src/tools/pcp/pcp_frontend_client.c
+++ b/src/tools/pcp/pcp_frontend_client.c
@@ -48,6 +48,7 @@ static void output_proccount_result(PCPResultInfo* pcpResInfo, bool verbose);
static void output_poolstatus_result(PCPResultInfo* pcpResInfo, bool verbose);
static void output_nodeinfo_result(PCPResultInfo* pcpResInfo, bool verbose);
static void output_nodecount_result(PCPResultInfo* pcpResInfo, bool verbose);
+static char* backend_status_to_string(BACKEND_STATUS status);
typedef enum
{
@@ -465,17 +466,19 @@ output_nodeinfo_result(PCPResultInfo* pcpResInfo, bool verbose)
if (verbose)
{
- printf("Hostname: %s\nPort : %d\nStatus : %d\nWeight : %f\n",
+ printf("Hostname : %s\nPort : %d\nStatus : %d\nWeight : %f\nStatus Name: %s\n",
backend_info->backend_hostname,
backend_info->backend_port,
backend_info->backend_status,
- backend_info->backend_weight/RAND_MAX);
+ backend_info->backend_weight/RAND_MAX,
+ backend_status_to_string(backend_info->backend_status));
} else {
- printf("%s %d %d %f\n",
+ printf("%s %d %d %f %s\n",
backend_info->backend_hostname,
backend_info->backend_port,
backend_info->backend_status,
- backend_info->backend_weight/RAND_MAX);
+ backend_info->backend_weight/RAND_MAX,
+ backend_status_to_string(backend_info->backend_status));
}
}
@@ -767,3 +770,35 @@ get_progname(const char *argv0)
return progname;
}
+/*
+ * Translate the BACKEND_STATUS enum value to string.
+ * the function returns the constant string so should not be freed
+ */
+static char* backend_status_to_string(BACKEND_STATUS status)
+{
+ char *statusName;
+
+ switch (status) {
+
+ case CON_UNUSED:
+ statusName = BACKEND_STATUS_CON_UNUSED;
+ break;
+
+ case CON_CONNECT_WAIT:
+ statusName = BACKEND_STATUS_CON_CONNECT_WAIT;
+ break;
+
+ case CON_UP:
+ statusName = BACKEND_STATUS_CON_UP;
+ break;
+
+ case CON_DOWN:
+ statusName = BACKEND_STATUS_CON_DOWN;
+ break;
+
+ default:
+ statusName = "unknown";
+ break;
+ }
+ return statusName;
+}
diff --git a/src/tools/pgmd5/pool_config.c b/src/tools/pgmd5/pool_config.c
index b6aebf6..ee5933d 100644
--- a/src/tools/pgmd5/pool_config.c
+++ b/src/tools/pgmd5/pool_config.c
@@ -2265,4 +2265,36 @@ char *pool_flag_to_str(unsigned short flag)
return buf;
}
+/*
+ * Translate the BACKEND_STATUS enum value to string.
+ * the function returns the constant string so should not be freed
+ */
+char* backend_status_to_str(BACKEND_STATUS status)
+{
+ char *statusName;
+
+ switch (status) {
+
+ case CON_UNUSED:
+ statusName = BACKEND_STATUS_CON_UNUSED;
+ break;
+
+ case CON_CONNECT_WAIT:
+ statusName = BACKEND_STATUS_CON_CONNECT_WAIT;
+ break;
+
+ case CON_UP:
+ statusName = BACKEND_STATUS_CON_UP;
+ break;
+
+ case CON_DOWN:
+ statusName = BACKEND_STATUS_CON_DOWN;
+ break;
+
+ default:
+ statusName = "unknown";
+ break;
+ }
+ return statusName;
+}
diff --git a/src/utils/pool_process_reporting.c b/src/utils/pool_process_reporting.c
index 15a1db8..8aa0868 100644
--- a/src/utils/pool_process_reporting.c
+++ b/src/utils/pool_process_reporting.c
@@ -32,6 +32,7 @@
#include <string.h>
#include <netinet/in.h>
+
void send_row_description(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend,
short num_fields, char **field_names)
{
@@ -902,7 +903,7 @@ POOL_REPORT_CONFIG* get_config(int *nrows)
i++;
snprintf(status[i].name, POOLCONFIG_MAXNAMELEN, "backend_status%d", j);
- snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%d", BACKEND_INFO(j).backend_status);
+ snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%s",backend_status_to_str(BACKEND_INFO(j).backend_status) );
snprintf(status[i].desc, POOLCONFIG_MAXDESCLEN, "status of backend #%d", j);
i++;
@@ -1153,7 +1154,7 @@ POOL_REPORT_NODES* get_nodes(int *nrows)
snprintf(nodes[i].node_id, POOLCONFIG_MAXIDLEN, "%d", i);
StrNCpy(nodes[i].hostname, bi->backend_hostname, strlen(bi->backend_hostname)+1);
snprintf(nodes[i].port, POOLCONFIG_MAXPORTLEN, "%d", bi->backend_port);
- snprintf(nodes[i].status, POOLCONFIG_MAXSTATLEN, "%d", bi->backend_status);
+ snprintf(nodes[i].status, POOLCONFIG_MAXSTATLEN, "%s", backend_status_to_str(bi->backend_status));
snprintf(nodes[i].lb_weight, POOLCONFIG_MAXWEIGHTLEN, "%f", bi->backend_weight/RAND_MAX);
snprintf(nodes[i].select, POOLCONFIG_MAXWEIGHTLEN, "%lld", stat_get_select_count(i));
snprintf(nodes[i].load_balance_node, POOLCONFIG_MAXWEIGHTLEN, "%s",
More information about the pgpool-hackers
mailing list