Consolidate final output of "standby follow" / "node rejoin"

This commit is contained in:
Ian Barwick
2017-08-09 19:31:42 +09:00
parent bae82318f1
commit 4930c95ef7
3 changed files with 81 additions and 43 deletions

View File

@@ -927,10 +927,13 @@ do_node_rejoin(void)
PQExpBufferData command; PQExpBufferData command;
PQExpBufferData command_output; PQExpBufferData command_output;
PQExpBufferData follow_output;
struct stat statbuf; struct stat statbuf;
char filebuf[MAXPGPATH] = ""; char filebuf[MAXPGPATH] = "";
t_node_info primary_node_record = T_NODE_INFO_INITIALIZER; t_node_info primary_node_record = T_NODE_INFO_INITIALIZER;
bool success;
/* check node is not actually running */ /* check node is not actually running */
status = PQping(config_file_options.conninfo); status = PQping(config_file_options.conninfo);
@@ -1069,8 +1072,36 @@ do_node_rejoin(void)
} }
} }
do_standby_follow_internal(upstream_conn, &primary_node_record); initPQExpBuffer(&follow_output);
success = do_standby_follow_internal(
upstream_conn,
&primary_node_record,
&follow_output);
create_event_notification(
upstream_conn,
&config_file_options,
config_file_options.node_id,
"node_rejoin",
success,
follow_output.data);
PQfinish(upstream_conn);
if (success == false)
{
log_notice(_("NODE REJOIN failed"));
log_detail("%s", follow_output.data);
termPQExpBuffer(&follow_output);
exit(ERR_DB_QUERY);
}
log_notice(_("NODE REJOIN successful"));
log_detail("%s", follow_output.data);
termPQExpBuffer(&follow_output);
} }
/* /*

View File

@@ -1226,6 +1226,9 @@ do_standby_follow(void)
int timer; int timer;
PQExpBufferData follow_output;
bool success;
log_verbose(LOG_DEBUG, "do_standby_follow()"); log_verbose(LOG_DEBUG, "do_standby_follow()");
@@ -1268,7 +1271,38 @@ do_standby_follow(void)
get_node_record(primary_conn, primary_id, &primary_node_record); get_node_record(primary_conn, primary_id, &primary_node_record);
do_standby_follow_internal(primary_conn, &primary_node_record); initPQExpBuffer(&follow_output);
success = do_standby_follow_internal(
primary_conn,
&primary_node_record,
&follow_output);
create_event_notification(
primary_conn,
&config_file_options,
config_file_options.node_id,
"standby_follow",
success,
follow_output.data);
PQfinish(primary_conn);
if (success == false)
{
log_notice(_("STANDBY FOLLOW failed"));
log_detail("%s", follow_output.data);
termPQExpBuffer(&follow_output);
exit(ERR_DB_QUERY);
}
log_notice(_("STANDBY FOLLOW successful"));
log_detail("%s", follow_output.data);
termPQExpBuffer(&follow_output);
return;
} }
@@ -1276,8 +1310,8 @@ do_standby_follow(void)
* Perform the actuall "follow" operation; this is executed by * Perform the actuall "follow" operation; this is executed by
* "node rejoin" too. * "node rejoin" too.
*/ */
void bool
do_standby_follow_internal(PGconn *primary_conn, t_node_info *primary_node_record) do_standby_follow_internal(PGconn *primary_conn, t_node_info *primary_node_record, PQExpBufferData *output)
{ {
t_node_info local_node_record = T_NODE_INFO_INITIALIZER; t_node_info local_node_record = T_NODE_INFO_INITIALIZER;
int original_upstream_node_id = UNKNOWN_NODE_ID; int original_upstream_node_id = UNKNOWN_NODE_ID;
@@ -1285,7 +1319,6 @@ do_standby_follow_internal(PGconn *primary_conn, t_node_info *primary_node_recor
int r; int r;
RecordStatus record_status; RecordStatus record_status;
PQExpBufferData event_details;
char *errmsg = NULL; char *errmsg = NULL;
@@ -1315,28 +1348,16 @@ do_standby_follow_internal(PGconn *primary_conn, t_node_info *primary_node_recor
{ {
int primary_server_version_num = get_server_version(primary_conn, NULL); int primary_server_version_num = get_server_version(primary_conn, NULL);
initPQExpBuffer(&event_details);
if (create_replication_slot(primary_conn, if (create_replication_slot(primary_conn,
local_node_record.slot_name, local_node_record.slot_name,
primary_server_version_num, primary_server_version_num,
&event_details) == false) output) == false)
{ {
log_error("%s", event_details.data); log_error("%s", output->data);
create_event_notification( return false;
primary_conn,
&config_file_options,
config_file_options.node_id,
"standby_follow",
false,
event_details.data);
PQfinish(primary_conn);
exit(ERR_DB_QUERY);
} }
termPQExpBuffer(&event_details);
} }
@@ -1477,34 +1498,19 @@ do_standby_follow_internal(PGconn *primary_conn, t_node_info *primary_node_recor
primary_node_record->node_id, primary_node_record->node_id,
true) == false) true) == false)
{ {
log_error(_("unable to update upstream node")); appendPQExpBuffer(output,
PQfinish(primary_conn); _("unable to update upstream node"));
return false;
exit(ERR_BAD_CONFIG);
} }
// XXX return to caller
log_notice(_("STANDBY FOLLOW successful"));
initPQExpBuffer(&event_details); appendPQExpBuffer(output,
appendPQExpBuffer(&event_details,
_("node %i is now attached to node %i"), _("node %i is now attached to node %i"),
config_file_options.node_id, primary_node_record->node_id); config_file_options.node_id,
primary_node_record->node_id);
create_event_notification(primary_conn,
&config_file_options,
config_file_options.node_id,
"standby_follow",
true,
event_details.data);
log_detail("%s", event_details.data); return true;
termPQExpBuffer(&event_details);
PQfinish(primary_conn);
return;
} }

View File

@@ -11,9 +11,10 @@ extern void do_standby_register(void);
extern void do_standby_unregister(void); extern void do_standby_unregister(void);
extern void do_standby_promote(void); extern void do_standby_promote(void);
extern void do_standby_follow(void); extern void do_standby_follow(void);
extern void do_standby_follow_internal(PGconn *primary_conn, t_node_info *primary_node_record);
extern void do_standby_switchover(void); extern void do_standby_switchover(void);
extern bool do_standby_follow_internal(PGconn *primary_conn, t_node_info *primary_node_record, PQExpBufferData *output);
#endif /* _REPMGR_ACTION_STANDBY_H_ */ #endif /* _REPMGR_ACTION_STANDBY_H_ */