提交 5f1600b7 编写于 作者: A Adam Berlin 提交者: Adam Berlin

Extract Greenplum option parsing from postgres option parsing.

上级 36bd2285
#include "pg_upgrade_greenplum.h"
GreenplumUserOpts greenplum_user_opts;
void
initialize_greenplum_user_options(void)
{
greenplum_user_opts.segment_mode = SEGMENT;
}
bool
process_greenplum_option(int option, char *option_value)
{
switch (option)
{
case GREENPLUM_MODE_OPTION: /* --mode={dispatcher|segment} */
if (pg_strcasecmp("dispatcher", optarg) == 0)
greenplum_user_opts.segment_mode = DISPATCHER;
else if (pg_strcasecmp("segment", optarg) == 0)
greenplum_user_opts.segment_mode = SEGMENT;
else
{
pg_log(PG_FATAL, "invalid segment configuration\n");
exit(1);
}
break;
case GREENPLUM_PROGRESS_OPTION: /* --progress */
greenplum_user_opts.progress = true;
break;
case GREENPLUM_ADD_CHECKSUM_OPTION: /* --add-checksum */
greenplum_user_opts.checksum_mode = CHECKSUM_ADD;
break;
case GREENPLUM_REMOVE_CHECKSUM_OPTION: /* --remove-checksum */
greenplum_user_opts.checksum_mode = CHECKSUM_REMOVE;
break;
case GREENPLUM_OLD_GP_DBID: /* --old-gp-dbid */
old_cluster.gp_dbid = atoi(optarg);
break;
case GREENPLUM_NEW_GP_DBID: /* --new-gp-dbid */
new_cluster.gp_dbid = atoi(optarg);
break;
case GREENPLUM_OLD_TABLESPACES_FILE: /* --old-tablespaces-file */
greenplum_user_opts.old_tablespace_file_path = pg_strdup(optarg);
break;
default:
return false;
}
return true;
}
......@@ -12,13 +12,46 @@
#define PG_OPTIONS_UTILITY_MODE " PGOPTIONS='-c gp_session_role=utility' "
typedef struct {
bool progress;
segmentMode segment_mode;
checksumMode checksum_mode;
char *old_tablespace_file_path;
} GreenplumUserOpts;
#define GREENPLUM_MODE_OPTION 1
#define GREENPLUM_PROGRESS_OPTION 2
#define GREENPLUM_ADD_CHECKSUM_OPTION 3
#define GREENPLUM_REMOVE_CHECKSUM_OPTION 4
#define GREENPLUM_OLD_GP_DBID 5
#define GREENPLUM_NEW_GP_DBID 6
#define GREENPLUM_OLD_TABLESPACES_FILE 7
#define GREENPLUM_OPTIONS \
{"mode", required_argument, NULL, GREENPLUM_MODE_OPTION}, \
{"progress", no_argument, NULL, GREENPLUM_PROGRESS_OPTION}, \
{"add-checksum", no_argument, NULL, GREENPLUM_ADD_CHECKSUM_OPTION}, \
{"remove-checksum", no_argument, NULL, GREENPLUM_REMOVE_CHECKSUM_OPTION},
{"old-gp-dbid", required_argument, NULL, 5},
{"new-gp-dbid", required_argument, NULL, 6},
{"old-tablespaces-file", required_argument, NULL, 7},
#define GREENPLUM_USAGE "\
--mode=TYPE designate node type to upgrade, \"segment\" or \"dispatcher\" (default \"segment\")\n\
--progress enable progress reporting\n\
--remove-checksum remove data checksums when creating new cluster\n\
--add-checksum add data checksumming to the new cluster\n\
--old-gp-dbid greenplum database id of the old segment\n\
--new-gp-dbid greenplum database id of the new segment\n\
--old-tablespaces-file file containing the tablespaces from an old gpdb five cluster\n\
"
/* option_gp.c */
extern GreenplumUserOpts greenplum_user_opts;
void initialize_greenplum_user_options(void);
bool process_greenplum_option(int option, char *option_value);
/* aotable.c */
......
......@@ -58,13 +58,7 @@ parseCommandLine(int argc, char *argv[])
{"verbose", no_argument, NULL, 'v'},
/* Greenplum specific parameters */
{"mode", required_argument, NULL, 1},
{"progress", no_argument, NULL, 2},
{"add-checksum", no_argument, NULL, 3},
{"remove-checksum", no_argument, NULL, 4},
{"old-gp-dbid", required_argument, NULL, 5},
{"new-gp-dbid", required_argument, NULL, 6},
{"old-tablespaces-file", required_argument, NULL, 7},
GREENPLUM_OPTIONS
{NULL, 0, NULL, 0}
};
......@@ -90,7 +84,7 @@ parseCommandLine(int argc, char *argv[])
os_user_effective_id = get_user_info(&os_info.user);
greenplum_user_opts.segment_mode = SEGMENT;
initialize_greenplum_user_options();
/* we override just the database user name; we got the OS id above */
if (getenv("PGUSER"))
......@@ -208,50 +202,10 @@ parseCommandLine(int argc, char *argv[])
log_opts.verbose = true;
break;
/*
* Greenplum specific parameters
*/
case 1: /* --mode={dispatcher|segment} */
if (pg_strcasecmp("dispatcher", optarg) == 0)
greenplum_user_opts.segment_mode = DISPATCHER;
else if (pg_strcasecmp("segment", optarg) == 0)
greenplum_user_opts.segment_mode = SEGMENT;
else
{
pg_log(PG_FATAL, "invalid segment configuration\n");
exit(1);
}
break;
case 2: /* --progress */
greenplum_user_opts.progress = true;
break;
case 3: /* --add-checksum */
greenplum_user_opts.checksum_mode = CHECKSUM_ADD;
break;
case 4: /* --remove-checksum */
greenplum_user_opts.checksum_mode = CHECKSUM_REMOVE;
break;
case 5: /* --old-gp-dbid */
old_cluster.gp_dbid = atoi(optarg);
break;
case 6: /* --new-gp-dbid */
new_cluster.gp_dbid = atoi(optarg);
break;
case 7: /* --old-tablespaces-file */
user_opts.old_tablespace_file_path = pg_strdup(optarg);
break;
default:
pg_fatal("Try \"%s --help\" for more information.\n",
os_info.progname);
if (!process_greenplum_option(option, pg_strdup(optarg)))
pg_fatal("Try \"%s --help\" for more information.\n",
os_info.progname);
break;
}
}
......@@ -338,13 +292,7 @@ Options:\n\
-U, --username=NAME cluster superuser (default \"%s\")\n\
-v, --verbose enable verbose internal logging\n\
-V, --version display version information, then exit\n\
--mode=TYPE designate node type to upgrade, \"segment\" or \"dispatcher\" (default \"segment\")\n\
--progress enable progress reporting\n\
--remove-checksum remove data checksums when creating new cluster\n\
--add-checksum add data checksumming to the new cluster\n\
--old-gp-dbid greenplum database id of the old segment\n\
--new-gp-dbid greenplum database id of the new segment\n\
--old-tablespaces-file file containing the tablespaces from an old gpdb five cluster\n\
%s\
-?, --help show this help, then exit\n\
\n\
Before running pg_upgrade you must:\n\
......@@ -360,7 +308,7 @@ When you run pg_upgrade, you must provide the following information:\n\
\n\
For example:\n\
pg_upgrade -d oldCluster/data -D newCluster/data -b oldCluster/bin -B newCluster/bin\n\
or\n"), old_cluster.port, new_cluster.port, os_info.user);
or\n"), old_cluster.port, new_cluster.port, os_info.user, GREENPLUM_USAGE);
#ifndef WIN32
printf(_("\
$ export PGDATAOLD=oldCluster/data\n\
......
......@@ -439,8 +439,6 @@ typedef struct
transferMode transfer_mode; /* copy files or link them? */
int jobs; /* number of processes/threads to use */
char *socketdir; /* directory to use for Unix sockets */
char *old_tablespace_file_path;
} UserOpts;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册