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

View File

@ -179,7 +179,7 @@ static void auroramon_free(AURORA_MONITOR *handle)
} }
static 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))); 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->script = NULL;
handle->events = 0; handle->events = 0;
handle->monitor = mon; 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; handle->checked = false;
MXS_ERROR("Monitor cannot access servers. Starting the monitor will fail "
"unless problem was temporary or is addressed");
}
} }
return handle; return handle;

View File

@ -30,8 +30,7 @@ static void monitorMain(void *);
/** Log a warning when a bad 'wsrep_local_index' is found */ /** Log a warning when a bad 'wsrep_local_index' is found */
static bool warn_erange_on_local_index = true; static bool warn_erange_on_local_index = true;
static MXS_MONITOR_INSTANCE *createInstance(MXS_MONITOR *mon, static MXS_MONITOR_INSTANCE *createInstance(MXS_MONITOR *mon);
const MXS_CONFIG_PARAMETER *params);
static void destroyInstance(MXS_MONITOR_INSTANCE* monitor); static void destroyInstance(MXS_MONITOR_INSTANCE* monitor);
static MXS_MONITOR_INSTANCE *startMonitor(MXS_MONITOR *, static MXS_MONITOR_INSTANCE *startMonitor(MXS_MONITOR *,
const MXS_CONFIG_PARAMETER *params); const MXS_CONFIG_PARAMETER *params);
@ -118,8 +117,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
} }
static MXS_MONITOR_INSTANCE *createInstance(MXS_MONITOR *mon, static MXS_MONITOR_INSTANCE *createInstance(MXS_MONITOR *mon)
const MXS_CONFIG_PARAMETER *params)
{ {
GALERA_MONITOR* handle = static_cast<GALERA_MONITOR*>(MXS_CALLOC(1, sizeof(GALERA_MONITOR))); GALERA_MONITOR* handle = static_cast<GALERA_MONITOR*>(MXS_CALLOC(1, sizeof(GALERA_MONITOR)));
HASHTABLE *nodes_info = hashtable_alloc(MAX_NUM_SLAVES, 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_size = 0;
handle->cluster_info.c_uuid = NULL; handle->cluster_info.c_uuid = NULL;
handle->monitor = mon; handle->monitor = mon;
if (check_monitor_permissions(mon, "SHOW STATUS LIKE 'wsrep_local_state'"))
{
handle->checked = true;
}
else
{
handle->checked = false; handle->checked = false;
MXS_ERROR("Monitor cannot access servers. Starting the monitor will fail "
"unless problem was temporary or is addressed");
}
} }
else else
{ {

View File

@ -35,9 +35,9 @@ struct GRMon : public MXS_MONITOR_INSTANCE
GRMon(const GRMon&); GRMon(const GRMon&);
GRMon& operator&(const GRMon&); GRMon& operator&(const GRMon&);
public: 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); static GRMon* create_and_start(MXS_MONITOR* monitor, const MXS_CONFIG_PARAMETER* params);
void start(); bool start(const MXS_CONFIG_PARAMETER* params);
void stop(); void stop();
~GRMon(); ~GRMon();
@ -49,17 +49,17 @@ private:
uint64_t m_events; /**< Enabled events */ uint64_t m_events; /**< Enabled events */
MXS_MONITOR* m_monitor; MXS_MONITOR* m_monitor;
GRMon(MXS_MONITOR* monitor, const MXS_CONFIG_PARAMETER *params); GRMon(MXS_MONITOR* monitor);
void main(); void main();
static void main(void* data); static void main(void* data);
}; };
GRMon::GRMon(MXS_MONITOR* monitor, const MXS_CONFIG_PARAMETER* params): GRMon::GRMon(MXS_MONITOR* monitor):
m_shutdown(0), m_shutdown(0),
m_master(NULL), m_master(NULL),
m_script(config_get_string(params, "script")), m_script(NULL),
m_events(config_get_enum(params, "events", mxs_monitor_event_enum_values)), m_events(0),
m_monitor(monitor) 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; GRMon* mon;
MXS_EXCEPTION_GUARD(mon = new GRMon(monitor, params)); MXS_EXCEPTION_GUARD(mon = new GRMon(monitor));
return mon; return mon;
} }
GRMon* GRMon::create_and_start(MXS_MONITOR* monitor, const MXS_CONFIG_PARAMETER* params) 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)
{ {
delete mon; if (!instance->start(params))
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) void GRMon::main(void* data)
@ -103,10 +126,9 @@ void GRMon::stop()
thread_wait(m_thread); thread_wait(m_thread);
} }
static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *mon, static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *mon)
const MXS_CONFIG_PARAMETER *params)
{ {
return GRMon::create(mon, params); return GRMon::create(mon);
} }
static void destroyInstance(MXS_MONITOR_INSTANCE* 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; return rval;
} }
MariaDBMonitor* MariaDBMonitor::create(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params) MariaDBMonitor* MariaDBMonitor::create(MXS_MONITOR *monitor)
{ {
MariaDBMonitor *handle = new MariaDBMonitor(monitor); return 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) 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; error = true;
} }
else
{
handle->m_checked = true;
}
if (!error) if (!error)
{ {
@ -928,10 +919,9 @@ bool MariaDBMonitor::check_sql_files()
return rval; return rval;
} }
static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *monitor, static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *monitor)
const MXS_CONFIG_PARAMETER* params)
{ {
return MariaDBMonitor::create(monitor, params); return MariaDBMonitor::create(monitor);
} }
static void destroyInstance(MXS_MONITOR_INSTANCE* monitor) static void destroyInstance(MXS_MONITOR_INSTANCE* monitor)

