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 *);
|
||||
/** 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,
|
||||
const MXS_CONFIG_PARAMETER *params);
|
||||
static void finishMonitor(MXS_SPECIFIC_MONITOR* monitor);
|
||||
static MXS_SPECIFIC_MONITOR *createInstance(MXS_MONITOR *mon,
|
||||
const MXS_CONFIG_PARAMETER *params);
|
||||
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,
|
||||
const MXS_CONFIG_PARAMETER *params)
|
||||
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);
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
static void finishMonitor(MXS_SPECIFIC_MONITOR* monitor)
|
||||
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);
|
||||
|
||||
@ -76,24 +76,25 @@ typedef struct galera_cluster_info
|
||||
*/
|
||||
struct GALERA_MONITOR : public MXS_SPECIFIC_MONITOR
|
||||
{
|
||||
THREAD thread; /**< Monitor thread */
|
||||
int shutdown; /**< Flag to shutdown the monitor thread */
|
||||
int status; /**< Monitor status */
|
||||
unsigned long id; /**< Monitor ID */
|
||||
int disableMasterFailback; /**< Monitor flag for Galera Cluster Master failback */
|
||||
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;
|
||||
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 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 */
|
||||
THREAD thread; /**< Monitor thread */
|
||||
int shutdown; /**< Flag to shutdown the monitor thread */
|
||||
int status; /**< Monitor status */
|
||||
unsigned long id; /**< Monitor ID */
|
||||
int disableMasterFailback; /**< Monitor flag for Galera Cluster Master failback */
|
||||
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; /**< 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 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
|
||||
|
||||
Reference in New Issue
Block a user