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:
@ -65,10 +65,10 @@ typedef struct mxs_specific_monitor
|
||||
typedef struct mxs_monitor_object
|
||||
{
|
||||
/**
|
||||
* @brief Initialize the monitor.
|
||||
* @brief Create the monitor.
|
||||
*
|
||||
* This entry point is called once when MaxScale is started, for
|
||||
* initializing the monitor.
|
||||
* creating the monitor.
|
||||
*
|
||||
* If the function fails, MaxScale will not start. That is, it
|
||||
* should fail only for fatal reasons such as not being able to
|
||||
@ -82,11 +82,11 @@ typedef struct mxs_monitor_object
|
||||
* @return Pointer to the monitor specific data. Will be stored
|
||||
* in @c monitor->handle.
|
||||
*/
|
||||
MXS_SPECIFIC_MONITOR *(*initMonitor)(MXS_MONITOR *monitor,
|
||||
MXS_SPECIFIC_MONITOR *(*createInstance)(MXS_MONITOR *monitor,
|
||||
const MXS_CONFIG_PARAMETER *params);
|
||||
|
||||
/**
|
||||
* @brief Finish the monitor.
|
||||
* @brief Destroy the monitor.
|
||||
*
|
||||
* This entry point is called once when MaxScale is shutting down, iff
|
||||
* the earlier call to @c initMonitor returned on object. The monitor should
|
||||
@ -94,7 +94,7 @@ typedef struct mxs_monitor_object
|
||||
*
|
||||
* @param monitor The monitor object.
|
||||
*/
|
||||
void (*finishMonitor)(MXS_SPECIFIC_MONITOR *monitor);
|
||||
void (*destroyInstance)(MXS_SPECIFIC_MONITOR *monitor);
|
||||
|
||||
/**
|
||||
* @brief Start the monitor
|
||||
|
||||
@ -31,7 +31,8 @@ struct AURORA_MONITOR : public MXS_SPECIFIC_MONITOR
|
||||
THREAD thread; /**< Monitor thread */
|
||||
char* script; /**< Launchable script */
|
||||
uint64_t events; /**< Enabled monitor events */
|
||||
MXS_MONITOR* monitor;
|
||||
MXS_MONITOR* monitor; /**< Pointer to generic monitor structure */
|
||||
bool checked; /**< Whether server access has been checked */
|
||||
};
|
||||
|
||||
/**
|
||||
@ -178,15 +179,41 @@ static void auroramon_free(AURORA_MONITOR *handle)
|
||||
}
|
||||
|
||||
static
|
||||
MXS_SPECIFIC_MONITOR* initMonitor(MXS_MONITOR* mon, const MXS_CONFIG_PARAMETER* params)
|
||||
MXS_SPECIFIC_MONITOR* createInstance(MXS_MONITOR* mon, const MXS_CONFIG_PARAMETER* params)
|
||||
{
|
||||
ss_dassert(!true);
|
||||
return NULL;
|
||||
AURORA_MONITOR* handle = static_cast<AURORA_MONITOR*>(MXS_CALLOC(1, sizeof(AURORA_MONITOR)));
|
||||
|
||||
if (handle)
|
||||
{
|
||||
handle->shutdown = false;
|
||||
handle->thread = 0;
|
||||
handle->script = NULL;
|
||||
handle->events = 0;
|
||||
handle->monitor = mon;
|
||||
|
||||
if (check_monitor_permissions(mon, "SELECT @@aurora_server_id, server_id FROM "
|
||||
"information_schema.replica_host_status "
|
||||
"WHERE session_id = 'MASTER_SESSION_ID'"))
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
static void finishMonitor(MXS_SPECIFIC_MONITOR* mon)
|
||||
return handle;
|
||||
}
|
||||
|
||||
static void destroyInstance(MXS_SPECIFIC_MONITOR* mon)
|
||||
{
|
||||
ss_dassert(!true);
|
||||
AURORA_MONITOR* handle = static_cast<AURORA_MONITOR*>(mon);
|
||||
|
||||
MXS_FREE(handle->script);
|
||||
MXS_FREE(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -217,6 +244,7 @@ startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
|
||||
|
||||
handle->shutdown = false;
|
||||
handle->monitor = mon;
|
||||
handle->checked = false;
|
||||
|
||||
if (!check_monitor_permissions(mon, "SELECT @@aurora_server_id, server_id FROM "
|
||||
"information_schema.replica_host_status "
|
||||
@ -226,6 +254,8 @@ startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
|
||||
auroramon_free(handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle->checked = true;
|
||||
}
|
||||
|
||||
handle->script = config_copy_string(params, "script");
|
||||
@ -290,8 +320,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
||||
{
|
||||
static MXS_MONITOR_OBJECT MyObject =
|
||||
{
|
||||
initMonitor,
|
||||
finishMonitor,
|
||||
createInstance,
|
||||
destroyInstance,
|
||||
startMonitor,
|
||||
stopMonitor,
|
||||
diagnostics,
|
||||
|
||||
@ -30,9 +30,9 @@ static void monitorMain(void *);
|
||||
/** Log a warning when a bad 'wsrep_local_index' is found */
|
||||
static bool warn_erange_on_local_index = true;
|
||||
|
||||
static MXS_SPECIFIC_MONITOR *initMonitor(MXS_MONITOR *mon,
|
||||
static MXS_SPECIFIC_MONITOR *createInstance(MXS_MONITOR *mon,
|
||||
const MXS_CONFIG_PARAMETER *params);
|
||||
static void finishMonitor(MXS_SPECIFIC_MONITOR* monitor);
|
||||
static void destroyInstance(MXS_SPECIFIC_MONITOR* monitor);
|
||||
static MXS_SPECIFIC_MONITOR *startMonitor(MXS_MONITOR *,
|
||||
const MXS_CONFIG_PARAMETER *params);
|
||||
static void stopMonitor(MXS_SPECIFIC_MONITOR *);
|
||||
@ -68,8 +68,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
||||
|
||||
static MXS_MONITOR_OBJECT MyObject =
|
||||
{
|
||||
initMonitor,
|
||||
finishMonitor,
|
||||
createInstance,
|
||||
destroyInstance,
|
||||
startMonitor,
|
||||
stopMonitor,
|
||||
diagnostics,
|
||||
@ -118,16 +118,59 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
||||
|
||||
}
|
||||
|
||||
static MXS_SPECIFIC_MONITOR *initMonitor(MXS_MONITOR *mon,
|
||||
static MXS_SPECIFIC_MONITOR *createInstance(MXS_MONITOR *mon,
|
||||
const MXS_CONFIG_PARAMETER *params)
|
||||
{
|
||||
ss_dassert(!true);
|
||||
return NULL;
|
||||
GALERA_MONITOR* handle = static_cast<GALERA_MONITOR*>(MXS_CALLOC(1, sizeof(GALERA_MONITOR)));
|
||||
HASHTABLE *nodes_info = hashtable_alloc(MAX_NUM_SLAVES,
|
||||
hashtable_item_strhash,
|
||||
hashtable_item_strcmp);
|
||||
|
||||
if (handle && nodes_info)
|
||||
{
|
||||
hashtable_memory_fns(nodes_info,
|
||||
hashtable_item_strdup,
|
||||
(HASHCOPYFN)nodeval_dup,
|
||||
hashtable_item_free,
|
||||
(HASHFREEFN)nodeval_free);
|
||||
|
||||
handle->shutdown = 0;
|
||||
handle->id = MXS_MONITOR_DEFAULT_ID;
|
||||
handle->master = NULL;
|
||||
|
||||
/* Initialise cluster nodes hash and Cluster info */
|
||||
handle->galera_nodes_info = nodes_info;
|
||||
handle->cluster_info.c_size = 0;
|
||||
handle->cluster_info.c_uuid = NULL;
|
||||
handle->monitor = mon;
|
||||
|
||||
if (check_monitor_permissions(mon, "SHOW STATUS LIKE 'wsrep_local_state'"))
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hashtable_free(nodes_info);
|
||||
MXS_FREE(handle);
|
||||
}
|
||||
|
||||
static void finishMonitor(MXS_SPECIFIC_MONITOR* monitor)
|
||||
return handle;
|
||||
}
|
||||
|
||||
static void destroyInstance(MXS_SPECIFIC_MONITOR* monitor)
|
||||
{
|
||||
ss_dassert(!true);
|
||||
GALERA_MONITOR* handle = static_cast<GALERA_MONITOR*>(monitor);
|
||||
|
||||
hashtable_free(handle->galera_nodes_info);
|
||||
MXS_FREE(handle->script);
|
||||
MXS_FREE(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -199,6 +242,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);
|
||||
|
||||
@ -84,16 +84,17 @@ struct GALERA_MONITOR : public MXS_SPECIFIC_MONITOR
|
||||
int availableWhenDonor; /**< Monitor flag for Galera Cluster Donor availability */
|
||||
bool disableMasterRoleSetting; /**< Monitor flag to disable setting master role */
|
||||
MXS_MONITORED_SERVER *master; /**< Master server for MySQL Master/Slave replication */
|
||||
char* script;
|
||||
char* script; /**< Launchable script */
|
||||
bool root_node_as_master; /**< Whether we require that the Master should
|
||||
* have a wsrep_local_index of 0 */
|
||||
bool use_priority; /*< Use server priorities */
|
||||
uint64_t events; /*< enabled events */
|
||||
bool use_priority; /**< Use server priorities */
|
||||
uint64_t events; /**< Enabled monitor events */
|
||||
bool set_donor_nodes; /**< set the wrep_sst_donor variable with an
|
||||
* ordered list of nodes */
|
||||
HASHTABLE *galera_nodes_info; /**< Contains Galera Cluster variables of all nodes */
|
||||
GALERA_CLUSTER_INFO cluster_info; /**< Contains Galera cluster info */
|
||||
MXS_MONITOR* monitor;
|
||||
MXS_MONITOR* monitor; /**< Pointer to generic monitor structure */
|
||||
bool checked; /**< Whether server access has been checked */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -36,6 +36,8 @@ struct GRMon : public MXS_SPECIFIC_MONITOR
|
||||
GRMon& operator&(const GRMon&);
|
||||
public:
|
||||
static GRMon* create(MXS_MONITOR* monitor, const MXS_CONFIG_PARAMETER* params);
|
||||
static GRMon* create_and_start(MXS_MONITOR* monitor, const MXS_CONFIG_PARAMETER* params);
|
||||
void start();
|
||||
void stop();
|
||||
~GRMon();
|
||||
|
||||
@ -70,12 +72,21 @@ GRMon* GRMon::create(MXS_MONITOR* monitor, const MXS_CONFIG_PARAMETER* params)
|
||||
{
|
||||
GRMon* mon;
|
||||
MXS_EXCEPTION_GUARD(mon = new GRMon(monitor, params));
|
||||
return mon;
|
||||
}
|
||||
|
||||
if (mon && thread_start(&mon->m_thread, GRMon::main, mon, 0) == NULL)
|
||||
GRMon* GRMon::create_and_start(MXS_MONITOR* monitor, const MXS_CONFIG_PARAMETER* params)
|
||||
{
|
||||
GRMon* mon = create(monitor, params);
|
||||
|
||||
if (mon)
|
||||
{
|
||||
if (thread_start(&mon->m_thread, GRMon::main, mon, 0) == NULL)
|
||||
{
|
||||
delete mon;
|
||||
mon = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return mon;
|
||||
}
|
||||
@ -92,6 +103,18 @@ void GRMon::stop()
|
||||
thread_wait(m_thread);
|
||||
}
|
||||
|
||||
static MXS_SPECIFIC_MONITOR* createInstance(MXS_MONITOR *mon,
|
||||
const MXS_CONFIG_PARAMETER *params)
|
||||
{
|
||||
return GRMon::create(mon, params);
|
||||
}
|
||||
|
||||
static void destroyInstance(MXS_SPECIFIC_MONITOR* mon)
|
||||
{
|
||||
GRMon* handle = static_cast<GRMon*>(mon);
|
||||
delete handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the instance of the monitor, returning a handle on the monitor.
|
||||
*
|
||||
@ -102,7 +125,7 @@ void GRMon::stop()
|
||||
static MXS_SPECIFIC_MONITOR *
|
||||
startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
|
||||
{
|
||||
return GRMon::create(mon, params);
|
||||
return GRMon::create_and_start(mon, params);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,18 +141,6 @@ stopMonitor(MXS_SPECIFIC_MONITOR *mon)
|
||||
delete handle;
|
||||
}
|
||||
|
||||
static MXS_SPECIFIC_MONITOR* initMonitor(MXS_MONITOR *mon,
|
||||
const MXS_CONFIG_PARAMETER *params)
|
||||
{
|
||||
ss_dassert(!true);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void finishMonitor(MXS_SPECIFIC_MONITOR* mon)
|
||||
{
|
||||
ss_dassert(!true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Diagnostic interface
|
||||
*
|
||||
@ -333,8 +344,8 @@ extern "C"
|
||||
{
|
||||
static MXS_MONITOR_OBJECT MyObject =
|
||||
{
|
||||
initMonitor,
|
||||
finishMonitor,
|
||||
createInstance,
|
||||
destroyInstance,
|
||||
startMonitor,
|
||||
stopMonitor,
|
||||
diagnostics,
|
||||
|
||||
@ -71,7 +71,7 @@ bool MariaDBMonitor::manual_switchover(SERVER* new_master, SERVER* current_maste
|
||||
|
||||
if (stopped)
|
||||
{
|
||||
MariaDBMonitor::start(m_monitor_base, m_monitor_base->parameters);
|
||||
MariaDBMonitor::create_and_start(m_monitor_base, m_monitor_base->parameters);
|
||||
}
|
||||
return rval;
|
||||
}
|
||||
@ -105,7 +105,7 @@ bool MariaDBMonitor::manual_failover(json_t** output)
|
||||
|
||||
if (stopped)
|
||||
{
|
||||
MariaDBMonitor::start(m_monitor_base, m_monitor_base->parameters);
|
||||
MariaDBMonitor::create_and_start(m_monitor_base, m_monitor_base->parameters);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@ -178,7 +178,7 @@ bool MariaDBMonitor::manual_rejoin(SERVER* rejoin_server, json_t** output)
|
||||
|
||||
if (stopped)
|
||||
{
|
||||
MariaDBMonitor::start(m_monitor_base, m_monitor_base->parameters);
|
||||
MariaDBMonitor::create_and_start(m_monitor_base, m_monitor_base->parameters);
|
||||
}
|
||||
return rval;
|
||||
}
|
||||
|
||||
@ -59,6 +59,7 @@ MariaDBMonitor::MariaDBMonitor(MXS_MONITOR* monitor_base)
|
||||
, m_master_gtid_domain(-1)
|
||||
, m_external_master_port(PORT_UNKNOWN)
|
||||
, m_warn_set_standalone_master(true)
|
||||
, m_checked(false)
|
||||
{}
|
||||
|
||||
MariaDBMonitor::~MariaDBMonitor()
|
||||
@ -128,7 +129,25 @@ bool MariaDBMonitor::set_replication_credentials(const MXS_CONFIG_PARAMETER* par
|
||||
return rval;
|
||||
}
|
||||
|
||||
MariaDBMonitor* MariaDBMonitor::start(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
|
||||
MariaDBMonitor* MariaDBMonitor::create(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
|
||||
{
|
||||
MariaDBMonitor *handle = new MariaDBMonitor(monitor);
|
||||
|
||||
if (check_monitor_permissions(monitor, "SHOW SLAVE STATUS"))
|
||||
{
|
||||
handle->m_checked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
handle->m_checked = false;
|
||||
MXS_ERROR("Monitor cannot access servers. Starting the monitor will fail "
|
||||
"unless problem was temporary or is addressed");
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
MariaDBMonitor* MariaDBMonitor::create_and_start(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
|
||||
{
|
||||
bool error = false;
|
||||
MariaDBMonitor *handle = static_cast<MariaDBMonitor*>(monitor->handle);
|
||||
@ -171,6 +190,11 @@ MariaDBMonitor* MariaDBMonitor::start(MXS_MONITOR *monitor, const MXS_CONFIG_PAR
|
||||
return handle;
|
||||
}
|
||||
|
||||
void MariaDBMonitor::destroy(MariaDBMonitor* monitor)
|
||||
{
|
||||
delete monitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load config parameters
|
||||
*
|
||||
@ -904,16 +928,15 @@ bool MariaDBMonitor::check_sql_files()
|
||||
return rval;
|
||||
}
|
||||
|
||||
static MXS_SPECIFIC_MONITOR* initMonitor(MXS_MONITOR *monitor,
|
||||
static MXS_SPECIFIC_MONITOR* createInstance(MXS_MONITOR *monitor,
|
||||
const MXS_CONFIG_PARAMETER* params)
|
||||
{
|
||||
ss_dassert(!true);
|
||||
return NULL;
|
||||
return MariaDBMonitor::create(monitor, params);
|
||||
}
|
||||
|
||||
static void finishMonitor(MXS_SPECIFIC_MONITOR* monitor)
|
||||
static void destroyInstance(MXS_SPECIFIC_MONITOR* monitor)
|
||||
{
|
||||
ss_dassert(!true);
|
||||
MariaDBMonitor::destroy(static_cast<MariaDBMonitor*>(monitor));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -927,7 +950,7 @@ static void finishMonitor(MXS_SPECIFIC_MONITOR* monitor)
|
||||
static MXS_SPECIFIC_MONITOR* startMonitor(MXS_MONITOR *monitor,
|
||||
const MXS_CONFIG_PARAMETER* params)
|
||||
{
|
||||
return MariaDBMonitor::start(monitor, params);
|
||||
return MariaDBMonitor::create_and_start(monitor, params);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1133,8 +1156,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
||||
|
||||
static MXS_MONITOR_OBJECT MyObject =
|
||||
{
|
||||
initMonitor,
|
||||
finishMonitor,
|
||||
createInstance,
|
||||
destroyInstance,
|
||||
startMonitor,
|
||||
stopMonitor,
|
||||
diagnostics,
|
||||
|
||||
@ -62,6 +62,15 @@ public:
|
||||
*/
|
||||
void main_loop();
|
||||
|
||||
/**
|
||||
* Create the monitor instance and return the instance data.
|
||||
*
|
||||
* @param monitor General monitor data
|
||||
* @param params Configuration parameters
|
||||
* @return A pointer to MariaDBMonitor specific data.
|
||||
*/
|
||||
static MariaDBMonitor* create(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params);
|
||||
|
||||
/**
|
||||
* Start the monitor instance and return the instance data, creating it if starting for the first time.
|
||||
* This function creates a thread to execute the monitoring.
|
||||
@ -70,7 +79,14 @@ public:
|
||||
* @param params Configuration parameters
|
||||
* @return A pointer to MariaDBMonitor specific data.
|
||||
*/
|
||||
static MariaDBMonitor* start(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params);
|
||||
static MariaDBMonitor* create_and_start(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params);
|
||||
|
||||
/**
|
||||
* Destroyes aka deletes the instance.
|
||||
*
|
||||
* @param monitor The instance to be finished.
|
||||
*/
|
||||
static void destroy(MariaDBMonitor* monitor);
|
||||
|
||||
/**
|
||||
* Stop the monitor. Waits until monitor has stopped.
|
||||
@ -149,6 +165,7 @@ private:
|
||||
std::string m_script; /**< Script to call when state changes occur on servers */
|
||||
uint64_t m_events; /**< enabled events */
|
||||
bool m_warn_set_standalone_master; /**< Log a warning when setting standalone master */
|
||||
bool m_checked; /**< Whether access to servers has been checked */
|
||||
|
||||
enum slave_down_setting_t
|
||||
{
|
||||
|
||||
@ -38,8 +38,8 @@ MXS_MODULE info =
|
||||
};
|
||||
/*lint +e14 */
|
||||
|
||||
static MXS_SPECIFIC_MONITOR *initMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *);
|
||||
static void finishMonitor(MXS_SPECIFIC_MONITOR *);
|
||||
static MXS_SPECIFIC_MONITOR *createInstance(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *);
|
||||
static void destroyInstance(MXS_SPECIFIC_MONITOR *);
|
||||
static MXS_SPECIFIC_MONITOR *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *);
|
||||
static void stopMonitor(MXS_SPECIFIC_MONITOR *);
|
||||
static void diagnostics(const MXS_SPECIFIC_MONITOR *, DCB *);
|
||||
@ -64,8 +64,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
||||
|
||||
static MXS_MONITOR_OBJECT MyObject =
|
||||
{
|
||||
initMonitor,
|
||||
finishMonitor,
|
||||
createInstance,
|
||||
destroyInstance,
|
||||
startMonitor,
|
||||
stopMonitor,
|
||||
diagnostics,
|
||||
@ -110,16 +110,42 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
||||
}
|
||||
/*lint +e14 */
|
||||
|
||||
static MXS_SPECIFIC_MONITOR* initMonitor(MXS_MONITOR *mon,
|
||||
static MXS_SPECIFIC_MONITOR* createInstance(MXS_MONITOR *mon,
|
||||
const MXS_CONFIG_PARAMETER *params)
|
||||
{
|
||||
ss_dassert(!true);
|
||||
return NULL;
|
||||
MM_MONITOR* handle = static_cast<MM_MONITOR*>(MXS_CALLOC(1, sizeof(MM_MONITOR)));
|
||||
|
||||
if (handle)
|
||||
{
|
||||
handle->shutdown = 0;
|
||||
handle->id = MXS_MONITOR_DEFAULT_ID;
|
||||
handle->master = NULL;
|
||||
handle->monitor = mon;
|
||||
handle->detectStaleMaster = config_get_bool(params, "detect_stale_master");
|
||||
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 SLAVE STATUS"))
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
static void finishMonitor(MXS_SPECIFIC_MONITOR* mon)
|
||||
return handle;
|
||||
}
|
||||
|
||||
static void destroyInstance(MXS_SPECIFIC_MONITOR* mon)
|
||||
{
|
||||
ss_dassert(!true);
|
||||
MM_MONITOR* handle = static_cast<MM_MONITOR*>(mon);
|
||||
|
||||
MXS_FREE(handle->script);
|
||||
MXS_FREE(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,6 +190,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);
|
||||
|
||||
@ -44,9 +44,10 @@ struct MM_MONITOR : public MXS_SPECIFIC_MONITOR
|
||||
unsigned long id; /**< Monitor ID */
|
||||
int detectStaleMaster; /**< Monitor flag for Stale Master detection */
|
||||
MXS_MONITORED_SERVER *master; /**< Master server for Master/Slave replication */
|
||||
char* script; /*< Script to call when state changes occur on servers */
|
||||
uint64_t events; /*< enabled events */
|
||||
MXS_MONITOR* monitor;
|
||||
char* script; /**< Script to call when state changes occur on servers */
|
||||
uint64_t events; /**< enabled events */
|
||||
MXS_MONITOR* monitor; /**< Pointer to generic monitor structure */
|
||||
bool checked; /**< Whether server access has been checked */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -30,9 +30,9 @@ static void monitorMain(void *);
|
||||
|
||||
/*lint +e14 */
|
||||
|
||||
static MXS_SPECIFIC_MONITOR *initMonitor(MXS_MONITOR *,
|
||||
static MXS_SPECIFIC_MONITOR *createInstance(MXS_MONITOR *,
|
||||
const MXS_CONFIG_PARAMETER *params);
|
||||
static void finishMonitor(MXS_SPECIFIC_MONITOR*);
|
||||
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,
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
void finishMonitor(MXS_SPECIFIC_MONITOR* mon)
|
||||
return handle;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@ -23,10 +23,11 @@ struct NDBC_MONITOR : public MXS_SPECIFIC_MONITOR
|
||||
THREAD thread; /**< Monitor thread */
|
||||
SPINLOCK lock; /**< The monitor spinlock */
|
||||
unsigned long id; /**< Monitor ID */
|
||||
uint64_t events; /*< enabled events */
|
||||
uint64_t events; /**< enabled events */
|
||||
int shutdown; /**< Flag to shutdown the monitor thread */
|
||||
int status; /**< Monitor status */
|
||||
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;
|
||||
char* script; /**< Script to call when state changes occur on servers */
|
||||
MXS_MONITOR* monitor; /**< Pointer to generic monitor structure */
|
||||
bool checked; /**< Whether server access has been checked */
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user