View File

@ -66,10 +66,9 @@ public:
* Create the monitor instance and return the instance data. * Create the monitor instance and return the instance data.
* *
* @param monitor General monitor data * @param monitor General monitor data
* @param params Configuration parameters
* @return A pointer to MariaDBMonitor specific data. * @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. * 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 */ /*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 void destroyInstance(MXS_MONITOR_INSTANCE *);
static MXS_MONITOR_INSTANCE *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *); static MXS_MONITOR_INSTANCE *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *);
static void stopMonitor(MXS_MONITOR_INSTANCE *); static void stopMonitor(MXS_MONITOR_INSTANCE *);
@ -110,8 +110,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
} }
/*lint +e14 */ /*lint +e14 */
static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *mon, static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *mon)
const MXS_CONFIG_PARAMETER *params)
{ {
MM_MONITOR* handle = static_cast<MM_MONITOR*>(MXS_CALLOC(1, sizeof(MM_MONITOR))); 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->id = MXS_MONITOR_DEFAULT_ID;
handle->master = NULL; handle->master = NULL;
handle->monitor = mon; handle->monitor = mon;
handle->detectStaleMaster = config_get_bool(params, "detect_stale_master"); handle->detectStaleMaster = false;
handle->script = config_copy_string(params, "script"); handle->script = NULL;
handle->events = config_get_enum(params, "events", mxs_monitor_event_enum_values); handle->events = 0;
if (check_monitor_permissions(mon, "SHOW SLAVE STATUS"))
{
handle->checked = true;
}
else
{
handle->checked = false; handle->checked = false;
MXS_ERROR("Monitor cannot access servers. Starting the monitor will fail "
"unless problem was temporary or is addressed");
}
} }
return handle; return handle;

View File

@ -30,8 +30,7 @@ static void monitorMain(void *);
/*lint +e14 */ /*lint +e14 */
static MXS_MONITOR_INSTANCE *createInstance(MXS_MONITOR *, static MXS_MONITOR_INSTANCE *createInstance(MXS_MONITOR *);
const MXS_CONFIG_PARAMETER *params);
static void destroyInstance(MXS_MONITOR_INSTANCE*); static void destroyInstance(MXS_MONITOR_INSTANCE*);
static MXS_MONITOR_INSTANCE *startMonitor(MXS_MONITOR *, static MXS_MONITOR_INSTANCE *startMonitor(MXS_MONITOR *,
const MXS_CONFIG_PARAMETER *params); const MXS_CONFIG_PARAMETER *params);
@ -104,8 +103,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
} }
/*lint +e14 */ /*lint +e14 */
static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *mon, static MXS_MONITOR_INSTANCE* createInstance(MXS_MONITOR *mon)
const MXS_CONFIG_PARAMETER *params)
{ {
NDBC_MONITOR* handle = static_cast<NDBC_MONITOR*>(MXS_CALLOC(1, sizeof(NDBC_MONITOR))); 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->master = NULL;
handle->monitor = mon; handle->monitor = mon;
handle->script = config_copy_string(params, "script"); handle->script = NULL;
handle->events = config_get_enum(params, "events", mxs_monitor_event_enum_values); handle->events = 0;
if (check_monitor_permissions(mon, "SHOW STATUS LIKE 'Ndb_number_of_ready_data_nodes'"))
{
handle->checked = true;
}
else
{
handle->checked = false; handle->checked = false;
MXS_ERROR("Monitor cannot access servers. Starting the monitor will fail "
"unless problem was temporary or is addressed");
}
} }
return handle; return handle;