From e1e59e85d7d5b6b98e616bd6ff191eebcd68e905 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Mon, 20 Aug 2018 16:47:24 +0900 Subject: [PATCH] repmgr: add "cluster_cleanup" event GitHub #492. --- HISTORY | 1 + dbutils.c | 3 +-- doc/appendix-release-notes.sgml | 6 ++++++ doc/event-notifications.sgml | 3 +++ doc/repmgr-cluster-cleanup.sgml | 8 ++++++++ repmgr-action-cluster.c | 31 ++++++++++++++++++++++++++++++- 6 files changed, 49 insertions(+), 3 deletions(-) diff --git a/HISTORY b/HISTORY index a5765a43..ae2c3323 100644 --- a/HISTORY +++ b/HISTORY @@ -3,6 +3,7 @@ repmgr: improve messages emitted during "standby promote" (Ian) repmgr: "standby clone" - don't copy external config files in --dry-run mode; GitHub #491 (Ian) + repmgr: add "cluster_cleanup" event; GitHub #492 (Ian) repmgrd: ensure that sending SIGHUP always results in the log file being reopened; GitHub #485 (Ian) repmgrd: report version number *after* logger initialisation; GitHub #487 (Ian) diff --git a/dbutils.c b/dbutils.c index 13ce238e..424074af 100644 --- a/dbutils.c +++ b/dbutils.c @@ -1760,7 +1760,6 @@ vacuum_table(PGconn *primary_conn, const char *table) res = PQexec(primary_conn, query.data); termPQExpBuffer(&query); - log_debug("%i", (int) PQresultStatus(res)); if (PQresultStatus(res) != PGRES_COMMAND_OK) { success = false; @@ -3336,7 +3335,7 @@ _create_event(PGconn *conn, t_configuration_options *options, int node_id, char */ if (notify_ok == false) { - log_debug(_("Not executing notification script for event type \"%s\""), event); + log_debug(_("not executing notification script for event type \"%s\""), event); return success; } } diff --git a/doc/appendix-release-notes.sgml b/doc/appendix-release-notes.sgml index 87715da6..351f9fd1 100644 --- a/doc/appendix-release-notes.sgml +++ b/doc/appendix-release-notes.sgml @@ -34,6 +34,12 @@ + + + repmgr cluster cleanup: + add cluster_cleanup event. (GitHub #492) + + diff --git a/doc/event-notifications.sgml b/doc/event-notifications.sgml index 7304ba6c..d5318ca7 100644 --- a/doc/event-notifications.sgml +++ b/doc/event-notifications.sgml @@ -193,6 +193,9 @@ node_rejoin + + cluster_cleanup + repmgrd_start diff --git a/doc/repmgr-cluster-cleanup.sgml b/doc/repmgr-cluster-cleanup.sgml index fa60ab66..6c149f03 100644 --- a/doc/repmgr-cluster-cleanup.sgml +++ b/doc/repmgr-cluster-cleanup.sgml @@ -44,6 +44,14 @@ + + Event notifications + + A cluster_cleanup event notification will be generated. + + + + See also diff --git a/repmgr-action-cluster.c b/repmgr-action-cluster.c index 2cbda76b..6c76bfc1 100644 --- a/repmgr-action-cluster.c +++ b/repmgr-action-cluster.c @@ -1332,6 +1332,7 @@ do_cluster_cleanup(void) PGconn *conn = NULL; PGconn *primary_conn = NULL; int entries_to_delete = 0; + PQExpBufferData event_details; conn = establish_db_connection(config_file_options.conninfo, true); @@ -1355,10 +1356,23 @@ do_cluster_cleanup(void) log_debug("at least %i monitoring records for deletion", entries_to_delete); + initPQExpBuffer(&event_details); + if (delete_monitoring_records(primary_conn, runtime_options.keep_history) == false) { - log_error(_("unable to delete monitoring records")); + appendPQExpBuffer(&event_details, + _("unable to delete monitoring records")); + + log_error("%s", event_details.data); log_detail("%s", PQerrorMessage(primary_conn)); + + create_event_notification(primary_conn, + &config_file_options, + config_file_options.node_id, + "cluster_cleanup", + false, + event_details.data); + PQfinish(primary_conn); exit(ERR_DB_QUERY); } @@ -1370,7 +1384,22 @@ do_cluster_cleanup(void) log_detail("%s", PQerrorMessage(primary_conn)); } + appendPQExpBuffer(&event_details, + _("monitoring records deleted")); + if (runtime_options.keep_history > 0) + appendPQExpBuffer(&event_details, + _("; records newer than %i day(s) retained"), + runtime_options.keep_history); + + create_event_notification(primary_conn, + &config_file_options, + config_file_options.node_id, + "cluster_cleanup", + true, + event_details.data); + + termPQExpBuffer(&event_details); PQfinish(primary_conn); if (runtime_options.keep_history > 0)