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.
This commit is contained in:
Johan Wikman
2018-05-04 10:02:06 +03:00
parent 1f6cc6db8a
commit d4008f7b28
11 changed files with 34 additions and 30 deletions

View File

@ -31,6 +31,14 @@ MXS_BEGIN_DECLS
struct mxs_monitor; struct mxs_monitor;
typedef struct mxs_monitor 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 * @verbatim
* The "module object" structure for a backend monitor module * 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 * @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 * @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 * The monitor API version number. Any change to the monitor module API
* must change these versions using the rules defined in modinfo.h * 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. * Specifies capabilities specific for monitor.
@ -211,7 +220,7 @@ struct mxs_monitor
*/ */
MXS_MONITOR_OBJECT *module; /**< The "monitor object" */ MXS_MONITOR_OBJECT *module; /**< The "monitor object" */
char *module_name; /**< Name of the monitor module */ 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 */ size_t interval; /**< The monitor interval */
volatile bool server_pending_changes; volatile bool server_pending_changes;
/**< Are there any pending changes to a server? /**< Are there any pending changes to a server?

View File

@ -25,14 +25,14 @@
#include <maxscale/debug.h> #include <maxscale/debug.h>
#include <maxscale/mysql_utils.h> #include <maxscale/mysql_utils.h>
typedef struct aurora_monitor struct AURORA_MONITOR : public MXS_SPECIFIC_MONITOR
{ {
bool shutdown; /**< True if the monitor is stopped */ bool shutdown; /**< True if the monitor is stopped */
THREAD thread; /**< Monitor thread */ THREAD thread; /**< Monitor thread */
char* script; /**< Launchable script */ char* script; /**< Launchable script */
uint64_t events; /**< Enabled monitor events */ uint64_t events; /**< Enabled monitor events */
MXS_MONITOR* monitor; MXS_MONITOR* monitor;
} AURORA_MONITOR; };
/** /**
* @brief Update the status of a server * @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 * @param opt The configuration parameters for this monitor
* @return Monitor handle * @return Monitor handle
*/ */
static void * static MXS_SPECIFIC_MONITOR *
startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params) startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
{ {
AURORA_MONITOR *handle = static_cast<AURORA_MONITOR*>(mon->handle); AURORA_MONITOR *handle = static_cast<AURORA_MONITOR*>(mon->handle);

View File

@ -30,7 +30,8 @@ static void monitorMain(void *);
/** Log a warning when a bad 'wsrep_local_index' is found */ /** Log a warning when a bad 'wsrep_local_index' is found */
static bool warn_erange_on_local_index = true; 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 stopMonitor(MXS_MONITOR *);
static void diagnostics(DCB *, const MXS_MONITOR *); static void diagnostics(DCB *, const MXS_MONITOR *);
static json_t* diagnostics_json(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 * @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) startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
{ {
GALERA_MONITOR *handle = static_cast<GALERA_MONITOR*>(mon->handle); GALERA_MONITOR *handle = static_cast<GALERA_MONITOR*>(mon->handle);

View File

@ -41,8 +41,6 @@
#include <maxscale/config.h> #include <maxscale/config.h>
#include <maxscale/hashtable.h> #include <maxscale/hashtable.h>
MXS_BEGIN_DECLS
/** /**
* Galera Variables and server reference for each * Galera Variables and server reference for each
* monitored node that could be part of cluster. * 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 * The handle for an instance of a Galera Monitor module
*/ */
typedef struct struct GALERA_MONITOR : public MXS_SPECIFIC_MONITOR
{ {
THREAD thread; /**< Monitor thread */ THREAD thread; /**< Monitor thread */
int shutdown; /**< Flag to shutdown the 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 */ HASHTABLE *galera_nodes_info; /**< Contains Galera Cluster variables of all nodes */
GALERA_CLUSTER_INFO cluster_info; /**< Contains Galera cluster info */ GALERA_CLUSTER_INFO cluster_info; /**< Contains Galera cluster info */
MXS_MONITOR* monitor; MXS_MONITOR* monitor;
} GALERA_MONITOR; };
MXS_END_DECLS
#endif #endif

View File

@ -30,7 +30,7 @@
/** /**
* The instance of a Group Replication Monitor * The instance of a Group Replication Monitor
*/ */
struct GRMon struct GRMon : public MXS_SPECIFIC_MONITOR
{ {
GRMon(const GRMon&); GRMon(const GRMon&);
GRMon& operator&(const GRMon&); GRMon& operator&(const GRMon&);
@ -99,7 +99,7 @@ void GRMon::stop()
* *
* @return A handle to use when interacting with the monitor * @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) startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
{ {
return GRMon::create(mon, params); return GRMon::create(mon, params);

View File

@ -912,7 +912,8 @@ bool MariaDBMonitor::check_sql_files()
* @param params Configuration parameters * @param params Configuration parameters
* @return A pointer to MariaDBMonitor specific data. Should be stored in MXS_MONITOR's "handle"-field. * @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); return MariaDBMonitor::start(monitor, params);
} }

View File

@ -35,7 +35,7 @@ typedef std::tr1::unordered_map<MXS_MONITORED_SERVER*, MariaDBServer*> ServerInf
typedef std::vector<MariaDBServer*> ServerArray; typedef std::vector<MariaDBServer*> ServerArray;
// MariaDB Monitor instance data // MariaDB Monitor instance data
class MariaDBMonitor class MariaDBMonitor : public MXS_SPECIFIC_MONITOR
{ {
private: private:
MariaDBMonitor(const MariaDBMonitor&); MariaDBMonitor(const MariaDBMonitor&);

View File

@ -38,7 +38,7 @@ MXS_MODULE info =
}; };
/*lint +e14 */ /*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 stopMonitor(MXS_MONITOR *);
static void diagnostics(DCB *, const MXS_MONITOR *); static void diagnostics(DCB *, const MXS_MONITOR *);
static json_t* diagnostics_json(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 * @param arg The current handle - NULL if first start
* @return A handle to use when interacting with the monitor * @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) startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
{ {
MM_MONITOR *handle = static_cast<MM_MONITOR*>(mon->handle); MM_MONITOR *handle = static_cast<MM_MONITOR*>(mon->handle);

View File

@ -33,12 +33,10 @@
* @file mmmon.h - The Multi-Master monitor * @file mmmon.h - The Multi-Master monitor
*/ */
MXS_BEGIN_DECLS
/** /**
* The handle for an instance of a Multi-Master Monitor module * The handle for an instance of a Multi-Master Monitor module
*/ */
typedef struct struct MM_MONITOR : public MXS_SPECIFIC_MONITOR
{ {
THREAD thread; /**< Monitor thread */ THREAD thread; /**< Monitor thread */
int shutdown; /**< Flag to shutdown the 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 */ char* script; /*< Script to call when state changes occur on servers */
uint64_t events; /*< enabled events */ uint64_t events; /*< enabled events */
MXS_MONITOR* monitor; MXS_MONITOR* monitor;
} MM_MONITOR; };
MXS_END_DECLS
#endif #endif

View File

@ -30,7 +30,8 @@ static void monitorMain(void *);
/*lint +e14 */ /*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 stopMonitor(MXS_MONITOR *);
static void diagnostics(DCB *, const MXS_MONITOR *); static void diagnostics(DCB *, const MXS_MONITOR *);
static json_t* diagnostics_json(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 * @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) startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
{ {
NDBC_MONITOR *handle = static_cast<NDBC_MONITOR*>(mon->handle); NDBC_MONITOR *handle = static_cast<NDBC_MONITOR*>(mon->handle);

View File

@ -18,7 +18,7 @@
#include <maxscale/thread.h> #include <maxscale/thread.h>
// The handle for an instance of a NDB Cluster Monitor module // The handle for an instance of a NDB Cluster Monitor module
typedef struct struct NDBC_MONITOR : public MXS_SPECIFIC_MONITOR
{ {
THREAD thread; /**< Monitor thread */ THREAD thread; /**< Monitor thread */
SPINLOCK lock; /**< The monitor spinlock */ SPINLOCK lock; /**< The monitor spinlock */
@ -29,4 +29,4 @@ typedef struct
MXS_MONITORED_SERVER *master; /**< Master server for MySQL Master/Slave replication */ MXS_MONITORED_SERVER *master; /**< Master server for MySQL Master/Slave replication */
char* script; /*< Script to call when state changes occur on servers */ char* script; /*< Script to call when state changes occur on servers */
MXS_MONITOR* monitor; MXS_MONITOR* monitor;
} NDBC_MONITOR; };