diff options
author | Pavan Deolasee | 2016-01-15 07:15:54 +0000 |
---|---|---|
committer | Pavan Deolasee | 2016-10-18 09:41:41 +0000 |
commit | 845e8ef75378ae7936a7e83808846fbd34bb2b4d (patch) | |
tree | 2370d7dfe058d122a3118354bdf8b044a1b08824 | |
parent | 396db0c198ac08894654f6575715a55c318a3aec (diff) |
Check if target directory is empty (if it already exists) on the remote node.
We were wrongly doing this check on the local node, which was clearly wrong.
-rw-r--r-- | contrib/pgxc_ctl/coord_cmd.c | 15 | ||||
-rw-r--r-- | contrib/pgxc_ctl/datanode_cmd.c | 19 | ||||
-rw-r--r-- | contrib/pgxc_ctl/gtm_cmd.c | 17 |
3 files changed, 36 insertions, 15 deletions
diff --git a/contrib/pgxc_ctl/coord_cmd.c b/contrib/pgxc_ctl/coord_cmd.c index 9837e5b0d0..5d8bbbae84 100644 --- a/contrib/pgxc_ctl/coord_cmd.c +++ b/contrib/pgxc_ctl/coord_cmd.c @@ -64,6 +64,7 @@ cmd_t *prepare_initCoordinatorMaster(char *nodeName) char localStdin[MAXPATH+1]; char *gtmHost, *gtmPort; char timestamp[MAXTOKEN+1]; + char remoteDirCheck[MAXPATH * 2 + 128]; /* Reset coordinator master directory and run initdb */ if ((jj = coordIdx(nodeName)) < 0) @@ -78,18 +79,24 @@ cmd_t *prepare_initCoordinatorMaster(char *nodeName) return(NULL); } - if ((pgxc_check_dir(aval(VAR_coordMasterDirs)[jj]) == 2) && !forceInit) + remoteDirCheck[0] = '\0'; + if (!forceInit) { - elog(ERROR, "ERROR: target coordinator directory %s exists and is not empty. Skip initilialization.\n", - aval(VAR_coordMasterDirs)[jj]); - return NULL; + sprintf(remoteDirCheck, "if [ \"$(ls -A %s 2> /dev/null)\" ]; then echo 'ERROR: " + "target directory (%s) exists and not empty. " + "Skip Coordinator initilialization'; exit; fi", + aval(VAR_coordMasterDirs)[jj], + aval(VAR_coordMasterDirs)[jj] + ); } cmd = cmdInitdb = initCmd(aval(VAR_coordMasterServers)[jj]); snprintf(newCommand(cmdInitdb), MAXLINE, + "%s;" "rm -rf %s;" "mkdir -p %s;" "initdb --nodename %s -D %s", + remoteDirCheck, aval(VAR_coordMasterDirs)[jj], aval(VAR_coordMasterDirs)[jj], nodeName, diff --git a/contrib/pgxc_ctl/datanode_cmd.c b/contrib/pgxc_ctl/datanode_cmd.c index bcad4bf02a..cbc12400ad 100644 --- a/contrib/pgxc_ctl/datanode_cmd.c +++ b/contrib/pgxc_ctl/datanode_cmd.c @@ -64,21 +64,30 @@ cmd_t *prepare_initDatanodeMaster(char *nodeName) char **fileList = NULL; FILE *f; char timeStamp[MAXTOKEN+1]; + char remoteDirCheck[MAXPATH * 2 + 128]; if ((idx = datanodeIdx(nodeName)) < 0) return(NULL); - if ((pgxc_check_dir(aval(VAR_datanodeMasterDirs)[idx]) == 2) && !forceInit) + remoteDirCheck[0] = '\0'; + if (!forceInit) { - elog(ERROR, "ERROR: target datanode directory %s exists and is not empty. Skip initilialization.\n", - aval(VAR_datanodeMasterDirs)[idx]); - return NULL; + sprintf(remoteDirCheck, "if [ \"$(ls -A %s 2> /dev/null)\" ]; then echo 'ERROR: " + "target directory (%s) exists and not empty. " + "Skip Datanode initilialization'; exit; fi", + aval(VAR_datanodeMasterDirs)[idx], + aval(VAR_datanodeMasterDirs)[idx] + ); + } /* Build each datanode's initialize command */ cmd = cmdInitdb = initCmd(aval(VAR_datanodeMasterServers)[idx]); snprintf(newCommand(cmdInitdb), MAXLINE, - "rm -rf %s; mkdir -p %s; initdb --nodename %s -D %s", + "%s;" + "rm -rf %s;" + "mkdir -p %s; initdb --nodename %s -D %s", + remoteDirCheck, aval(VAR_datanodeMasterDirs)[idx], aval(VAR_datanodeMasterDirs)[idx], aval(VAR_datanodeNames)[idx], aval(VAR_datanodeMasterDirs)[idx]); diff --git a/contrib/pgxc_ctl/gtm_cmd.c b/contrib/pgxc_ctl/gtm_cmd.c index 0737549d47..69faf037a6 100644 --- a/contrib/pgxc_ctl/gtm_cmd.c +++ b/contrib/pgxc_ctl/gtm_cmd.c @@ -54,20 +54,25 @@ cmd_t *prepare_initGtmMaster(void) FILE *f; char **fileList = NULL; int result; + char remoteDirCheck[MAXPATH * 2 + 128]; - result = pgxc_check_dir(sval(VAR_gtmMasterDir)); - - if ((result == 2) && !forceInit) + remoteDirCheck[0] = '\0'; + if (!forceInit) { - elog(ERROR, "ERROR: target GTM directory %s exists and is not empty. Skip initilialization.\n", - sval(VAR_gtmMasterDir)); - return NULL; + sprintf(remoteDirCheck, "if [ \"$(ls -A %s 2> /dev/null)\" ]; then echo 'ERROR: " + "target directory (%s) exists and not empty. " + "Skip GTM initilialization'; exit; fi", + sval(VAR_gtmMasterDir), + sval(VAR_gtmMasterDir) + ); } /* Kill current gtm, bild work directory and run initgtm */ cmdInitGtmMaster = initCmd(sval(VAR_gtmMasterServer)); snprintf(newCommand(cmdInitGtmMaster), MAXLINE, + "%s;" "gtm_ctl -D %s -m immediate -Z gtm stop; rm -rf %s; mkdir -p %s;initgtm -Z gtm -D %s", + remoteDirCheck, sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir)); |