diff options
author | Pavan Deolasee | 2015-01-12 12:17:42 +0000 |
---|---|---|
committer | Pavan Deolasee | 2015-04-15 05:49:15 +0000 |
commit | d0bcd6978849a8a58d457c135faa34f71cb2fd95 (patch) | |
tree | f106fbda72ae3cb72cb1827539930be476664566 | |
parent | 266b8aaa84555edfb62b857b0d797011917bc523 (diff) |
Add "force" option to pgxc_ctl init command to forcefully remove datanode,
coordinator or gtm directory
-rw-r--r-- | contrib/pgxc_ctl/coord_cmd.c | 2 | ||||
-rw-r--r-- | contrib/pgxc_ctl/datanode_cmd.c | 2 | ||||
-rw-r--r-- | contrib/pgxc_ctl/do_command.c | 33 | ||||
-rw-r--r-- | contrib/pgxc_ctl/do_command.h | 1 | ||||
-rw-r--r-- | contrib/pgxc_ctl/gtm_cmd.c | 2 | ||||
-rw-r--r-- | doc-xc/src/sgml/pgxc_ctl-ref.sgmlin | 23 |
6 files changed, 39 insertions, 24 deletions
diff --git a/contrib/pgxc_ctl/coord_cmd.c b/contrib/pgxc_ctl/coord_cmd.c index 1d4a1e5a23..c809047934 100644 --- a/contrib/pgxc_ctl/coord_cmd.c +++ b/contrib/pgxc_ctl/coord_cmd.c @@ -78,7 +78,7 @@ cmd_t *prepare_initCoordinatorMaster(char *nodeName) return(NULL); } - if (pgxc_check_dir(aval(VAR_coordMasterDirs)[jj]) == 2) + if ((pgxc_check_dir(aval(VAR_coordMasterDirs)[jj]) == 2) && !forceInit) { elog(ERROR, "ERROR: target coordinator directory %s exists and is not empty. Skip initilialization.\n", aval(VAR_coordMasterDirs)[jj]); diff --git a/contrib/pgxc_ctl/datanode_cmd.c b/contrib/pgxc_ctl/datanode_cmd.c index b86ca4ded6..5defe8a7e8 100644 --- a/contrib/pgxc_ctl/datanode_cmd.c +++ b/contrib/pgxc_ctl/datanode_cmd.c @@ -68,7 +68,7 @@ cmd_t *prepare_initDatanodeMaster(char *nodeName) if ((idx = datanodeIdx(nodeName)) < 0) return(NULL); - if (pgxc_check_dir(aval(VAR_datanodeMasterDirs)[idx]) == 2) + if ((pgxc_check_dir(aval(VAR_datanodeMasterDirs)[idx]) == 2) && !forceInit) { elog(ERROR, "ERROR: target datanode directory %s exists and is not empty. Skip initilialization.\n", aval(VAR_datanodeMasterDirs)[idx]); diff --git a/contrib/pgxc_ctl/do_command.c b/contrib/pgxc_ctl/do_command.c index 49ee7ff983..e8e1c8ac14 100644 --- a/contrib/pgxc_ctl/do_command.c +++ b/contrib/pgxc_ctl/do_command.c @@ -41,6 +41,8 @@ extern char *pgxc_ctl_conf_prototype[]; extern char *pgxc_ctl_conf_prototype_minimal[]; +int forceInit = false; + #define Exit(c) exit(myWEXITSTATUS(c)) #define GetToken() (line = get_word(line, &token)) #define TestToken(word) ((token != NULL) && (strcasecmp(token, word) == 0)) @@ -566,7 +568,15 @@ static void do_init_command(char *line) if (GetToken() == NULL) elog(ERROR, "ERROR: Please specify option to init command.\n"); - else if (TestToken("all")) + + if (TestToken("force")) + { + forceInit = true; + if (GetToken() == NULL) + elog(ERROR, "ERROR: Please specify option to init command.\n"); + } + + if (TestToken("all")) init_all(); else if (TestToken("gtm")) { @@ -2786,16 +2796,17 @@ do_show_help(char *line) { printf( "\n" - "init all\n" - "init nodename ...\n" - "init gtm [ master | slave | all ]\n" - "init gtm_proxy [ all | nodename ... ]\n" - "init coordinator nodename ...\n" - "init coordinator [ master | slave ] [ all | nodename ... ]\n" - "init datanode nodename ...\n" - "init datanode [ master | slave ] [ all | nodename ... ]\n" - "\n" - "Initializes specified nodes\n" + "init [force] all\n" + "init [force] nodename ...\n" + "init [force] gtm [ master | slave | all ]\n" + "init [force] gtm_proxy [ all | nodename ... ]\n" + "init [force] coordinator nodename ...\n" + "init [force] coordinator [ master | slave ] [ all | nodename ... ]\n" + "init [force] datanode nodename ...\n" + "init [force] datanode [ master | slave ] [ all | nodename ... ]\n" + "\n" + "Initializes specified nodes.\n" + " [force] option removes existing data directories even if they are not empty\n" "For more details, please see the pgxc_ctl documentation\n" "\n" ); diff --git a/contrib/pgxc_ctl/do_command.h b/contrib/pgxc_ctl/do_command.h index 57c5bb3513..5c9c685991 100644 --- a/contrib/pgxc_ctl/do_command.h +++ b/contrib/pgxc_ctl/do_command.h @@ -11,6 +11,7 @@ #ifndef DO_COMMAND_H #define DO_COMMAND_H +extern int forceInit; extern void do_command(FILE *inf, FILE *outf); extern int do_singleLine(char *buf, char *wkline); #endif /* DO_COMMAND_H */ diff --git a/contrib/pgxc_ctl/gtm_cmd.c b/contrib/pgxc_ctl/gtm_cmd.c index c7879bb3a2..6aec250627 100644 --- a/contrib/pgxc_ctl/gtm_cmd.c +++ b/contrib/pgxc_ctl/gtm_cmd.c @@ -57,7 +57,7 @@ cmd_t *prepare_initGtmMaster(void) result = pgxc_check_dir(sval(VAR_gtmMasterDir)); - if (result == 2) + if ((result == 2) && !forceInit) { elog(ERROR, "ERROR: target GTM directory %s exists and is not empty. Skip initilialization.\n", sval(VAR_gtmMasterDir)); diff --git a/doc-xc/src/sgml/pgxc_ctl-ref.sgmlin b/doc-xc/src/sgml/pgxc_ctl-ref.sgmlin index 9eb92cdf80..1910bb419c 100644 --- a/doc-xc/src/sgml/pgxc_ctl-ref.sgmlin +++ b/doc-xc/src/sgml/pgxc_ctl-ref.sgmlin @@ -1690,22 +1690,25 @@ PGXC$ prepare config minimal my_minimal_config.conf </varlistentry> <varlistentry> - <term><literal>init all</literal></term> - <term><literal>init <replaceable class="parameter">nodename ...</replaceable></literal></term> - <term><literal>init gtm [ master | slave | all ]</literal></term> - <term><literal>init gtm_proxy [ all | <replaceable class="parameter">nodename ...</replaceable> ]</literal></term> - <term><literal>init coordinator <replaceable class="parameter">nodename ...</replaceable></literal></term> - <term><literal>init coordinator [ master | slave ] [ all | <replaceable class="parameter">nodename ...</replaceable> ]</literal></term> - <term><literal>init datanode <replaceable class="parameter">nodename ...</replaceable></literal></term> - <term><literal>init datanode [ master | slave ] [ all | <replaceable class="parameter">nodename ...</replaceable> ]</literal></term> + <term><literal>init [force] all</literal></term> + <term><literal>init [force] <replaceable class="parameter">nodename ...</replaceable></literal></term> + <term><literal>init [force] gtm [ master | slave | all ]</literal></term> + <term><literal>init [force] gtm_proxy [ all | <replaceable class="parameter">nodename ...</replaceable> ]</literal></term> + <term><literal>init [force] coordinator <replaceable class="parameter">nodename ...</replaceable></literal></term> + <term><literal>init [force] coordinator [ master | slave ] [ all | <replaceable class="parameter">nodename ...</replaceable> ]</literal></term> + <term><literal>init [force] datanode <replaceable class="parameter">nodename ...</replaceable></literal></term> + <term><literal>init [force] datanode [ master | slave ] [ all | <replaceable class="parameter">nodename ...</replaceable> ]</literal></term> <listitem> <para> Initializes specified nodes. </para> <para> At initialization, all the working directories of each component - will be created if it does not exist. If it does, then all the - contents under the working directory will be removed. + will be created if it does not exist. If it does and +<literal>force</literal> is specified, then all the + contents under the working directory will be removed. Without +<literal>force</literal> option, existing non-empty directories will not be +cleaned and the server will start with the existing data. </para> <para> When "all" option is specified, then node information at each |