Cleanup monitor.hh

Also removes an unused field from several monitors.
This commit is contained in:
Esa Korhonen
2018-12-05 16:31:51 +02:00
parent e979a73cc0
commit 8a8ac26e32
8 changed files with 27 additions and 42 deletions

View File

@ -28,18 +28,14 @@
#include <maxscale/server.hh> #include <maxscale/server.hh>
#include <maxscale/protocol/mysql.hh> #include <maxscale/protocol/mysql.hh>
MXS_BEGIN_DECLS struct MXS_MONITOR;
struct mxs_monitor;
typedef struct mxs_monitor MXS_MONITOR;
/** /**
* An opaque type from which types specific for a particular * An opaque type representing a monitor instance.
* monitor can be derived.
*/ */
typedef struct mxs_monitor_instance struct MXS_MONITOR_INSTANCE
{ {
} MXS_MONITOR_INSTANCE; };
/** /**
* @verbatim * @verbatim
@ -64,7 +60,7 @@ typedef struct mxs_monitor_instance
* *
* @see load_module * @see load_module
*/ */
typedef struct mxs_monitor_api struct MXS_MONITOR_API
{ {
/** /**
* @brief Create the monitor. * @brief Create the monitor.
@ -137,7 +133,7 @@ typedef struct mxs_monitor_api
* @see jansson.h * @see jansson.h
*/ */
json_t* (*diagnostics_json)(const MXS_MONITOR_INSTANCE * monitor); json_t* (*diagnostics_json)(const MXS_MONITOR_INSTANCE * monitor);
} MXS_MONITOR_API; };
/** /**
* The monitor API version number. Any change to the monitor module API * The monitor API version number. Any change to the monitor module API
@ -153,39 +149,31 @@ typedef struct mxs_monitor_api
* @note The values of the capabilities here *must* be between 0x0001 0000 0000 0000 * @note The values of the capabilities here *must* be between 0x0001 0000 0000 0000
* and 0x0080 0000 0000 0000, that is, bits 48 to 55. * and 0x0080 0000 0000 0000, that is, bits 48 to 55.
*/ */
typedef enum monitor_capability enum monitor_capability_t
{ {
MCAP_TYPE_NONE = 0x0 // TODO: remove once monitor capabilities are defined MCAP_TYPE_NONE = 0x0 // TODO: remove once monitor capabilities are defined
} monitor_capability_t; };
/** Monitor's poll frequency */
#define MXS_MON_BASE_INTERVAL_MS 100
#define MXS_MONITOR_DEFAULT_ID 1UL // unsigned long value
#define MAX_MONITOR_USER_LEN 512
#define MAX_MONITOR_PASSWORD_LEN 512
// Monitor state enum // Monitor state enum
typedef enum enum monitor_state_t
{ {
MONITOR_STATE_RUNNING, MONITOR_STATE_RUNNING,
MONITOR_STATE_STOPPING, MONITOR_STATE_STOPPING,
MONITOR_STATE_STOPPED MONITOR_STATE_STOPPED
} monitor_state_t; };
/* Return type of mon_ping_or_connect_to_db(). */ /* Return type of mon_ping_or_connect_to_db(). */
typedef enum enum mxs_connect_result_t
{ {
MONITOR_CONN_EXISTING_OK, /* Existing connection was ok and server replied to ping. */ MONITOR_CONN_EXISTING_OK, /* Existing connection was ok and server replied to ping. */
MONITOR_CONN_NEWCONN_OK, /* No existing connection or no ping reply. New connection created MONITOR_CONN_NEWCONN_OK, /* No existing connection or no ping reply. New connection created
* successfully. */ * successfully. */
MONITOR_CONN_REFUSED, /* No existing connection or no ping reply. Server refused new connection. */ MONITOR_CONN_REFUSED, /* No existing connection or no ping reply. Server refused new connection. */
MONITOR_CONN_TIMEOUT /* No existing connection or no ping reply. Timeout on new connection. */ MONITOR_CONN_TIMEOUT /* No existing connection or no ping reply. Timeout on new connection. */
} mxs_connect_result_t; };
/** Monitor events */ /** Monitor events */
typedef enum enum mxs_monitor_event_t
{ {
UNDEFINED_EVENT = 0, UNDEFINED_EVENT = 0,
MASTER_DOWN_EVENT = (1 << 0), /**< master_down */ MASTER_DOWN_EVENT = (1 << 0), /**< master_down */
@ -210,12 +198,12 @@ typedef enum
NEW_SYNCED_EVENT = (1 << 19), /**< new_synced */ NEW_SYNCED_EVENT = (1 << 19), /**< new_synced */
NEW_DONOR_EVENT = (1 << 20), /**< new_donor */ NEW_DONOR_EVENT = (1 << 20), /**< new_donor */
NEW_NDB_EVENT = (1 << 21), /**< new_ndb */ NEW_NDB_EVENT = (1 << 21), /**< new_ndb */
} mxs_monitor_event_t; };
/** /**
* The linked list of servers that are being monitored by the monitor module. * The linked list of servers that are being monitored by the monitor module.
*/ */
typedef struct monitored_server struct MXS_MONITORED_SERVER
{ {
SERVER* server;/**< The server being monitored */ SERVER* server;/**< The server being monitored */
MYSQL* con; /**< The MySQL connection */ MYSQL* con; /**< The MySQL connection */
@ -224,13 +212,16 @@ typedef struct monitored_server
uint64_t mon_prev_status; /**< Status before starting the current monitor loop */ uint64_t mon_prev_status; /**< Status before starting the current monitor loop */
uint64_t pending_status; /**< Status during current monitor loop */ uint64_t pending_status; /**< Status during current monitor loop */
int64_t disk_space_checked;/**< When was the disk space checked the last time */ int64_t disk_space_checked;/**< When was the disk space checked the last time */
struct monitored_server* next; /**< The next server in the list */ struct MXS_MONITORED_SERVER* next; /**< The next server in the list */
} MXS_MONITORED_SERVER; };
#define MAX_MONITOR_USER_LEN 512
#define MAX_MONITOR_PASSWORD_LEN 512
/** /**
* Representation of the running monitor. * Representation of the running monitor.
*/ */
struct mxs_monitor struct MXS_MONITOR
{ {
char* name; /**< The name of the monitor module */ char* name; /**< The name of the monitor module */
char user[MAX_MONITOR_USER_LEN]; /*< Monitor username */ char user[MAX_MONITOR_USER_LEN]; /*< Monitor username */
@ -271,7 +262,7 @@ struct mxs_monitor
int64_t disk_space_check_interval; /**< How often should a disk space check be made int64_t disk_space_check_interval; /**< How often should a disk space check be made
* at most. */ * at most. */
uint64_t ticks; /**< Number of performed monitoring intervals */ uint64_t ticks; /**< Number of performed monitoring intervals */
struct mxs_monitor* next; /**< Next monitor in the linked list */ struct MXS_MONITOR* next; /**< Next monitor in the linked list */
}; };
/** /**
@ -428,8 +419,6 @@ bool monitor_set_disk_space_threshold(MXS_MONITOR* monitor, const char* disk_spa
// Function for waiting one monitor interval // Function for waiting one monitor interval
void monitor_debug_wait(); void monitor_debug_wait();
MXS_END_DECLS
namespace maxscale namespace maxscale
{ {

View File

@ -2928,6 +2928,9 @@ void MonitorInstance::post_run()
bool MonitorInstance::call_run_one_tick(Worker::Call::action_t action) bool MonitorInstance::call_run_one_tick(Worker::Call::action_t action)
{ {
/** This is both the minimum sleep between two ticks and also the maximum time between early
* wakeup checks. */
const int base_interval_ms = 100;
if (action == Worker::Call::EXECUTE) if (action == Worker::Call::EXECUTE)
{ {
int64_t now = get_time_ms(); int64_t now = get_time_ms();
@ -2946,8 +2949,8 @@ bool MonitorInstance::call_run_one_tick(Worker::Call::action_t action)
int64_t ms_to_next_call = m_monitor->interval - (now - m_loop_called); int64_t ms_to_next_call = m_monitor->interval - (now - m_loop_called);
// ms_to_next_call will be negative, if the run_one_tick() call took // ms_to_next_call will be negative, if the run_one_tick() call took
// longer than one monitor interval. // longer than one monitor interval.
int64_t delay = ((ms_to_next_call <= 0) || (ms_to_next_call >= MXS_MON_BASE_INTERVAL_MS)) ? int64_t delay = ((ms_to_next_call <= 0) || (ms_to_next_call >= base_interval_ms)) ?
MXS_MON_BASE_INTERVAL_MS : ms_to_next_call; base_interval_ms : ms_to_next_call;
delayed_call(delay, &MonitorInstance::call_run_one_tick, this); delayed_call(delay, &MonitorInstance::call_run_one_tick, this);
} }

