Prevent pcp_recovery_node from recovering "unused" status node.
authorTatsuo Ishii <ishii@postgresql.org>
Wed, 18 Apr 2018 01:03:37 +0000 (10:03 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Wed, 18 Apr 2018 01:42:52 +0000 (10:42 +0900)
This allowed to try to recover a node without configuration data,
which leads to variety of problems. See discussion:
https://www.pgpool.net/pipermail/pgpool-general/2018-March/006021.html
for more details.

Also I fixed pgpool_recovery function so that it quotes an empty
string argument with double quotes. Without this, the argument is
treated as if it does not exist, which was the source of the complain
from the user.

src/pcp_con/recovery.c
src/sql/pgpool-recovery/pgpool-recovery.c

index 3665ff733cbc61b06a5511c9244da0f8074acd5d..cb259b3986ff46adc3e34dbc4d1cf573d1700f38 100644 (file)
@@ -72,6 +72,10 @@ void start_recovery(int recovery_node)
                ereport(ERROR,
                                (errmsg("node recovery failed, node id: %d is not valid", recovery_node)));
 
+       if (*(my_backend_status[(recovery_node)]) == CON_UNUSED)
+               ereport(ERROR,
+                               (errmsg("node recovery failed, node id: %d is unused", recovery_node)));
+
        if (VALID_BACKEND(recovery_node))
                ereport(ERROR,
                                (errmsg("node recovery failed, node id: %d is alive", recovery_node)));
index c37a57e7abe7928d7fa015d38f862b427d8487ca..f93cc3a0e1bf58eb73776792ec9f860693402174 100644 (file)
@@ -4,7 +4,7 @@
  *
  * pgpool-recovery: exec online recovery script from SELECT statement.
  *
- * Copyright (c) 2003-2013     PgPool Global Development Group
+ * Copyright (c) 2003-2018     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -83,13 +83,13 @@ pgpool_recovery(PG_FUNCTION_ARGS)
        {
                char *remote_port = DatumGetCString(DirectFunctionCall1(textout,
                                                                                                                  PointerGetDatum(PG_GETARG_TEXT_P(3))));
-               snprintf(recovery_script, sizeof(recovery_script), "%s/%s %s %s %s %s",
+               snprintf(recovery_script, sizeof(recovery_script), "\\"%s/%s\\" \\"%s\\" \\"%s\\" \\"%s\\" \\"%s\\"",
                                 DataDir, script, DataDir, remote_host,
                                 remote_data_directory, remote_port);
        }
        else
        {
-               snprintf(recovery_script, sizeof(recovery_script), "%s/%s %s %s %s",
+               snprintf(recovery_script, sizeof(recovery_script), "\\"%s/%s\\" \\"%s\\" \\"%s\"" \\"%s\\"",
                                 DataDir, script, DataDir, remote_host,
                                 remote_data_directory);
        }