MXS-1848 Implement createInstance() and destroyInstance()
CreateInstance() (renamed from initMonitor()) and destroyInstance()
(renamed from finishMonitor()) have now tentatively been
implemented for all monitors.
Next step is to
1) change the prototype of startMonitor() to
bool (*startMonitor)(MXS_SPECIFIC_MONITOR*,
const MXS_MONITOR_PARAMETER*);
and assume that mon->handle will always contain the
instance,
2) not delete any data in stopMonitor(),
3) add monitorCreateAll() that calls createInstance() for all
monitors (and call that in main()), and
4) add monitorDestroyAll() that calls destroyInstance() for
all monitors (and call that in main()).
This commit is contained in:
@ -30,9 +30,9 @@ static void monitorMain(void *);
|
||||
|
||||
/*lint +e14 */
|
||||
|
||||
static MXS_SPECIFIC_MONITOR *initMonitor(MXS_MONITOR *,
|
||||
const MXS_CONFIG_PARAMETER *params);
|
||||
static void finishMonitor(MXS_SPECIFIC_MONITOR*);
|
||||
static MXS_SPECIFIC_MONITOR *createInstance(MXS_MONITOR *,
|
||||
const MXS_CONFIG_PARAMETER *params);
|
||||
static void destroyInstance(MXS_SPECIFIC_MONITOR*);
|
||||
static MXS_SPECIFIC_MONITOR *startMonitor(MXS_MONITOR *,
|
||||
const MXS_CONFIG_PARAMETER *params);
|
||||
static void stopMonitor(MXS_SPECIFIC_MONITOR *);
|
||||
@ -59,8 +59,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
||||
|
||||
static MXS_MONITOR_OBJECT MyObject =
|
||||
{
|
||||
initMonitor,
|
||||
finishMonitor,
|
||||
createInstance,
|
||||
destroyInstance,
|
||||
startMonitor,
|
||||
stopMonitor,
|
||||
diagnostics,
|
||||
@ -104,16 +104,42 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
||||
}
|
||||
/*lint +e14 */
|
||||
|
||||
static MXS_SPECIFIC_MONITOR* initMonitor(MXS_MONITOR *mon,
|
||||
const MXS_CONFIG_PARAMETER *params)
|
||||
static MXS_SPECIFIC_MONITOR* createInstance(MXS_MONITOR *mon,
|
||||
const MXS_CONFIG_PARAMETER *params)
|
||||
{
|
||||
ss_dassert(!true);
|
||||
return NULL;
|
||||
NDBC_MONITOR* handle = static_cast<NDBC_MONITOR*>(MXS_CALLOC(1, sizeof(NDBC_MONITOR)));
|
||||
|
||||
if (handle)
|
||||
{
|
||||
handle->shutdown = 0;
|
||||
handle->id = MXS_MONITOR_DEFAULT_ID;
|
||||
handle->master = NULL;
|
||||
handle->monitor = mon;
|
||||
|
||||
handle->script = config_copy_string(params, "script");
|
||||
handle->events = config_get_enum(params, "events", mxs_monitor_event_enum_values);
|
||||
|
||||
if (check_monitor_permissions(mon, "SHOW STATUS LIKE 'Ndb_number_of_ready_data_nodes'"))
|
||||
{
|
||||
handle->checked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
handle->checked = false;
|
||||
MXS_ERROR("Monitor cannot access servers. Starting the monitor will fail "
|
||||
"unless problem was temporary or is addressed");
|
||||
}
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void finishMonitor(MXS_SPECIFIC_MONITOR* mon)
|
||||
void destroyInstance(MXS_SPECIFIC_MONITOR* mon)
|
||||
{
|
||||
ss_dassert(!true);
|
||||
NDBC_MONITOR* handle = static_cast<NDBC_MONITOR*>(mon);
|
||||
|
||||
MXS_FREE(handle->script);
|
||||
MXS_FREE(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,6 +184,8 @@ startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle->checked = true;
|
||||
|
||||
if (thread_start(&handle->thread, monitorMain, handle, 0) == NULL)
|
||||
{
|
||||
MXS_ERROR("Failed to start monitor thread for monitor '%s'.", mon->name);
|
||||
|
||||
Reference in New Issue
Block a user