More work on "standby clone"

This commit is contained in:
Ian Barwick
2017-05-01 22:22:31 +09:00
parent 675dc5adb3
commit 206a9fd333
5 changed files with 213 additions and 137 deletions

View File

@@ -652,7 +652,7 @@ guc_set_typed(PGconn *conn, const char *parameter, const char *op,
" WHERE name = '%s' AND setting::%s %s '%s'::%s", " WHERE name = '%s' AND setting::%s %s '%s'::%s",
parameter, datatype, op, value, datatype); parameter, datatype, op, value, datatype);
log_verbose(LOG_DEBUG, "guc_set_typed():\n%s\n", query.data); log_verbose(LOG_DEBUG, "guc_set_typed():\n%s", query.data);
res = PQexec(conn, query.data); res = PQexec(conn, query.data);

View File

@@ -266,9 +266,12 @@ check_source_server()
{ {
int server_version_num = UNKNOWN_SERVER_VERSION_NUM; int server_version_num = UNKNOWN_SERVER_VERSION_NUM;
char cluster_size[MAXLEN]; char cluster_size[MAXLEN];
t_node_info node_record = T_NODE_INFO_INITIALIZER;
int query_result;
t_extension_status extension_status;
/* Attempt to connect to the upstream server to verify its configuration */ /* Attempt to connect to the upstream server to verify its configuration */
log_info(_("connecting to upstream node\n")); log_info(_("connecting to upstream node"));
source_conn = establish_db_connection_by_params((const char**)source_conninfo.keywords, source_conn = establish_db_connection_by_params((const char**)source_conninfo.keywords,
(const char**)source_conninfo.values, (const char**)source_conninfo.values,
@@ -280,24 +283,25 @@ check_source_server()
*/ */
if (PQstatus(source_conn) != CONNECTION_OK) if (PQstatus(source_conn) != CONNECTION_OK)
{ {
if (mode != barman) if (mode == barman)
{
return;
}
else
{ {
PQfinish(source_conn); PQfinish(source_conn);
exit(ERR_DB_CON); exit(ERR_DB_CON);
} }
} }
else
{
/* /*
* If a connection was established, perform some sanity checks on the * If a connection was established, perform some sanity checks on the
* provided upstream connection * provided upstream connection
*/ */
t_node_info upstream_node_record = T_NODE_INFO_INITIALIZER;
int query_result;
t_extension_status extension_status;
/* Verify that upstream node is a supported server version */ /* Verify that upstream node is a supported server version */
log_verbose(LOG_INFO, _("connected to upstream node, checking its state\n")); log_verbose(LOG_INFO, _("connected to upstream node, checking its state"));
server_version_num = check_server_version(source_conn, "master", true, NULL); server_version_num = check_server_version(source_conn, "master", true, NULL);
@@ -306,7 +310,8 @@ check_source_server()
if (get_cluster_size(source_conn, cluster_size) == false) if (get_cluster_size(source_conn, cluster_size) == false)
exit(ERR_DB_QUERY); exit(ERR_DB_QUERY);
log_info(_("Successfully connected to source node. Current installation size is %s"), log_info(_("successfully connected to source node"));
log_detail(_("current installation size is %s"),
cluster_size); cluster_size);
/* /*
@@ -371,8 +376,8 @@ check_source_server()
} }
/* /*
* If no target directory was explicitly provided, we'll default to * If no target data directory was explicitly provided, we'll default to
* the same directory as on the source host. * the source host's data directory.
*/ */
if (local_data_directory_provided == false) if (local_data_directory_provided == false)
{ {
@@ -386,6 +391,8 @@ check_source_server()
* Copy the source connection so that we have some default values, * Copy the source connection so that we have some default values,
* particularly stuff like passwords extracted from PGPASSFILE; * particularly stuff like passwords extracted from PGPASSFILE;
* these will be overridden from the upstream conninfo, if provided. * these will be overridden from the upstream conninfo, if provided.
*
* XXX only allow passwords if --use-conninfo-password
*/ */
conn_to_param_list(source_conn, &recovery_conninfo); conn_to_param_list(source_conn, &recovery_conninfo);
@@ -397,14 +404,29 @@ check_source_server()
else else
upstream_node_id = config_file_options.upstream_node_id; upstream_node_id = config_file_options.upstream_node_id;
query_result = get_node_record(source_conn, upstream_node_id, &upstream_node_record); query_result = get_node_record(source_conn, upstream_node_id, &node_record);
if (query_result) if (query_result)
{ {
upstream_record_found = true; upstream_record_found = true;
strncpy(recovery_conninfo_str, upstream_node_record.conninfo, MAXLEN); strncpy(recovery_conninfo_str, node_record.conninfo, MAXLEN);
} }
/*
* check that there's no existing node record with the same name but
* different ID
*/
query_result = get_node_record_by_name(source_conn, config_file_options.node_name, &node_record);
if (query_result)
{
log_error(_("another node (node_id: %i) already exists with node_name \"%s\""),
node_record.node_id,
config_file_options.node_name);
PQfinish(source_conn);
exit(ERR_BAD_CONFIG);
} }
} }

View File

@@ -28,8 +28,13 @@ typedef struct
bool terse; bool terse;
bool verbose; bool verbose;
/* connection options */ /* standard connection options */
char dbname[MAXLEN];
char host[MAXLEN]; char host[MAXLEN];
char username[MAXLEN];
char port[MAXLEN];
/* other connection options */
char remote_user[MAXLEN]; char remote_user[MAXLEN];
char superuser[MAXLEN]; char superuser[MAXLEN];
@@ -62,8 +67,10 @@ typedef struct
"", false, "", \ "", false, "", \
/* logging options */ \ /* logging options */ \
"", false, false, false, \ "", false, false, false, \
/* connection options */ \ /* database connection options */ \
"", "", "", \ "", "", "", "", \
/* other connection options */ \
"", "", \
/* node options */ \ /* node options */ \
UNKNOWN_NODE_ID, "", "", \ UNKNOWN_NODE_ID, "", "", \
/* standby clone options */ \ /* standby clone options */ \

View File

@@ -74,7 +74,9 @@ main(int argc, char **argv)
*/ */
logger_output_mode = OM_COMMAND_LINE; logger_output_mode = OM_COMMAND_LINE;
while ((c = getopt_long(argc, argv, "?Vf:Fb:S:L:vtD:cr", long_options, initialize_conninfo_params(&source_conninfo, true);
while ((c = getopt_long(argc, argv, "?Vb:f:Fd:h:p:U:R:S:L:vtD:cr", long_options,
&optindex)) != -1) &optindex)) != -1)
{ {
/* /*
@@ -107,21 +109,37 @@ main(int argc, char **argv)
/* general configuration options /* general configuration options
* ----------------------------- */ * ----------------------------- */
/* -f/--config-file */
case 'f':
strncpy(runtime_options.config_file, optarg, MAXLEN);
break;
/* -F/--force */
case 'F':
runtime_options.force = true;
break;
/* -b/--pg_bindir */ /* -b/--pg_bindir */
case 'b': case 'b':
strncpy(runtime_options.pg_bindir, optarg, MAXLEN); strncpy(runtime_options.pg_bindir, optarg, MAXLEN);
break; break;
/* connection options */ /* -f/--config-file */
/* ------------------ */ case 'f':
strncpy(runtime_options.config_file, optarg, MAXLEN);
break;
/* -F/--force */
case 'F':
runtime_options.force = true;
break;
/* database connection options */
/* --------------------------- */
/*
* These are the standard database connection options; with the
* exception of -d/--dbname (which could be a conninfo string)
* we'll also set these values in "source_conninfo" (overwriting
* preset values from environment variables).
* XXX check this is same as psql
*/
/* -d/--dbname */
case 'd':
strncpy(runtime_options.dbname, optarg, MAXLEN);
/* dbname will be set in source_conninfo later after checking if it's a conninfo string */
runtime_options.connection_param_provided = true;
break;
/* -h/--host */ /* -h/--host */
case 'h': case 'h':
@@ -131,6 +149,25 @@ main(int argc, char **argv)
runtime_options.host_param_provided = true; runtime_options.host_param_provided = true;
break; break;
case 'p':
(void) repmgr_atoi(optarg, "-p/--port", &cli_errors, false);
param_set(&source_conninfo, "port", optarg);
strncpy(runtime_options.port,
optarg,
MAXLEN);
runtime_options.connection_param_provided = true;
break;
/* -U/--user */
case 'U':
strncpy(runtime_options.username, optarg, MAXLEN);
param_set(&source_conninfo, "user", optarg);
runtime_options.connection_param_provided = true;
break;
/* other connection options */
/* ------------------------ */
/* -R/--remote_user */ /* -R/--remote_user */
case 'R': case 'R':
strncpy(runtime_options.remote_user, optarg, MAXLEN); strncpy(runtime_options.remote_user, optarg, MAXLEN);
@@ -162,18 +199,22 @@ main(int argc, char **argv)
/* standby clone options * /* standby clone options *
* --------------------- */ * --------------------- */
/* -c/--fast-checkpoint */
case 'c': case 'c':
runtime_options.fast_checkpoint = true; runtime_options.fast_checkpoint = true;
break; break;
/* -r/--rsync-only */
case 'r': case 'r':
runtime_options.rsync_only = true; runtime_options.rsync_only = true;
break; break;
/* --no-upstream-connection */
case OPT_NO_UPSTREAM_CONNECTION: case OPT_NO_UPSTREAM_CONNECTION:
runtime_options.no_upstream_connection = true; runtime_options.no_upstream_connection = true;
break; break;
/* --recovery-min-apply-delay */
case OPT_RECOVERY_MIN_APPLY_DELAY: case OPT_RECOVERY_MIN_APPLY_DELAY:
{ {
char *ptr = NULL; char *ptr = NULL;
@@ -324,6 +365,12 @@ main(int argc, char **argv)
if (strcasecmp(repmgr_action, "REGISTER") == 0) if (strcasecmp(repmgr_action, "REGISTER") == 0)
action = MASTER_REGISTER; action = MASTER_REGISTER;
} }
else if(strcasecmp(repmgr_node_type, "STANDBY") == 0)
{
if (strcasecmp(repmgr_action, "CLONE") == 0)
action = STANDBY_CLONE;
}
else if(strcasecmp(repmgr_node_type, "CLUSTER") == 0) else if(strcasecmp(repmgr_node_type, "CLUSTER") == 0)
{ {
if (strcasecmp(repmgr_action, "EVENT") == 0) if (strcasecmp(repmgr_action, "EVENT") == 0)

View File

@@ -50,7 +50,7 @@
#define OPT_CLUSTER 15 #define OPT_CLUSTER 15
#define OPT_LOG_TO_FILE 16 #define OPT_LOG_TO_FILE 16
#define OPT_UPSTREAM_CONNINFO 17 #define OPT_UPSTREAM_CONNINFO 17
/* XXX deprecate, replace with --use-conninfo-password */ /* XXX deprecate, replace with --use-conninfo-password (--use-recovery-conninfo-password) set */
#define OPT_NO_CONNINFO_PASSWORD 18 #define OPT_NO_CONNINFO_PASSWORD 18
#define OPT_REPLICATION_USER 19 #define OPT_REPLICATION_USER 19
#define OPT_EVENT 20 #define OPT_EVENT 20
@@ -70,9 +70,12 @@ static struct option long_options[] =
{"pg_bindir", required_argument, NULL, 'b'}, {"pg_bindir", required_argument, NULL, 'b'},
/* connection options */ /* connection options */
{"dbname", required_argument, NULL, 'd'},
{"host", required_argument, NULL, 'h'}, {"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'},
{"remote-user", required_argument, NULL, 'R'}, {"remote-user", required_argument, NULL, 'R'},
{"superuser", required_argument, NULL, 'S'}, {"superuser", required_argument, NULL, 'S'},
{"username", required_argument, NULL, 'U'},
/* node options */ /* node options */
{"pgdata", required_argument, NULL, 'D'}, {"pgdata", required_argument, NULL, 'D'},
@@ -102,9 +105,6 @@ static struct option long_options[] =
{"limit", required_argument, NULL, OPT_LIMIT }, {"limit", required_argument, NULL, OPT_LIMIT },
/* not yet handled */ /* not yet handled */
{"dbname", required_argument, NULL, 'd'},
{"port", required_argument, NULL, 'p'},
{"username", required_argument, NULL, 'U'},
{"wal-keep-segments", required_argument, NULL, 'w'}, {"wal-keep-segments", required_argument, NULL, 'w'},
{"keep-history", required_argument, NULL, 'k'}, {"keep-history", required_argument, NULL, 'k'},
{"wait", no_argument, NULL, 'W'}, {"wait", no_argument, NULL, 'W'},