MXS-1848 Use MXS_SPECIFIC_MONITOR type in monitor APIs
Now, all monitor functions but startMonitor takes a MXS_SPECIFIC_MONITOR instead of MXS_MONITOR. That is, startMonitor is now like a static factory member returning a new specific monitor instance and the other functions are like member functions of that instance.
This commit is contained in:
@ -87,17 +87,26 @@ typedef struct mxs_monitor_object
|
|||||||
*
|
*
|
||||||
* @param monitor The monitor object
|
* @param monitor The monitor object
|
||||||
*/
|
*/
|
||||||
void (*stopMonitor)(MXS_MONITOR *monitor);
|
void (*stopMonitor)(MXS_SPECIFIC_MONITOR *monitor);
|
||||||
void (*diagnostics)(DCB *, const MXS_MONITOR *);
|
|
||||||
|
/**
|
||||||
|
* @brief Write diagnostic information to a DCB.
|
||||||
|
*
|
||||||
|
* @param monitor The monitor object.
|
||||||
|
* @param dcb The dcb to write to.
|
||||||
|
*/
|
||||||
|
void (*diagnostics)(const MXS_SPECIFIC_MONITOR* monitor, DCB* dcb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return diagnostic information about the monitor
|
* @brief Return diagnostic information about the monitor
|
||||||
*
|
*
|
||||||
|
* @param monitor The monitor object.
|
||||||
|
*
|
||||||
* @return A JSON object representing the state of the monitor
|
* @return A JSON object representing the state of the monitor
|
||||||
*
|
*
|
||||||
* @see jansson.h
|
* @see jansson.h
|
||||||
*/
|
*/
|
||||||
json_t* (*diagnostics_json)(const MXS_MONITOR *monitor);
|
json_t* (*diagnostics_json)(const MXS_SPECIFIC_MONITOR *monitor);
|
||||||
} MXS_MONITOR_OBJECT;
|
} MXS_MONITOR_OBJECT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,7 +158,7 @@ monitor_free(MXS_MONITOR *mon)
|
|||||||
{
|
{
|
||||||
MXS_MONITOR *ptr;
|
MXS_MONITOR *ptr;
|
||||||
|
|
||||||
mon->module->stopMonitor(mon);
|
mon->module->stopMonitor(mon->handle);
|
||||||
mon->state = MONITOR_STATE_FREED;
|
mon->state = MONITOR_STATE_FREED;
|
||||||
spinlock_acquire(&monLock);
|
spinlock_acquire(&monLock);
|
||||||
if (allMonitors == mon)
|
if (allMonitors == mon)
|
||||||
@ -253,7 +253,7 @@ monitorStop(MXS_MONITOR *monitor)
|
|||||||
if (monitor->state == MONITOR_STATE_RUNNING)
|
if (monitor->state == MONITOR_STATE_RUNNING)
|
||||||
{
|
{
|
||||||
monitor->state = MONITOR_STATE_STOPPING;
|
monitor->state = MONITOR_STATE_STOPPING;
|
||||||
monitor->module->stopMonitor(monitor);
|
monitor->module->stopMonitor(monitor->handle);
|
||||||
monitor->state = MONITOR_STATE_STOPPED;
|
monitor->state = MONITOR_STATE_STOPPED;
|
||||||
|
|
||||||
MXS_MONITORED_SERVER* db = monitor->monitored_servers;
|
MXS_MONITORED_SERVER* db = monitor->monitored_servers;
|
||||||
@ -539,7 +539,7 @@ monitorShow(DCB *dcb, MXS_MONITOR *monitor)
|
|||||||
{
|
{
|
||||||
if (monitor->module->diagnostics)
|
if (monitor->module->diagnostics)
|
||||||
{
|
{
|
||||||
monitor->module->diagnostics(dcb, monitor);
|
monitor->module->diagnostics(monitor->handle, dcb);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1854,7 +1854,7 @@ json_t* monitor_json_data(const MXS_MONITOR* monitor, const char* host)
|
|||||||
|
|
||||||
if (monitor->handle && monitor->module->diagnostics_json)
|
if (monitor->handle && monitor->module->diagnostics_json)
|
||||||
{
|
{
|
||||||
json_t* diag = monitor->module->diagnostics_json(monitor);
|
json_t* diag = monitor->module->diagnostics_json(monitor->handle);
|
||||||
|
|
||||||
if (diag)
|
if (diag)
|
||||||
{
|
{
|
||||||
|
@ -235,9 +235,9 @@ startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
|
|||||||
* @param arg Handle on thr running monior
|
* @param arg Handle on thr running monior
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
stopMonitor(MXS_MONITOR *mon)
|
stopMonitor(MXS_SPECIFIC_MONITOR *mon)
|
||||||
{
|
{
|
||||||
AURORA_MONITOR *handle = (AURORA_MONITOR *) mon->handle;
|
AURORA_MONITOR *handle = static_cast<AURORA_MONITOR*>(mon);
|
||||||
|
|
||||||
handle->shutdown = true;
|
handle->shutdown = true;
|
||||||
thread_wait(handle->thread);
|
thread_wait(handle->thread);
|
||||||
@ -250,7 +250,7 @@ stopMonitor(MXS_MONITOR *mon)
|
|||||||
* @param mon The monitor
|
* @param mon The monitor
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
diagnostics(DCB *dcb, const MXS_MONITOR *mon)
|
diagnostics(const MXS_SPECIFIC_MONITOR *mon, DCB *dcb)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +260,7 @@ diagnostics(DCB *dcb, const MXS_MONITOR *mon)
|
|||||||
* @param dcb DCB to send output
|
* @param dcb DCB to send output
|
||||||
* @param mon The monitor
|
* @param mon The monitor
|
||||||
*/
|
*/
|
||||||
static json_t* diagnostics_json(const MXS_MONITOR *mon)
|
static json_t* diagnostics_json(const MXS_SPECIFIC_MONITOR *mon)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,9 @@ static bool warn_erange_on_local_index = true;
|
|||||||
|
|
||||||
static MXS_SPECIFIC_MONITOR *startMonitor(MXS_MONITOR *,
|
static MXS_SPECIFIC_MONITOR *startMonitor(MXS_MONITOR *,
|
||||||
const MXS_CONFIG_PARAMETER *params);
|
const MXS_CONFIG_PARAMETER *params);
|
||||||
static void stopMonitor(MXS_MONITOR *);
|
static void stopMonitor(MXS_SPECIFIC_MONITOR *);
|
||||||
static void diagnostics(DCB *, const MXS_MONITOR *);
|
static void diagnostics(const MXS_SPECIFIC_MONITOR *, DCB *);
|
||||||
static json_t* diagnostics_json(const MXS_MONITOR *);
|
static json_t* diagnostics_json(const MXS_SPECIFIC_MONITOR *);
|
||||||
static MXS_MONITORED_SERVER *get_candidate_master(MXS_MONITOR*);
|
static MXS_MONITORED_SERVER *get_candidate_master(MXS_MONITOR*);
|
||||||
static MXS_MONITORED_SERVER *set_cluster_master(MXS_MONITORED_SERVER *, MXS_MONITORED_SERVER *, int);
|
static MXS_MONITORED_SERVER *set_cluster_master(MXS_MONITORED_SERVER *, MXS_MONITORED_SERVER *, int);
|
||||||
static void disableMasterFailback(void *, int);
|
static void disableMasterFailback(void *, int);
|
||||||
@ -200,9 +200,9 @@ startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
|
|||||||
* @param arg Handle on thr running monior
|
* @param arg Handle on thr running monior
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
stopMonitor(MXS_MONITOR *mon)
|
stopMonitor(MXS_SPECIFIC_MONITOR *mon)
|
||||||
{
|
{
|
||||||
GALERA_MONITOR *handle = (GALERA_MONITOR *) mon->handle;
|
GALERA_MONITOR *handle = static_cast<GALERA_MONITOR*>(mon);
|
||||||
|
|
||||||
handle->shutdown = 1;
|
handle->shutdown = 1;
|
||||||
thread_wait(handle->thread);
|
thread_wait(handle->thread);
|
||||||
@ -215,9 +215,9 @@ stopMonitor(MXS_MONITOR *mon)
|
|||||||
* @param arg The monitor handle
|
* @param arg The monitor handle
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
diagnostics(DCB *dcb, const MXS_MONITOR *mon)
|
diagnostics(const MXS_SPECIFIC_MONITOR *mon, DCB *dcb)
|
||||||
{
|
{
|
||||||
const GALERA_MONITOR *handle = (const GALERA_MONITOR *) mon->handle;
|
const GALERA_MONITOR *handle = static_cast<const GALERA_MONITOR*>(mon);
|
||||||
|
|
||||||
dcb_printf(dcb, "Master Failback:\t%s\n", (handle->disableMasterFailback == 1) ? "off" : "on");
|
dcb_printf(dcb, "Master Failback:\t%s\n", (handle->disableMasterFailback == 1) ? "off" : "on");
|
||||||
dcb_printf(dcb, "Available when Donor:\t%s\n", (handle->availableWhenDonor == 1) ? "on" : "off");
|
dcb_printf(dcb, "Available when Donor:\t%s\n", (handle->availableWhenDonor == 1) ? "on" : "off");
|
||||||
@ -240,10 +240,10 @@ diagnostics(DCB *dcb, const MXS_MONITOR *mon)
|
|||||||
*
|
*
|
||||||
* @param arg The monitor handle
|
* @param arg The monitor handle
|
||||||
*/
|
*/
|
||||||
static json_t* diagnostics_json(const MXS_MONITOR *mon)
|
static json_t* diagnostics_json(const MXS_SPECIFIC_MONITOR *mon)
|
||||||
{
|
{
|
||||||
json_t* rval = json_object();
|
json_t* rval = json_object();
|
||||||
const GALERA_MONITOR *handle = (const GALERA_MONITOR *)mon->handle;
|
const GALERA_MONITOR *handle = static_cast<const GALERA_MONITOR*>(mon);
|
||||||
|
|
||||||
json_object_set_new(rval, "disable_master_failback", json_boolean(handle->disableMasterFailback));
|
json_object_set_new(rval, "disable_master_failback", json_boolean(handle->disableMasterFailback));
|
||||||
json_object_set_new(rval, "disable_master_role_setting", json_boolean(handle->disableMasterRoleSetting));
|
json_object_set_new(rval, "disable_master_role_setting", json_boolean(handle->disableMasterRoleSetting));
|
||||||
|
@ -111,12 +111,11 @@ startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
|
|||||||
* @param arg Handle on thr running monior
|
* @param arg Handle on thr running monior
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
stopMonitor(MXS_MONITOR *mon)
|
stopMonitor(MXS_SPECIFIC_MONITOR *mon)
|
||||||
{
|
{
|
||||||
GRMon *handle = (GRMon *) mon->handle;
|
GRMon *handle = static_cast<GRMon*>(mon);
|
||||||
handle->stop();
|
handle->stop();
|
||||||
delete handle;
|
delete handle;
|
||||||
mon->handle = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,7 +125,7 @@ stopMonitor(MXS_MONITOR *mon)
|
|||||||
* @param arg The monitor handle
|
* @param arg The monitor handle
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
diagnostics(DCB *dcb, const MXS_MONITOR *mon)
|
diagnostics(const MXS_SPECIFIC_MONITOR *mon, DCB *dcb)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +134,7 @@ diagnostics(DCB *dcb, const MXS_MONITOR *mon)
|
|||||||
*
|
*
|
||||||
* @param arg The monitor handle
|
* @param arg The monitor handle
|
||||||
*/
|
*/
|
||||||
static json_t* diagnostics_json(const MXS_MONITOR *mon)
|
static json_t* diagnostics_json(const MXS_SPECIFIC_MONITOR *mon)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -923,9 +923,9 @@ static MXS_SPECIFIC_MONITOR* startMonitor(MXS_MONITOR *monitor,
|
|||||||
*
|
*
|
||||||
* @param mon The monitor that should be stopped.
|
* @param mon The monitor that should be stopped.
|
||||||
*/
|
*/
|
||||||
static void stopMonitor(MXS_MONITOR *mon)
|
static void stopMonitor(MXS_SPECIFIC_MONITOR *mon)
|
||||||
{
|
{
|
||||||
auto handle = static_cast<MariaDBMonitor*>(mon->handle);
|
auto handle = static_cast<MariaDBMonitor*>(mon);
|
||||||
handle->stop();
|
handle->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -935,9 +935,9 @@ static void stopMonitor(MXS_MONITOR *mon)
|
|||||||
* @param dcb DCB to print diagnostics
|
* @param dcb DCB to print diagnostics
|
||||||
* @param arg The monitor handle
|
* @param arg The monitor handle
|
||||||
*/
|
*/
|
||||||
static void diagnostics(DCB *dcb, const MXS_MONITOR *mon)
|
static void diagnostics(const MXS_SPECIFIC_MONITOR *mon, DCB *dcb)
|
||||||
{
|
{
|
||||||
const MariaDBMonitor* handle = static_cast<const MariaDBMonitor*>(mon->handle);
|
const MariaDBMonitor* handle = static_cast<const MariaDBMonitor*>(mon);
|
||||||
handle->diagnostics(dcb);
|
handle->diagnostics(dcb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -946,9 +946,9 @@ static void diagnostics(DCB *dcb, const MXS_MONITOR *mon)
|
|||||||
*
|
*
|
||||||
* @param arg The monitor handle
|
* @param arg The monitor handle
|
||||||
*/
|
*/
|
||||||
static json_t* diagnostics_json(const MXS_MONITOR *mon)
|
static json_t* diagnostics_json(const MXS_SPECIFIC_MONITOR *mon)
|
||||||
{
|
{
|
||||||
const MariaDBMonitor *handle = (const MariaDBMonitor *)mon->handle;
|
const MariaDBMonitor *handle = static_cast<const MariaDBMonitor*>(mon);
|
||||||
return handle->diagnostics_json();
|
return handle->diagnostics_json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,9 +39,9 @@ MXS_MODULE info =
|
|||||||
/*lint +e14 */
|
/*lint +e14 */
|
||||||
|
|
||||||
static MXS_SPECIFIC_MONITOR *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_SPECIFIC_MONITOR *);
|
||||||
static void diagnostics(DCB *, const MXS_MONITOR *);
|
static void diagnostics(const MXS_SPECIFIC_MONITOR *, DCB *);
|
||||||
static json_t* diagnostics_json(const MXS_MONITOR *);
|
static json_t* diagnostics_json(const MXS_SPECIFIC_MONITOR *);
|
||||||
static void detectStaleMaster(void *, int);
|
static void detectStaleMaster(void *, int);
|
||||||
static MXS_MONITORED_SERVER *get_current_master(MXS_MONITOR *);
|
static MXS_MONITORED_SERVER *get_current_master(MXS_MONITOR *);
|
||||||
static bool isMySQLEvent(mxs_monitor_event_t event);
|
static bool isMySQLEvent(mxs_monitor_event_t event);
|
||||||
@ -165,9 +165,9 @@ startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
|
|||||||
* @param arg Handle on thr running monior
|
* @param arg Handle on thr running monior
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
stopMonitor(MXS_MONITOR *mon)
|
stopMonitor(MXS_SPECIFIC_MONITOR *mon)
|
||||||
{
|
{
|
||||||
MM_MONITOR *handle = (MM_MONITOR *) mon->handle;
|
MM_MONITOR *handle = static_cast<MM_MONITOR*>(mon);
|
||||||
|
|
||||||
handle->shutdown = 1;
|
handle->shutdown = 1;
|
||||||
thread_wait(handle->thread);
|
thread_wait(handle->thread);
|
||||||
@ -179,9 +179,9 @@ stopMonitor(MXS_MONITOR *mon)
|
|||||||
* @param dcb DCB to print diagnostics
|
* @param dcb DCB to print diagnostics
|
||||||
* @param arg The monitor handle
|
* @param arg The monitor handle
|
||||||
*/
|
*/
|
||||||
static void diagnostics(DCB *dcb, const MXS_MONITOR *mon)
|
static void diagnostics(const MXS_SPECIFIC_MONITOR *mon, DCB *dcb)
|
||||||
{
|
{
|
||||||
const MM_MONITOR *handle = (const MM_MONITOR *) mon->handle;
|
const MM_MONITOR *handle = static_cast<const MM_MONITOR*>(mon);
|
||||||
|
|
||||||
dcb_printf(dcb, "Detect Stale Master:\t%s\n", (handle->detectStaleMaster == 1) ? "enabled" : "disabled");
|
dcb_printf(dcb, "Detect Stale Master:\t%s\n", (handle->detectStaleMaster == 1) ? "enabled" : "disabled");
|
||||||
}
|
}
|
||||||
@ -191,9 +191,9 @@ static void diagnostics(DCB *dcb, const MXS_MONITOR *mon)
|
|||||||
*
|
*
|
||||||
* @param arg The monitor handle
|
* @param arg The monitor handle
|
||||||
*/
|
*/
|
||||||
static json_t* diagnostics_json(const MXS_MONITOR *mon)
|
static json_t* diagnostics_json(const MXS_SPECIFIC_MONITOR *mon)
|
||||||
{
|
{
|
||||||
const MM_MONITOR *handle = (const MM_MONITOR *)mon->handle;
|
const MM_MONITOR *handle = static_cast<const MM_MONITOR*>(mon);
|
||||||
|
|
||||||
json_t* rval = json_object();
|
json_t* rval = json_object();
|
||||||
json_object_set_new(rval, "detect_stale_master", json_boolean(handle->detectStaleMaster));
|
json_object_set_new(rval, "detect_stale_master", json_boolean(handle->detectStaleMaster));
|
||||||
|
@ -32,9 +32,9 @@ static void monitorMain(void *);
|
|||||||
|
|
||||||
static MXS_SPECIFIC_MONITOR *startMonitor(MXS_MONITOR *,
|
static MXS_SPECIFIC_MONITOR *startMonitor(MXS_MONITOR *,
|
||||||
const MXS_CONFIG_PARAMETER *params);
|
const MXS_CONFIG_PARAMETER *params);
|
||||||
static void stopMonitor(MXS_MONITOR *);
|
static void stopMonitor(MXS_SPECIFIC_MONITOR *);
|
||||||
static void diagnostics(DCB *, const MXS_MONITOR *);
|
static void diagnostics(const MXS_SPECIFIC_MONITOR *, DCB *);
|
||||||
static json_t* diagnostics_json(const MXS_MONITOR *);
|
static json_t* diagnostics_json(const MXS_SPECIFIC_MONITOR *);
|
||||||
bool isNdbEvent(mxs_monitor_event_t event);
|
bool isNdbEvent(mxs_monitor_event_t event);
|
||||||
|
|
||||||
|
|
||||||
@ -158,9 +158,9 @@ startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
|
|||||||
* @param arg Handle on thr running monior
|
* @param arg Handle on thr running monior
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
stopMonitor(MXS_MONITOR *mon)
|
stopMonitor(MXS_SPECIFIC_MONITOR *mon)
|
||||||
{
|
{
|
||||||
NDBC_MONITOR *handle = (NDBC_MONITOR *) mon->handle;
|
NDBC_MONITOR *handle = static_cast<NDBC_MONITOR*>(mon);
|
||||||
|
|
||||||
handle->shutdown = 1;
|
handle->shutdown = 1;
|
||||||
thread_wait(handle->thread);
|
thread_wait(handle->thread);
|
||||||
@ -173,7 +173,7 @@ stopMonitor(MXS_MONITOR *mon)
|
|||||||
* @param arg The monitor handle
|
* @param arg The monitor handle
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
diagnostics(DCB *dcb, const MXS_MONITOR *mon)
|
diagnostics(const MXS_SPECIFIC_MONITOR *mon, DCB *dcb)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ diagnostics(DCB *dcb, const MXS_MONITOR *mon)
|
|||||||
* @param dcb DCB to send output
|
* @param dcb DCB to send output
|
||||||
* @param arg The monitor handle
|
* @param arg The monitor handle
|
||||||
*/
|
*/
|
||||||
static json_t* diagnostics_json(const MXS_MONITOR *mon)
|
static json_t* diagnostics_json(const MXS_SPECIFIC_MONITOR *mon)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user