From d4008f7b28ad248f79d82e7b485ec613d70c73dd Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Fri, 4 May 2018 10:02:06 +0300 Subject: [PATCH] MXS-1848 Introduce a specific monitor type Instead of using void there's now a MXS_SPECIFIC_MONITOR struct from which monitor specific types can be derived. This change does not bring about other benefits than a bit of clarity but this is the first step in clearing up the monitor API. --- include/maxscale/monitor.h | 15 ++++++++++++--- server/modules/monitor/auroramon/auroramon.cc | 6 +++--- server/modules/monitor/galeramon/galeramon.cc | 5 +++-- server/modules/monitor/galeramon/galeramon.h | 8 ++------ server/modules/monitor/grmon/grmon.cc | 4 ++-- server/modules/monitor/mariadbmon/mariadbmon.cc | 3 ++- server/modules/monitor/mariadbmon/mariadbmon.hh | 2 +- server/modules/monitor/mmmon/mmmon.cc | 4 ++-- server/modules/monitor/mmmon/mmmon.h | 8 ++------ .../monitor/ndbclustermon/ndbclustermon.cc | 5 +++-- .../modules/monitor/ndbclustermon/ndbclustermon.h | 4 ++-- 11 files changed, 34 insertions(+), 30 deletions(-) diff --git a/include/maxscale/monitor.h b/include/maxscale/monitor.h index acffd762d..e3671f1b6 100644 --- a/include/maxscale/monitor.h +++ b/include/maxscale/monitor.h @@ -31,6 +31,14 @@ MXS_BEGIN_DECLS struct mxs_monitor; typedef struct mxs_monitor MXS_MONITOR; +/** + * An opaque type from which types specific for a particular + * monitor can be derived. + */ +typedef struct mxs_specific_monitor +{ +} MXS_SPECIFIC_MONITOR; + /** * @verbatim * The "module object" structure for a backend monitor module @@ -68,7 +76,8 @@ typedef struct mxs_monitor_object * * @return Pointer to the monitor specific data, stored in @c monitor->handle */ - void *(*startMonitor)(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER *params); + MXS_SPECIFIC_MONITOR *(*startMonitor)(MXS_MONITOR *monitor, + const MXS_CONFIG_PARAMETER *params); /** * @brief Stop the monitor @@ -95,7 +104,7 @@ typedef struct mxs_monitor_object * The monitor API version number. Any change to the monitor module API * must change these versions using the rules defined in modinfo.h */ -#define MXS_MONITOR_VERSION {3, 1, 0} +#define MXS_MONITOR_VERSION {4, 0, 0} /** * Specifies capabilities specific for monitor. @@ -211,7 +220,7 @@ struct mxs_monitor */ MXS_MONITOR_OBJECT *module; /**< The "monitor object" */ char *module_name; /**< Name of the monitor module */ - void *handle; /**< Handle returned from startMonitor */ + MXS_SPECIFIC_MONITOR *handle; /**< Handle returned from startMonitor */ size_t interval; /**< The monitor interval */ volatile bool server_pending_changes; /**< Are there any pending changes to a server? diff --git a/server/modules/monitor/auroramon/auroramon.cc b/server/modules/monitor/auroramon/auroramon.cc index b6ae7591e..81c574399 100644 --- a/server/modules/monitor/auroramon/auroramon.cc +++ b/server/modules/monitor/auroramon/auroramon.cc @@ -25,14 +25,14 @@ #include #include -typedef struct aurora_monitor +struct AURORA_MONITOR : public MXS_SPECIFIC_MONITOR { bool shutdown; /**< True if the monitor is stopped */ THREAD thread; /**< Monitor thread */ char* script; /**< Launchable script */ uint64_t events; /**< Enabled monitor events */ MXS_MONITOR* monitor; -} AURORA_MONITOR; +}; /** * @brief Update the status of a server @@ -186,7 +186,7 @@ static void auroramon_free(AURORA_MONITOR *handle) * @param opt The configuration parameters for this monitor * @return Monitor handle */ -static void * +static MXS_SPECIFIC_MONITOR * startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params) { AURORA_MONITOR *handle = static_cast(mon->handle); diff --git a/server/modules/monitor/galeramon/galeramon.cc b/server/modules/monitor/galeramon/galeramon.cc index e64a780bb..1a820c616 100644 --- a/server/modules/monitor/galeramon/galeramon.cc +++ b/server/modules/monitor/galeramon/galeramon.cc @@ -30,7 +30,8 @@ static void monitorMain(void *); /** Log a warning when a bad 'wsrep_local_index' is found */ static bool warn_erange_on_local_index = true; -static void *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *params); +static MXS_SPECIFIC_MONITOR *startMonitor(MXS_MONITOR *, + const MXS_CONFIG_PARAMETER *params); static void stopMonitor(MXS_MONITOR *); static void diagnostics(DCB *, const MXS_MONITOR *); static json_t* diagnostics_json(const MXS_MONITOR *); @@ -119,7 +120,7 @@ MXS_MODULE* MXS_CREATE_MODULE() * * @return A handle to use when interacting with the monitor */ -static void * +static MXS_SPECIFIC_MONITOR * startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params) { GALERA_MONITOR *handle = static_cast(mon->handle); diff --git a/server/modules/monitor/galeramon/galeramon.h b/server/modules/monitor/galeramon/galeramon.h index b5ea9d7a4..d86a4b846 100644 --- a/server/modules/monitor/galeramon/galeramon.h +++ b/server/modules/monitor/galeramon/galeramon.h @@ -41,8 +41,6 @@ #include #include -MXS_BEGIN_DECLS - /** * Galera Variables and server reference for each * monitored node that could be part of cluster. @@ -76,7 +74,7 @@ typedef struct galera_cluster_info /** * The handle for an instance of a Galera Monitor module */ -typedef struct +struct GALERA_MONITOR : public MXS_SPECIFIC_MONITOR { THREAD thread; /**< Monitor thread */ int shutdown; /**< Flag to shutdown the monitor thread */ @@ -96,8 +94,6 @@ typedef struct HASHTABLE *galera_nodes_info; /**< Contains Galera Cluster variables of all nodes */ GALERA_CLUSTER_INFO cluster_info; /**< Contains Galera cluster info */ MXS_MONITOR* monitor; -} GALERA_MONITOR; - -MXS_END_DECLS +}; #endif diff --git a/server/modules/monitor/grmon/grmon.cc b/server/modules/monitor/grmon/grmon.cc index 78d0a38f4..0ca3f8328 100644 --- a/server/modules/monitor/grmon/grmon.cc +++ b/server/modules/monitor/grmon/grmon.cc @@ -30,7 +30,7 @@ /** * The instance of a Group Replication Monitor */ -struct GRMon +struct GRMon : public MXS_SPECIFIC_MONITOR { GRMon(const GRMon&); GRMon& operator&(const GRMon&); @@ -99,7 +99,7 @@ void GRMon::stop() * * @return A handle to use when interacting with the monitor */ -static void * +static MXS_SPECIFIC_MONITOR * startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params) { return GRMon::create(mon, params); diff --git a/server/modules/monitor/mariadbmon/mariadbmon.cc b/server/modules/monitor/mariadbmon/mariadbmon.cc index f1c340297..130052e35 100644 --- a/server/modules/monitor/mariadbmon/mariadbmon.cc +++ b/server/modules/monitor/mariadbmon/mariadbmon.cc @@ -912,7 +912,8 @@ bool MariaDBMonitor::check_sql_files() * @param params Configuration parameters * @return A pointer to MariaDBMonitor specific data. Should be stored in MXS_MONITOR's "handle"-field. */ -static void* startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params) +static MXS_SPECIFIC_MONITOR* startMonitor(MXS_MONITOR *monitor, + const MXS_CONFIG_PARAMETER* params) { return MariaDBMonitor::start(monitor, params); } diff --git a/server/modules/monitor/mariadbmon/mariadbmon.hh b/server/modules/monitor/mariadbmon/mariadbmon.hh index 32677f35e..b93a3e37b 100644 --- a/server/modules/monitor/mariadbmon/mariadbmon.hh +++ b/server/modules/monitor/mariadbmon/mariadbmon.hh @@ -35,7 +35,7 @@ typedef std::tr1::unordered_map ServerInf typedef std::vector ServerArray; // MariaDB Monitor instance data -class MariaDBMonitor +class MariaDBMonitor : public MXS_SPECIFIC_MONITOR { private: MariaDBMonitor(const MariaDBMonitor&); diff --git a/server/modules/monitor/mmmon/mmmon.cc b/server/modules/monitor/mmmon/mmmon.cc index 88538b1dd..ea8372431 100644 --- a/server/modules/monitor/mmmon/mmmon.cc +++ b/server/modules/monitor/mmmon/mmmon.cc @@ -38,7 +38,7 @@ MXS_MODULE info = }; /*lint +e14 */ -static void *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *); +static MXS_SPECIFIC_MONITOR *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *); static void stopMonitor(MXS_MONITOR *); static void diagnostics(DCB *, const MXS_MONITOR *); static json_t* diagnostics_json(const MXS_MONITOR *); @@ -114,7 +114,7 @@ MXS_MODULE* MXS_CREATE_MODULE() * @param arg The current handle - NULL if first start * @return A handle to use when interacting with the monitor */ -static void * +static MXS_SPECIFIC_MONITOR * startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params) { MM_MONITOR *handle = static_cast(mon->handle); diff --git a/server/modules/monitor/mmmon/mmmon.h b/server/modules/monitor/mmmon/mmmon.h index 679e9dc2b..8436b6004 100644 --- a/server/modules/monitor/mmmon/mmmon.h +++ b/server/modules/monitor/mmmon/mmmon.h @@ -33,12 +33,10 @@ * @file mmmon.h - The Multi-Master monitor */ -MXS_BEGIN_DECLS - /** * The handle for an instance of a Multi-Master Monitor module */ -typedef struct +struct MM_MONITOR : public MXS_SPECIFIC_MONITOR { THREAD thread; /**< Monitor thread */ int shutdown; /**< Flag to shutdown the monitor thread */ @@ -49,8 +47,6 @@ typedef struct char* script; /*< Script to call when state changes occur on servers */ uint64_t events; /*< enabled events */ MXS_MONITOR* monitor; -} MM_MONITOR; - -MXS_END_DECLS +}; #endif diff --git a/server/modules/monitor/ndbclustermon/ndbclustermon.cc b/server/modules/monitor/ndbclustermon/ndbclustermon.cc index 9ea98774d..24633567e 100644 --- a/server/modules/monitor/ndbclustermon/ndbclustermon.cc +++ b/server/modules/monitor/ndbclustermon/ndbclustermon.cc @@ -30,7 +30,8 @@ static void monitorMain(void *); /*lint +e14 */ -static void *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *params); +static MXS_SPECIFIC_MONITOR *startMonitor(MXS_MONITOR *, + const MXS_CONFIG_PARAMETER *params); static void stopMonitor(MXS_MONITOR *); static void diagnostics(DCB *, const MXS_MONITOR *); static json_t* diagnostics_json(const MXS_MONITOR *); @@ -105,7 +106,7 @@ MXS_MODULE* MXS_CREATE_MODULE() * * @return A handle to use when interacting with the monitor */ -static void * +static MXS_SPECIFIC_MONITOR * startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params) { NDBC_MONITOR *handle = static_cast(mon->handle); diff --git a/server/modules/monitor/ndbclustermon/ndbclustermon.h b/server/modules/monitor/ndbclustermon/ndbclustermon.h index dd1e10d5d..92a4ecc46 100644 --- a/server/modules/monitor/ndbclustermon/ndbclustermon.h +++ b/server/modules/monitor/ndbclustermon/ndbclustermon.h @@ -18,7 +18,7 @@ #include // The handle for an instance of a NDB Cluster Monitor module -typedef struct +struct NDBC_MONITOR : public MXS_SPECIFIC_MONITOR { THREAD thread; /**< Monitor thread */ SPINLOCK lock; /**< The monitor spinlock */ @@ -29,4 +29,4 @@ typedef struct MXS_MONITORED_SERVER *master; /**< Master server for MySQL Master/Slave replication */ char* script; /*< Script to call when state changes occur on servers */ MXS_MONITOR* monitor; -} NDBC_MONITOR; +};