View File

@ -44,7 +44,6 @@ static bool using_xtrabackup(MXS_MONITORED_SERVER* database, co
GaleraMonitor::GaleraMonitor(MXS_MONITOR* mon) GaleraMonitor::GaleraMonitor(MXS_MONITOR* mon)
: maxscale::MonitorInstanceSimple(mon) : maxscale::MonitorInstanceSimple(mon)
, m_id(MXS_MONITOR_DEFAULT_ID)
, m_disableMasterFailback(0) , m_disableMasterFailback(0)
, m_availableWhenDonor(0) , m_availableWhenDonor(0)
, m_disableMasterRoleSetting(0) , m_disableMasterRoleSetting(0)

View File

@ -55,7 +55,6 @@ protected:
void post_tick(); void post_tick();
private: private:
unsigned long m_id; /**< Monitor ID */
int m_disableMasterFailback; /**< Monitor flag for Galera Cluster Master failback */ int m_disableMasterFailback; /**< Monitor flag for Galera Cluster Master failback */
int m_availableWhenDonor; /**< Monitor flag for Galera Cluster Donor availability */ int m_availableWhenDonor; /**< Monitor flag for Galera Cluster Donor availability */
bool m_disableMasterRoleSetting; /**< Monitor flag to disable setting master role */ bool m_disableMasterRoleSetting; /**< Monitor flag to disable setting master role */

View File

@ -36,7 +36,6 @@ static bool isMySQLEvent(mxs_monitor_event_t event);
MMMonitor::MMMonitor(MXS_MONITOR* monitor) MMMonitor::MMMonitor(MXS_MONITOR* monitor)
: maxscale::MonitorInstanceSimple(monitor) : maxscale::MonitorInstanceSimple(monitor)
, m_id(MXS_MONITOR_DEFAULT_ID)
, m_detectStaleMaster(false) , m_detectStaleMaster(false)
{ {
} }

View File

@ -37,7 +37,6 @@ protected:
void post_tick(); void post_tick();
private: private:
unsigned long m_id; /**< Monitor ID */
int m_detectStaleMaster; /**< Monitor flag for Stale Master detection */ int m_detectStaleMaster; /**< Monitor flag for Stale Master detection */
MMMonitor(MXS_MONITOR* monitor); MMMonitor(MXS_MONITOR* monitor);

View File

@ -24,7 +24,6 @@
NDBCMonitor::NDBCMonitor(MXS_MONITOR* monitor) NDBCMonitor::NDBCMonitor(MXS_MONITOR* monitor)
: maxscale::MonitorInstanceSimple(monitor) : maxscale::MonitorInstanceSimple(monitor)
, m_id(MXS_MONITOR_DEFAULT_ID)
{ {
} }

View File

@ -33,7 +33,5 @@ protected:
void update_server_status(MXS_MONITORED_SERVER* monitored_server); void update_server_status(MXS_MONITORED_SERVER* monitored_server);
private: private:
unsigned long m_id; /**< Monitor ID */
NDBCMonitor(MXS_MONITOR* monitor); NDBCMonitor(MXS_MONITOR* monitor);
}; };