mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
@@ -35,6 +35,29 @@ do_bdr_node_check(void)
|
|||||||
/* nothing to do at the moment */
|
/* nothing to do at the moment */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
handle_sigint_bdr(SIGNAL_ARGS)
|
||||||
|
{
|
||||||
|
PQExpBufferData event_details;
|
||||||
|
|
||||||
|
initPQExpBuffer(&event_details);
|
||||||
|
|
||||||
|
appendPQExpBuffer(&event_details,
|
||||||
|
"%s signal received",
|
||||||
|
postgres_signal_arg == SIGTERM
|
||||||
|
? "TERM" : "INT");
|
||||||
|
|
||||||
|
create_event_notification(local_conn,
|
||||||
|
&config_file_options,
|
||||||
|
config_file_options.node_id,
|
||||||
|
"repmgrd_shutdown",
|
||||||
|
true,
|
||||||
|
event_details.data);
|
||||||
|
termPQExpBuffer(&event_details);
|
||||||
|
|
||||||
|
terminate(SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
monitor_bdr(void)
|
monitor_bdr(void)
|
||||||
|
|||||||
@@ -22,4 +22,5 @@
|
|||||||
extern void do_bdr_node_check(void);
|
extern void do_bdr_node_check(void);
|
||||||
extern void monitor_bdr(void);
|
extern void monitor_bdr(void);
|
||||||
|
|
||||||
|
extern void handle_sigint_bdr(SIGNAL_ARGS);
|
||||||
#endif /* _REPMGRD_BDR_H_ */
|
#endif /* _REPMGRD_BDR_H_ */
|
||||||
|
|||||||
@@ -85,6 +85,36 @@ static void update_monitoring_history(void);
|
|||||||
static const char * format_failover_state(FailoverState failover_state);
|
static const char * format_failover_state(FailoverState failover_state);
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
handle_sigint_physical(SIGNAL_ARGS)
|
||||||
|
{
|
||||||
|
PGconn *writeable_conn;
|
||||||
|
PQExpBufferData event_details;
|
||||||
|
|
||||||
|
initPQExpBuffer(&event_details);
|
||||||
|
|
||||||
|
appendPQExpBuffer(&event_details,
|
||||||
|
"%s signal received",
|
||||||
|
postgres_signal_arg == SIGTERM
|
||||||
|
? "TERM" : "INT");
|
||||||
|
|
||||||
|
if (local_node_info.type == PRIMARY)
|
||||||
|
writeable_conn = local_conn;
|
||||||
|
else
|
||||||
|
writeable_conn = primary_conn;
|
||||||
|
|
||||||
|
create_event_notification(writeable_conn,
|
||||||
|
&config_file_options,
|
||||||
|
config_file_options.node_id,
|
||||||
|
"repmgrd_shutdown",
|
||||||
|
true,
|
||||||
|
event_details.data);
|
||||||
|
|
||||||
|
termPQExpBuffer(&event_details);
|
||||||
|
|
||||||
|
terminate(SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
/* perform some sanity checks on the node's configuration */
|
/* perform some sanity checks on the node's configuration */
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -113,6 +143,14 @@ do_physical_node_check(void)
|
|||||||
log_error(_("this node is marked as inactive and cannot be used as a failover target"));
|
log_error(_("this node is marked as inactive and cannot be used as a failover target"));
|
||||||
log_hint(_("%s"), hint);
|
log_hint(_("%s"), hint);
|
||||||
PQfinish(local_conn);
|
PQfinish(local_conn);
|
||||||
|
|
||||||
|
create_event_notification(NULL,
|
||||||
|
&config_file_options,
|
||||||
|
config_file_options.node_id,
|
||||||
|
"repmgrd_shutdown",
|
||||||
|
false,
|
||||||
|
"node is inactive and cannot be used as a failover target");
|
||||||
|
|
||||||
terminate(ERR_BAD_CONFIG);
|
terminate(ERR_BAD_CONFIG);
|
||||||
|
|
||||||
case FAILOVER_MANUAL:
|
case FAILOVER_MANUAL:
|
||||||
@@ -303,7 +341,7 @@ monitor_streaming_primary(void)
|
|||||||
create_event_notification(NULL,
|
create_event_notification(NULL,
|
||||||
&config_file_options,
|
&config_file_options,
|
||||||
config_file_options.node_id,
|
config_file_options.node_id,
|
||||||
"repmgrd_terminate",
|
"repmgrd_shutdown",
|
||||||
true,
|
true,
|
||||||
event_details.data);
|
event_details.data);
|
||||||
|
|
||||||
@@ -414,15 +452,28 @@ monitor_streaming_primary(void)
|
|||||||
}
|
}
|
||||||
else if (record_status == RECORD_NOT_FOUND)
|
else if (record_status == RECORD_NOT_FOUND)
|
||||||
{
|
{
|
||||||
log_error(_("no metadata record found for this node on current primary %i"), primary_node_id);
|
PQExpBufferData event_details;
|
||||||
|
initPQExpBuffer(&event_details);
|
||||||
|
|
||||||
|
appendPQExpBuffer(&event_details,
|
||||||
|
_("no metadata record found for this node on current primary %i"),
|
||||||
|
primary_node_id);
|
||||||
|
|
||||||
|
log_error("%s", event_details.data);
|
||||||
log_hint(_("check that 'repmgr (primary|standby) register' was executed for this node"));
|
log_hint(_("check that 'repmgr (primary|standby) register' was executed for this node"));
|
||||||
|
|
||||||
PQfinish(new_primary_conn);
|
PQfinish(new_primary_conn);
|
||||||
|
|
||||||
/* add event notification */
|
create_event_notification(NULL,
|
||||||
|
&config_file_options,
|
||||||
|
config_file_options.node_id,
|
||||||
|
"repmgrd_shutdown",
|
||||||
|
false,
|
||||||
|
event_details.data);
|
||||||
|
termPQExpBuffer(&event_details);
|
||||||
|
|
||||||
terminate(ERR_BAD_CONFIG);
|
terminate(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1058,9 +1109,26 @@ monitor_streaming_witness(void)
|
|||||||
|
|
||||||
if (get_primary_node_record(local_conn, &upstream_node_info) == false)
|
if (get_primary_node_record(local_conn, &upstream_node_info) == false)
|
||||||
{
|
{
|
||||||
log_error(_("unable to retrieve record for primary node"));
|
PQExpBufferData event_details;
|
||||||
|
|
||||||
|
initPQExpBuffer(&event_details);
|
||||||
|
|
||||||
|
appendPQExpBuffer(&event_details,
|
||||||
|
_("unable to retrieve record for primary node"));
|
||||||
|
|
||||||
|
log_error("%s", event_details.data);
|
||||||
log_hint(_("execute \"repmgr witness register --force\" to update the witness node "));
|
log_hint(_("execute \"repmgr witness register --force\" to update the witness node "));
|
||||||
PQfinish(local_conn);
|
PQfinish(local_conn);
|
||||||
|
|
||||||
|
create_event_notification(NULL,
|
||||||
|
&config_file_options,
|
||||||
|
config_file_options.node_id,
|
||||||
|
"repmgrd_shutdown",
|
||||||
|
false,
|
||||||
|
event_details.data);
|
||||||
|
|
||||||
|
termPQExpBuffer(&event_details);
|
||||||
|
|
||||||
terminate(ERR_BAD_CONFIG);
|
terminate(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,4 +26,6 @@ void monitor_streaming_standby(void);
|
|||||||
void monitor_streaming_witness(void);
|
void monitor_streaming_witness(void);
|
||||||
void close_connections_physical(void);
|
void close_connections_physical(void);
|
||||||
|
|
||||||
|
void handle_sigint_physical(SIGNAL_ARGS);
|
||||||
|
|
||||||
#endif /* _REPMGRD_PHYSICAL_H_ */
|
#endif /* _REPMGRD_PHYSICAL_H_ */
|
||||||
|
|||||||
25
repmgrd.c
25
repmgrd.c
@@ -73,7 +73,6 @@ static void start_monitoring(void);
|
|||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
static void setup_event_handlers(void);
|
static void setup_event_handlers(void);
|
||||||
static void handle_sighup(SIGNAL_ARGS);
|
static void handle_sighup(SIGNAL_ARGS);
|
||||||
static void handle_sigint(SIGNAL_ARGS);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int calculate_elapsed(instr_time start_time);
|
int calculate_elapsed(instr_time start_time);
|
||||||
@@ -613,11 +612,6 @@ check_and_create_pid_file(const char *pid_file)
|
|||||||
|
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
static void
|
|
||||||
handle_sigint(SIGNAL_ARGS)
|
|
||||||
{
|
|
||||||
terminate(SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* SIGHUP: set flag to re-read config file at next convenient time */
|
/* SIGHUP: set flag to re-read config file at next convenient time */
|
||||||
static void
|
static void
|
||||||
@@ -630,8 +624,23 @@ static void
|
|||||||
setup_event_handlers(void)
|
setup_event_handlers(void)
|
||||||
{
|
{
|
||||||
pqsignal(SIGHUP, handle_sighup);
|
pqsignal(SIGHUP, handle_sighup);
|
||||||
pqsignal(SIGINT, handle_sigint);
|
|
||||||
pqsignal(SIGTERM, handle_sigint);
|
/*
|
||||||
|
* we want to be able to write a "repmgrd_shutdown" event, so delegate
|
||||||
|
* signal handling to the respective replication type handler, as it
|
||||||
|
* will know best which database connection to use
|
||||||
|
*/
|
||||||
|
switch (config_file_options.replication_type)
|
||||||
|
{
|
||||||
|
case REPLICATION_TYPE_BDR:
|
||||||
|
pqsignal(SIGINT, handle_sigint_bdr);
|
||||||
|
pqsignal(SIGTERM, handle_sigint_bdr);
|
||||||
|
break;
|
||||||
|
case REPLICATION_TYPE_PHYSICAL:
|
||||||
|
pqsignal(SIGINT, handle_sigint_physical);
|
||||||
|
pqsignal(SIGTERM, handle_sigint_physical);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user