MXS-1848 Parameters are not available at createInstance time

The monitor parameters are not available when the monitor instance
is created so at least for the time being they are removed from
the API.
This commit is contained in:
Johan Wikman
2018-05-07 10:18:48 +03:00
parent 81654fb0e7
commit 5c1083c4aa
8 changed files with 66 additions and 106 deletions

View File

@ -72,18 +72,14 @@ typedef struct mxs_monitor_api
*
* If the function fails, MaxScale will not start. That is, it
* should fail only for fatal reasons such as not being able to
* create vital resources. The function may contact servers and
* log errors if that does not succeed, but a failure to contact
* some server must not be treated as a fatal error.
* create vital resources.
*
* @param monitor The monitor object.
* @param params Parameters for this monitor
*
* @return Pointer to the monitor specific data. Will be stored
* in @c monitor->handle.
*/
MXS_MONITOR_INSTANCE *(*createInstance)(MXS_MONITOR *monitor,
const MXS_CONFIG_PARAMETER *params);
MXS_MONITOR_INSTANCE *(*createInstance)(MXS_MONITOR *monitor);
/**
* @brief Destroy the monitor.

View File

@ -179,7 +179,7 @@ static void auroramon_free(AURORA_MONITOR *handle)
}
static
MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR* mon, const MXS_CONFIG_PARAMETER* params)
MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR* mon)
{
AURORA_MONITOR* handle = static_cast<AURORA_MONITOR*>(MXS_CALLOC(1, sizeof(AURORA_MONITOR)));
@ -190,19 +190,7 @@ MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR* mon, const MXS_CONFIG_PARAMETE
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");
}
handle->checked = false;
}
return handle;

View File

@ -30,8 +30,7 @@ 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_MONITOR_INSTANCE *createInstance(MXS_MONITOR *mon,
const MXS_CONFIG_PARAMETER *params);
static MXS_MONITOR_INSTANCE *createInstance(MXS_MONITOR *mon);
static void destroyInstance(MXS_MONITOR_INSTANCE* monitor);
static MXS_MONITOR_INSTANCE *startMonitor(MXS_MONITOR *,
const MXS_CONFIG_PARAMETER *params);
@ -118,8 +117,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
}
static MXS_MONITOR_INSTANCE *createInstance(MXS_MONITOR *mon,
const MXS_CONFIG_PARAMETER *params)
static MXS_MONITOR_INSTANCE *createInstance(MXS_MONITOR *mon)
{
GALERA_MONITOR* handle = static_cast<GALERA_MONITOR*>(MXS_CALLOC(1, sizeof(GALERA_MONITOR)));
HASHTABLE *nodes_info = hashtable_alloc(MAX_NUM_SLAVES,
@ -143,17 +141,7 @@ static MXS_MONITOR_INSTANCE *createInstance(MXS_MONITOR *mon,
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");
}
handle->checked = false;
}
else
{

View File

@ -35,9 +35,9 @@ struct GRMon : public MXS_MONITOR_INSTANCE
GRMon(const GRMon&);
GRMon& operator&(const GRMon&);
public:
static GRMon* create(MXS_MONITOR* monitor, const MXS_CONFIG_PARAMETER* params);
static GRMon* create(MXS_MONITOR* monitor);
static GRMon* create_and_start(MXS_MONITOR* monitor, const MXS_CONFIG_PARAMETER* params);
void start();
bool start(const MXS_CONFIG_PARAMETER* params);
void stop();
~GRMon();
@ -49,17 +49,17 @@ private:
uint64_t m_events; /**< Enabled events */
MXS_MONITOR* m_monitor;
GRMon(MXS_MONITOR* monitor, const MXS_CONFIG_PARAMETER *params);
GRMon(MXS_MONITOR* monitor);
void main();
static void main(void* data);
};
GRMon::GRMon(MXS_MONITOR* monitor, const MXS_CONFIG_PARAMETER* params):
GRMon::GRMon(MXS_MONITOR* monitor):
m_shutdown(0),
m_master(NULL),
m_script(config_get_string(params, "script")),
m_events(config_get_enum(params, "events", mxs_monitor_event_enum_values)),
m_script(NULL),
m_events(0),
m_monitor(monitor)
{
}
@ -68,27 +68,50 @@ GRMon::~GRMon()
{
}
GRMon* GRMon::create(MXS_MONITOR* monitor, const MXS_CONFIG_PARAMETER* params)
GRMon* GRMon::create(MXS_MONITOR* monitor)
{
GRMon* mon;
MXS_EXCEPTION_GUARD(mon = new GRMon(monitor, params));
MXS_EXCEPTION_GUARD(mon = new GRMon(monitor));
return mon;
}
GRMon* GRMon::create_and_start(MXS_MONITOR* monitor, const MXS_CONFIG_PARAMETER* params)
{
GRMon* mon = create(monitor, params);
GRMon* instance = static_cast<GRMon*>(monitor->instance);
if (mon)
if (!instance)
{
if (thread_start(&mon->m_thread, GRMon::main, mon, 0) == NULL)
instance = create(monitor);
}
if (instance)
{
if (!instance->start(params))
{
delete mon;
mon = NULL;
delete instance;
instance = NULL;
}
}
return mon;
return instance;
}
bool GRMon::start(const MXS_CONFIG_PARAMETER* params)
{
bool started = false;
m_shutdown = 0;
m_master = NULL;
m_script = config_get_string(params, "script");
m_events = config_get_enum(params, "events", mxs_monitor_event_enum_values);
m_thread = 0;
if (thread_start(&m_thread, GRMon::main, this, 0) != NULL)
{
started = true;
}
return started;
}
void GRMon::main(void* data)
@ -103,10 +126,9 @@ void GRMon::stop()
thread_wait(m_thread);
}
static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *mon,
const MXS_CONFIG_PARAMETER *params)
static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *mon)
{
return GRMon::create(mon, params);
return GRMon::create(mon);
}
static void destroyInstance(MXS_MONITOR_INSTANCE* mon)

