From 63d83cd85db7dd82487edcb7552d5a03d24acc82 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Wed, 11 Mar 2015 15:18:55 +0200 Subject: [PATCH] Monitor API 2.0.0 implemented. --- CMakeLists.txt | 1 + server/core/config.c | 18 +----- server/core/gateway.c | 2 +- server/core/monitor.c | 64 ++----------------- server/core/poll.c | 2 +- server/core/test/testhash.c | 2 +- server/include/{config.h => maxconfig.h} | 0 server/include/monitor.h | 11 +--- server/include/service.h | 2 +- server/modules/monitor/galera_mon.c | 24 ++++--- server/modules/monitor/mm_mon.c | 25 ++++---- server/modules/monitor/mysql_mon.c | 25 ++++---- server/modules/monitor/ndbcluster_mon.c | 17 ++--- server/modules/routing/debugcmd.c | 4 +- server/modules/routing/maxinfo/maxinfo_exec.c | 2 +- 15 files changed, 66 insertions(+), 133 deletions(-) rename server/include/{config.h => maxconfig.h} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ba32df44..ed14ca23b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,6 +118,7 @@ include_directories(utils) include_directories(log_manager) include_directories(query_classifier) include_directories(server/include) +include_directories(server/include/maxscale) include_directories(server/inih) include_directories(server/modules/include) include_directories(${CMAKE_BINARY_DIR}/server/include) diff --git a/server/core/config.c b/server/core/config.c index d42bdffeb..3af8f5caa 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include #include #include @@ -895,26 +895,12 @@ int error_count = 0; gateway.id = getpid(); } - monitorStart(obj->element,obj->parameters) - /* add the maxscale-id to monitor data */ - monitorSetId(obj->element, gateway.id); + monitorStart(obj->element,obj->parameters); /* set monitor interval */ if (interval > 0) monitorSetInterval(obj->element, interval); - /* set replication heartbeat */ - if(replication_heartbeat == 1) - monitorSetReplicationHeartbeat(obj->element, replication_heartbeat); - - /* detect stale master */ - if(detect_stale_master == 1) - monitorDetectStaleMaster(obj->element, detect_stale_master); - - /* disable master failback */ - if(disable_master_failback == 1) - monitorDisableMasterFailback(obj->element, disable_master_failback); - /* set timeouts */ if (connect_timeout > 0) monitorSetNetworkTimeout(obj->element, MONITOR_CONNECT_TIMEOUT, connect_timeout); diff --git a/server/core/gateway.c b/server/core/gateway.c index 5034c4ffd..3ac45e34e 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -53,7 +53,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/server/core/monitor.c b/server/core/monitor.c index 8ef9a1396..ed46978ac 100644 --- a/server/core/monitor.c +++ b/server/core/monitor.c @@ -78,8 +78,10 @@ MONITOR *mon; free(mon); return NULL; } +/* mon->handle = (*mon->module->startMonitor)(NULL); mon->state = MONITOR_STATE_RUNNING; +*/ spinlock_acquire(&monLock); mon->next = allMonitors; @@ -125,9 +127,9 @@ MONITOR *ptr; * @param monitor The Monitor that should be started */ void -monitorStart(MONITOR *monitor) +monitorStart(MONITOR *monitor, void* params) { - monitor->handle = (*monitor->module->startMonitor)(monitor->handle); + monitor->handle = (*monitor->module->startMonitor)(monitor->handle,params); monitor->state = MONITOR_STATE_RUNNING; } @@ -279,22 +281,6 @@ MONITOR *ptr; return ptr; } - -/** - * Set the id of the monitor. - * - * @param mon The monitor instance - * @param id The id for the monitor - */ - -void -monitorSetId(MONITOR *mon, unsigned long id) -{ - if (mon->module->defaultId != NULL) { - mon->module->defaultId(mon->handle, id); - } -} - /** * Set the monitor sampling interval. * @@ -310,48 +296,6 @@ monitorSetInterval (MONITOR *mon, unsigned long interval) } } -/** - * Enable Replication Heartbeat support in monitor. - * - * @param mon The monitor instance - * @param enable The enabling value is 1, 0 turns it off - */ -void -monitorSetReplicationHeartbeat(MONITOR *mon, int enable) -{ - if (mon->module->replicationHeartbeat != NULL) { - mon->module->replicationHeartbeat(mon->handle, enable); - } -} - -/** - * Enable Stale Master assignement. - * - * @param mon The monitor instance - * @param enable The enabling value is 1, 0 turns it off - */ -void -monitorDetectStaleMaster(MONITOR *mon, int enable) -{ - if (mon->module->detectStaleMaster != NULL) { - mon->module->detectStaleMaster(mon->handle, enable); - } -} - -/** - * Disable Master Failback - * - * @param mon The monitor instance - * @param disable The value 1 disable the failback, 0 keeps it - */ -void -monitorDisableMasterFailback(MONITOR *mon, int disable) -{ - if (mon->module->disableMasterFailback != NULL) { - mon->module->disableMasterFailback(mon->handle, disable); - } -} - /** * Set Monitor timeouts for connect/read/write * diff --git a/server/core/poll.c b/server/core/poll.c index a6e3035dc..6862e7204 100644 --- a/server/core/poll.c +++ b/server/core/poll.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/server/core/test/testhash.c b/server/core/test/testhash.c index 776c8d93a..60f759839 100644 --- a/server/core/test/testhash.c +++ b/server/core/test/testhash.c @@ -33,7 +33,7 @@ #include #include -#include "../../include/hashtable.h" +#include static void read_lock(HASHTABLE *table) diff --git a/server/include/config.h b/server/include/maxconfig.h similarity index 100% rename from server/include/config.h rename to server/include/maxconfig.h diff --git a/server/include/monitor.h b/server/include/monitor.h index 72e09f1b5..5c76a4afa 100644 --- a/server/include/monitor.h +++ b/server/include/monitor.h @@ -73,22 +73,15 @@ typedef struct { void (*unregisterServer)(void *, SERVER *); void (*defaultUser)(void *, char *, char *); void (*diagnostics)(DCB *, void *); - void (*setInterval)(void *, size_t); void (*setNetworkTimeout)(void *, int, int); - - void (*defaultId)(void *, unsigned long); - - void (*replicationHeartbeat)(void *, int); - void (*detectStaleMaster)(void *, int); - void (*disableMasterFailback)(void *, int); } MONITOR_OBJECT; /** * The monitor API version number. Any change to the monitor module API * must change these versions usign the rules defined in modinfo.h */ -#define MONITOR_VERSION {1, 0, 0} +#define MONITOR_VERSION {2, 0, 0} /** Monitor's poll frequency */ #define MON_BASE_INTERVAL_MS 100 @@ -137,7 +130,7 @@ extern MONITOR *monitor_find(char *); extern void monitorAddServer(MONITOR *, SERVER *); extern void monitorAddUser(MONITOR *, char *, char *); extern void monitorStop(MONITOR *); -extern void monitorStart(MONITOR *); +extern void monitorStart(MONITOR *, void*); extern void monitorStopAll(); extern void monitorShowAll(DCB *); extern void monitorShow(DCB *, MONITOR *); diff --git a/server/include/service.h b/server/include/service.h index 6347b7b59..8b55ce32b 100644 --- a/server/include/service.h +++ b/server/include/service.h @@ -25,7 +25,7 @@ #include #include #include -#include "config.h" +#include /** * @file service.h diff --git a/server/modules/monitor/galera_mon.c b/server/modules/monitor/galera_mon.c index ad35e6e3e..dff68c217 100644 --- a/server/modules/monitor/galera_mon.c +++ b/server/modules/monitor/galera_mon.c @@ -49,6 +49,7 @@ #include #include #include +#include /** Defined in log_manager.cc */ extern int lm_enabled_logfiles_bitmask; @@ -66,7 +67,7 @@ MODULE_INFO info = { "A Galera cluster monitor" }; -static void *startMonitor(void *); +static void *startMonitor(void *,void*); static void stopMonitor(void *); static void registerServer(void *, SERVER *); static void unregisterServer(void *, SERVER *); @@ -88,11 +89,7 @@ static MONITOR_OBJECT MyObject = { defaultUsers, diagnostics, setInterval, - setNetworkTimeout, - NULL, - NULL, - NULL, - disableMasterFailback + setNetworkTimeout }; /** @@ -141,10 +138,10 @@ GetModuleObject() * @return A handle to use when interacting with the monitor */ static void * -startMonitor(void *arg) +startMonitor(void *arg,void* opt) { MYSQL_MONITOR *handle; - +CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt; if (arg != NULL) { handle = (MYSQL_MONITOR *)arg; @@ -158,7 +155,7 @@ MYSQL_MONITOR *handle; handle->shutdown = 0; handle->defaultUser = NULL; handle->defaultPasswd = NULL; - handle->id = MONITOR_DEFAULT_ID; + handle->id = config_get_gateway_id(); handle->interval = MONITOR_INTERVAL; handle->disableMasterFailback = 0; handle->master = NULL; @@ -167,6 +164,15 @@ MYSQL_MONITOR *handle; handle->write_timeout=DEFAULT_WRITE_TIMEOUT; spinlock_init(&handle->lock); } + + + while(params) + { + if(!strcmp(params->name,"disable_master_failback")) + handle->disableMasterFailback = config_truth_value(params->value); + params = params->next; + } + handle->tid = (THREAD)thread_start(monitorMain, handle); return handle; } diff --git a/server/modules/monitor/mm_mon.c b/server/modules/monitor/mm_mon.c index d79e7fc91..5e9bdd542 100644 --- a/server/modules/monitor/mm_mon.c +++ b/server/modules/monitor/mm_mon.c @@ -41,7 +41,7 @@ #include #include #include - +#include /** Defined in log_manager.cc */ extern int lm_enabled_logfiles_bitmask; extern size_t log_ses_count[]; @@ -58,7 +58,7 @@ MODULE_INFO info = { "A MySQL Multi Master monitor" }; -static void *startMonitor(void *); +static void *startMonitor(void *,void*); static void stopMonitor(void *); static void registerServer(void *, SERVER *); static void unregisterServer(void *, SERVER *); @@ -79,12 +79,7 @@ static MONITOR_OBJECT MyObject = { unregisterServer, defaultUser, diagnostics, - setInterval, - NULL, - NULL, - NULL, - detectStaleMaster, - NULL + setInterval }; /** @@ -134,10 +129,10 @@ GetModuleObject() * @return A handle to use when interacting with the monitor */ static void * -startMonitor(void *arg) +startMonitor(void *arg,void* opt) { MYSQL_MONITOR *handle; - +CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt; if (arg) { handle = arg; /* Must be a restart */ @@ -151,13 +146,21 @@ MYSQL_MONITOR *handle; handle->shutdown = 0; handle->defaultUser = NULL; handle->defaultPasswd = NULL; - handle->id = MONITOR_DEFAULT_ID; + handle->id = config_get_gateway_id(); handle->interval = MONITOR_INTERVAL; handle->replicationHeartbeat = 0; handle->detectStaleMaster = 0; handle->master = NULL; spinlock_init(&handle->lock); } + + while(params) + { + if(!strcmp(params->name,"detect_stale_master")) + handle->detectStaleMaster = config_truth_value(params->value); + params = params->next; + } + handle->tid = (THREAD)thread_start(monitorMain, handle); return handle; } diff --git a/server/modules/monitor/mysql_mon.c b/server/modules/monitor/mysql_mon.c index c4a900704..9945086fb 100644 --- a/server/modules/monitor/mysql_mon.c +++ b/server/modules/monitor/mysql_mon.c @@ -63,8 +63,7 @@ #include #include #include - -#include "config.h" +#include /** Defined in log_manager.cc */ extern int lm_enabled_logfiles_bitmask; @@ -82,7 +81,7 @@ MODULE_INFO info = { "A MySQL Master/Slave replication monitor" }; -static void *startMonitor(void *); +static void *startMonitor(void *,void*); static void stopMonitor(void *); static void registerServer(void *, SERVER *); static void unregisterServer(void *, SERVER *); @@ -90,8 +89,6 @@ static void defaultUser(void *, char *, char *); static void diagnostics(DCB *, void *); static void setInterval(void *, size_t); static void defaultId(void *, unsigned long); -static void replicationHeartbeat(void *, int); -static void detectStaleMaster(void *, int); static void setNetworkTimeout(void *, int, int); static bool mon_status_changed(MONITOR_SERVERS* mon_srv); static bool mon_print_fail_status(MONITOR_SERVERS* mon_srv); @@ -112,11 +109,7 @@ static MONITOR_OBJECT MyObject = { defaultUser, diagnostics, setInterval, - setNetworkTimeout, - defaultId, - replicationHeartbeat, - detectStaleMaster, - NULL + setNetworkTimeout }; /** @@ -183,7 +176,7 @@ CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt; handle->shutdown = 0; handle->defaultUser = NULL; handle->defaultPasswd = NULL; - handle->id = MONITOR_DEFAULT_ID; + handle->id = config_get_gateway_id(); handle->interval = MONITOR_INTERVAL; handle->replicationHeartbeat = 0; handle->detectStaleMaster = 0; @@ -193,6 +186,16 @@ CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt; handle->write_timeout=DEFAULT_WRITE_TIMEOUT; spinlock_init(&handle->lock); } + + while(params) + { + if(!strcmp(params->name,"detect_stale_master")) + handle->detectStaleMaster = config_truth_value(params->value); + else if(!strcmp(params->name,"detect_replication_lag")) + handle->replicationHeartbeat = config_truth_value(params->value); + params = params->next; + } + handle->tid = (THREAD)thread_start(monitorMain, handle); return handle; } diff --git a/server/modules/monitor/ndbcluster_mon.c b/server/modules/monitor/ndbcluster_mon.c index 52389737d..c146d3f09 100644 --- a/server/modules/monitor/ndbcluster_mon.c +++ b/server/modules/monitor/ndbcluster_mon.c @@ -42,7 +42,7 @@ #include #include #include - +#include /** Defined in log_manager.cc */ extern int lm_enabled_logfiles_bitmask; extern size_t log_ses_count[]; @@ -59,7 +59,7 @@ MODULE_INFO info = { "A MySQL cluster SQL node monitor" }; -static void *startMonitor(void *); +static void *startMonitor(void *,void*); static void stopMonitor(void *); static void registerServer(void *, SERVER *); static void unregisterServer(void *, SERVER *); @@ -76,11 +76,7 @@ static MONITOR_OBJECT MyObject = { defaultUsers, diagnostics, setInterval, - setNetworkTimeout, - NULL, - NULL, - NULL, - NULL + setNetworkTimeout }; /** @@ -129,10 +125,10 @@ GetModuleObject() * @return A handle to use when interacting with the monitor */ static void * -startMonitor(void *arg) +startMonitor(void *arg,void* opt) { MYSQL_MONITOR *handle; - +CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt; if (arg != NULL) { handle = (MYSQL_MONITOR *)arg; @@ -146,13 +142,14 @@ MYSQL_MONITOR *handle; handle->shutdown = 0; handle->defaultUser = NULL; handle->defaultPasswd = NULL; - handle->id = MONITOR_DEFAULT_ID; + handle->id = config_get_gateway_id(); handle->interval = MONITOR_INTERVAL; handle->connect_timeout=DEFAULT_CONNECT_TIMEOUT; handle->read_timeout=DEFAULT_READ_TIMEOUT; handle->write_timeout=DEFAULT_WRITE_TIMEOUT; spinlock_init(&handle->lock); } + handle->tid = (THREAD)thread_start(monitorMain, handle); return handle; } diff --git a/server/modules/routing/debugcmd.c b/server/modules/routing/debugcmd.c index 253647786..b4a13167f 100644 --- a/server/modules/routing/debugcmd.c +++ b/server/modules/routing/debugcmd.c @@ -63,7 +63,7 @@ #include #include #include -#include +#include #include #include #include @@ -1195,7 +1195,7 @@ shutdown_monitor(DCB *dcb, MONITOR *monitor) static void restart_monitor(DCB *dcb, MONITOR *monitor) { - monitorStart(monitor); + monitorStart(monitor, NULL); } /** diff --git a/server/modules/routing/maxinfo/maxinfo_exec.c b/server/modules/routing/maxinfo/maxinfo_exec.c index cced4bec5..6257228f6 100644 --- a/server/modules/routing/maxinfo/maxinfo_exec.c +++ b/server/modules/routing/maxinfo/maxinfo_exec.c @@ -47,7 +47,7 @@ #include #include #include -#include +#include extern int lm_enabled_logfiles_bitmask; extern size_t log_ses_count[];