From 1aba13177be93f2b8fb05219692ff1d1f1f3cd91 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 11 May 2015 19:12:45 +0300 Subject: [PATCH] Added ndbclustermon and mmmon headers. --- server/core/mon_exec.c | 1 + server/include/mon_exec.h | 1 + server/modules/monitor/CMakeLists.txt | 4 +- server/modules/monitor/galeramon.c | 1 + server/modules/monitor/galeramon.h | 1 - server/modules/monitor/{mm_mon.c => mmmon.c} | 89 +++---------------- server/modules/monitor/mmmon.h | 51 +++++++++++ server/modules/monitor/mysqlmon.h | 2 +- .../{ndbcluster_mon.c => ndbclustermon.c} | 1 + server/modules/monitor/ndbclustermon.h | 55 ++++++++++++ 10 files changed, 127 insertions(+), 79 deletions(-) rename server/modules/monitor/{mm_mon.c => mmmon.c} (90%) create mode 100644 server/modules/monitor/mmmon.h rename server/modules/monitor/{ndbcluster_mon.c => ndbclustermon.c} (99%) create mode 100644 server/modules/monitor/ndbclustermon.h diff --git a/server/core/mon_exec.c b/server/core/mon_exec.c index bae0d31fc..01640bcd6 100644 --- a/server/core/mon_exec.c +++ b/server/core/mon_exec.c @@ -141,6 +141,7 @@ int externcmd_execute(EXTERNCMD* cmd) } else { + cmd->child = pid; cmd->n_exec++; LOGIF(LD,skygw_log_write(LD,"[monitor_exec_cmd] Forked child process %d : %s.",pid,cmd)); } diff --git a/server/include/mon_exec.h b/server/include/mon_exec.h index e1ef7ad37..25390bb82 100644 --- a/server/include/mon_exec.h +++ b/server/include/mon_exec.h @@ -11,6 +11,7 @@ typedef struct extern_cmd_t{ char* parameters[MAXSCALE_EXTCMD_ARG_MAX]; /*< Command arguments */ int n_exec; /*< Number of times executed */ + pid_t child; /*< PID of the child process */ }EXTERNCMD; EXTERNCMD* externcmd_allocate(char* argstr); diff --git a/server/modules/monitor/CMakeLists.txt b/server/modules/monitor/CMakeLists.txt index 8f364fe5b..9f08a5b32 100644 --- a/server/modules/monitor/CMakeLists.txt +++ b/server/modules/monitor/CMakeLists.txt @@ -6,11 +6,11 @@ add_library(galeramon SHARED galeramon.c monitor_common.c) target_link_libraries(galeramon log_manager utils) install(TARGETS galeramon DESTINATION modules) -add_library(ndbclustermon SHARED ndbcluster_mon.c monitor_common.c) +add_library(ndbclustermon SHARED ndbclustermon.c monitor_common.c) target_link_libraries(ndbclustermon log_manager utils) install(TARGETS ndbclustermon DESTINATION modules) if(BUILD_MMMON) - add_library(mmmon SHARED mm_mon.c monitor_common.c) + add_library(mmmon SHARED mmmon.c monitor_common.c) target_link_libraries(mmmon log_manager utils) install(TARGETS mmmon DESTINATION modules) endif() diff --git a/server/modules/monitor/galeramon.c b/server/modules/monitor/galeramon.c index a99ea952b..66ccc28ce 100644 --- a/server/modules/monitor/galeramon.c +++ b/server/modules/monitor/galeramon.c @@ -34,6 +34,7 @@ * 10/11/14 Massimiliano Pinto Added setNetworkTimeout for connect,read,write * 20/04/15 Guillaume Lefranc Added availableWhenDonor feature * 22/04/15 Martin Brampton Addition of disableMasterRoleSetting + * 08/05/15 Markus Makela Addition of launchable scripts * * @endverbatim */ diff --git a/server/modules/monitor/galeramon.h b/server/modules/monitor/galeramon.h index 3a9c41e7f..30b642921 100644 --- a/server/modules/monitor/galeramon.h +++ b/server/modules/monitor/galeramon.h @@ -56,7 +56,6 @@ typedef struct { int shutdown; /**< Flag to shutdown the monitor thread */ int status; /**< Monitor status */ unsigned long id; /**< Monitor ID */ - int detectStaleMaster; /**< Monitor flag for MySQL replication Stale Master detection */ int disableMasterFailback; /**< Monitor flag for Galera Cluster Master failback */ int availableWhenDonor; /**< Monitor flag for Galera Cluster Donor availability */ int disableMasterRoleSetting; /**< Monitor flag to disable setting master role */ diff --git a/server/modules/monitor/mm_mon.c b/server/modules/monitor/mmmon.c similarity index 90% rename from server/modules/monitor/mm_mon.c rename to server/modules/monitor/mmmon.c index 71bf0022b..d4e04d288 100644 --- a/server/modules/monitor/mm_mon.c +++ b/server/modules/monitor/mmmon.c @@ -17,19 +17,20 @@ */ /** - * @file mysql_mon.c - A MySQL Multi Muster cluster monitor + * @file mm_mon.c - A Multi-Master Multi Muster cluster monitor * * @verbatim * Revision History * * Date Who Description * 08/09/14 Massimiliano Pinto Initial implementation + * 08/05/15 Markus Makela Addition of launchable scripts * * @endverbatim */ -#include +#include /** Defined in log_manager.cc */ extern int lm_enabled_logfiles_bitmask; @@ -44,7 +45,7 @@ MODULE_INFO info = { MODULE_API_MONITOR, MODULE_BETA_RELEASE, MONITOR_VERSION, - "A MySQL Multi Master monitor" + "A Multi-Master Multi Master monitor" }; static void *startMonitor(void *,void*); @@ -79,7 +80,7 @@ ModuleInit() { LOGIF(LM, (skygw_log_write( LOGFILE_MESSAGE, - "Initialise the MySQL Monitor module %s.", + "Initialise the Multi-Master Monitor module %s.", version_str))); } @@ -109,7 +110,7 @@ static void * startMonitor(void *arg,void* opt) { MONITOR* mon = (MONITOR*)arg; - MYSQL_MONITOR *handle = mon->handle; + MM_MONITOR *handle = mon->handle; CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt; if (handle) { @@ -117,12 +118,10 @@ startMonitor(void *arg,void* opt) } else { - if ((handle = (MYSQL_MONITOR *)malloc(sizeof(MYSQL_MONITOR))) == NULL) + if ((handle = (MM_MONITOR *)malloc(sizeof(MM_MONITOR))) == NULL) return NULL; handle->shutdown = 0; handle->id = MONITOR_DEFAULT_ID; - handle->replicationHeartbeat = 0; - handle->detectStaleMaster = 0; handle->master = NULL; spinlock_init(&handle->lock); } @@ -157,7 +156,7 @@ startMonitor(void *arg,void* opt) static void stopMonitor(void *arg) { -MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; +MM_MONITOR *handle = (MM_MONITOR *)arg; handle->shutdown = 1; thread_wait((void *)handle->tid); @@ -172,7 +171,7 @@ MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; static void diagnostics(DCB *dcb, void *arg) { MONITOR* mon = (MONITOR*)arg; -MYSQL_MONITOR *handle = (MYSQL_MONITOR *)mon->handle; +MM_MONITOR *handle = (MM_MONITOR *)mon->handle; MONITOR_SERVERS *db; char *sep; @@ -217,7 +216,7 @@ char *sep; static void monitorDatabase(MONITOR* mon, MONITOR_SERVERS *database) { - MYSQL_MONITOR *handle = mon->handle; + MM_MONITOR *handle = mon->handle; MYSQL_ROW row; MYSQL_RES *result; int isslave = 0; @@ -240,7 +239,7 @@ char *server_string; if (SERVER_IN_MAINT(database->server)) return; - /** Store prevous status */ + /** Store previous status */ database->mon_prev_status = database->server->status; if (database->con == NULL || mysql_ping(database->con) != 0) @@ -473,7 +472,7 @@ static void monitorMain(void *arg) { MONITOR* mon = (MONITOR*)arg; -MYSQL_MONITOR *handle = (MYSQL_MONITOR *)mon->handle; +MM_MONITOR *handle = (MM_MONITOR *)mon->handle; MONITOR_SERVERS *ptr; int detect_stale_master = handle->detectStaleMaster; MONITOR_SERVERS *root_master; @@ -612,70 +611,10 @@ static void detectStaleMaster(void *arg, int enable) { MONITOR* mon = (MONITOR*)arg; -MYSQL_MONITOR *handle = (MYSQL_MONITOR *)mon->handle; +MM_MONITOR *handle = (MM_MONITOR *)mon->handle; memcpy(&handle->detectStaleMaster, &enable, sizeof(int)); } -static bool mon_status_changed( - MONITOR_SERVERS* mon_srv) -{ - bool succp; - - if (mon_srv->mon_prev_status != mon_srv->server->status) - { - succp = true; - } - else - { - succp = false; - } - return succp; -} - -static bool mon_print_fail_status( - MONITOR_SERVERS* mon_srv) -{ - bool succp; - int errcount = mon_srv->mon_err_count; - uint8_t modval; - - modval = 1<<(MIN(errcount/10, 7)); - - if (SERVER_IS_DOWN(mon_srv->server) && errcount%modval == 0) - { - succp = true; - } - else - { - succp = false; - } - return succp; -} - -/** - * Set a pending status bit in the monior server - * - * @param server The server to update - * @param bit The bit to clear for the server - */ -static void -monitor_set_pending_status(MONITOR_SERVERS *ptr, int bit) -{ - ptr->pending_status |= bit; -} - -/** - * Clear a pending status bit in the monior server - * - * @param server The server to update - * @param bit The bit to clear for the server - */ -static void -monitor_clear_pending_status(MONITOR_SERVERS *ptr, int bit) -{ - ptr->pending_status &= ~bit; -} - /******* * This function returns the master server * from a set of MySQL Multi Master monitored servers @@ -687,7 +626,7 @@ monitor_clear_pending_status(MONITOR_SERVERS *ptr, int bit) */ static MONITOR_SERVERS *get_current_master(MONITOR *mon) { - MYSQL_MONITOR* handle = mon->handle; + MM_MONITOR* handle = mon->handle; MONITOR_SERVERS *ptr; ptr = mon->databases; diff --git a/server/modules/monitor/mmmon.h b/server/modules/monitor/mmmon.h new file mode 100644 index 000000000..fb035a594 --- /dev/null +++ b/server/modules/monitor/mmmon.h @@ -0,0 +1,51 @@ +#ifndef _MMMON_H +#define _MMMON_H +/* + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright MariaDB Corporation Ab 2015 + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * The handle for an instance of a Multi-Master Monitor module + */ +typedef struct { + SPINLOCK lock; /**< The monitor spinlock */ + pthread_t tid; /**< id of monitor thread */ + int shutdown; /**< Flag to shutdown the monitor thread */ + int status; /**< Monitor status */ + unsigned long id; /**< Monitor ID */ + int detectStaleMaster; /**< Monitor flag for Stale Master detection */ + MONITOR_SERVERS *master; /**< Master server for Master/Slave replication */ + char* script; /*< Script to call when state changes occur on servers */ +} MM_MONITOR; + +#endif diff --git a/server/modules/monitor/mysqlmon.h b/server/modules/monitor/mysqlmon.h index f5d0e2a37..9bd6a2da9 100644 --- a/server/modules/monitor/mysqlmon.h +++ b/server/modules/monitor/mysqlmon.h @@ -49,7 +49,7 @@ * 07/11/14 Massimiliano Pinto Addition of NetworkTimeout: connect, read, write * 20/04/15 Guillaume Lefranc Addition of availableWhenDonor * 22/04/15 Martin Brampton Addition of disableMasterRoleSetting - * 07/05/15 Markus Makela Addition of command execution on Master server failure + * 07/05/15 Markus Makela Addition of command execution on Master server failure * @endverbatim */ diff --git a/server/modules/monitor/ndbcluster_mon.c b/server/modules/monitor/ndbclustermon.c similarity index 99% rename from server/modules/monitor/ndbcluster_mon.c rename to server/modules/monitor/ndbclustermon.c index 6917f414d..8385131e3 100644 --- a/server/modules/monitor/ndbcluster_mon.c +++ b/server/modules/monitor/ndbclustermon.c @@ -25,6 +25,7 @@ * Date Who Description * 25/07/14 Massimiliano Pinto Initial implementation * 10/11/14 Massimiliano Pinto Added setNetworkTimeout for connect,read,write + * 08/05/15 Markus Makela Addition of launchable scripts * * @endverbatim */ diff --git a/server/modules/monitor/ndbclustermon.h b/server/modules/monitor/ndbclustermon.h new file mode 100644 index 000000000..7066a5a4e --- /dev/null +++ b/server/modules/monitor/ndbclustermon.h @@ -0,0 +1,55 @@ +#ifndef _MYSQLMON_H +#define _MYSQLMON_H +/* + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright MariaDB Corporation Ab 2013-2014 + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * @file ndbclustermon.h - The NDB Cluster monitor + * + */ + +/** + * The handle for an instance of a NDB Cluster Monitor module + */ +typedef struct { + SPINLOCK lock; /**< The monitor spinlock */ + pthread_t tid; /**< id of monitor thread */ + int shutdown; /**< Flag to shutdown the monitor thread */ + int status; /**< Monitor status */ + unsigned long id; /**< Monitor ID */ + MONITOR_SERVERS *master; /**< Master server for MySQL Master/Slave replication */ + char* script; /*< Script to call when state changes occur on servers */ +} MYSQL_MONITOR; + +#endif