View File

@ -129,22 +129,9 @@ bool MariaDBMonitor::set_replication_credentials(const MXS_CONFIG_PARAMETER* par
return rval;
}
MariaDBMonitor* MariaDBMonitor::create(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
MariaDBMonitor* MariaDBMonitor::create(MXS_MONITOR *monitor)
{
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;
return new MariaDBMonitor(monitor);
}
MariaDBMonitor* MariaDBMonitor::create_and_start(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
@ -171,6 +158,10 @@ MariaDBMonitor* MariaDBMonitor::create_and_start(MXS_MONITOR *monitor, const MXS
{
error = true;
}
else
{
handle->m_checked = true;
}
if (!error)
{
@ -928,10 +919,9 @@ bool MariaDBMonitor::check_sql_files()
return rval;
}
static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *monitor,
const MXS_CONFIG_PARAMETER* params)
static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *monitor)
{
return MariaDBMonitor::create(monitor, params);
return MariaDBMonitor::create(monitor);
}
static void destroyInstance(MXS_MONITOR_INSTANCE* monitor)

View File

@ -66,10 +66,9 @@ public:
* 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);
static MariaDBMonitor* create(MXS_MONITOR *monitor);
/**
* Start the monitor instance and return the instance data, creating it if starting for the first time.

View File

@ -38,7 +38,7 @@ MXS_MODULE info =
};
/*lint +e14 */
static MXS_MONITOR_INSTANCE *createInstance(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *);
static MXS_MONITOR_INSTANCE *createInstance(MXS_MONITOR *);
static void destroyInstance(MXS_MONITOR_INSTANCE *);
static MXS_MONITOR_INSTANCE *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *);
static void stopMonitor(MXS_MONITOR_INSTANCE *);
@ -110,8 +110,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
}
/*lint +e14 */
static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *mon,
const MXS_CONFIG_PARAMETER *params)
static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *mon)
{
MM_MONITOR* handle = static_cast<MM_MONITOR*>(MXS_CALLOC(1, sizeof(MM_MONITOR)));
@ -121,20 +120,10 @@ static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *mon,
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");
}
handle->detectStaleMaster = false;
handle->script = NULL;
handle->events = 0;
handle->checked = false;
}
return handle;

View File

@ -30,8 +30,7 @@ static void monitorMain(void *);
/*lint +e14 */
static MXS_MONITOR_INSTANCE *createInstance(MXS_MONITOR *,
const MXS_CONFIG_PARAMETER *params);
static MXS_MONITOR_INSTANCE *createInstance(MXS_MONITOR *);
static void destroyInstance(MXS_MONITOR_INSTANCE*);
static MXS_MONITOR_INSTANCE *startMonitor(MXS_MONITOR *,
const MXS_CONFIG_PARAMETER *params);
@ -104,8 +103,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
}
/*lint +e14 */
static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *mon,
const MXS_CONFIG_PARAMETER *params)
static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *mon)
{
NDBC_MONITOR* handle = static_cast<NDBC_MONITOR*>(MXS_CALLOC(1, sizeof(NDBC_MONITOR)));
@ -116,19 +114,9 @@ static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *mon,
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");
}
handle->script = NULL;
handle->events = 0;
handle->checked = false;
}
return handle;