Remove duplicate monitor state definitions
The state is still stored in two different variables. Also, removed the ALLOC and FREED states.
This commit is contained in:
@ -159,25 +159,17 @@ typedef enum monitor_capability
|
|||||||
/** Monitor's poll frequency */
|
/** Monitor's poll frequency */
|
||||||
#define MXS_MON_BASE_INTERVAL_MS 100
|
#define MXS_MON_BASE_INTERVAL_MS 100
|
||||||
|
|
||||||
#define MXS_MONITOR_RUNNING 1
|
|
||||||
#define MXS_MONITOR_STOPPING 2
|
|
||||||
#define MXS_MONITOR_STOPPED 3
|
|
||||||
|
|
||||||
#define MXS_MONITOR_DEFAULT_ID 1UL // unsigned long value
|
#define MXS_MONITOR_DEFAULT_ID 1UL // unsigned long value
|
||||||
|
|
||||||
#define MAX_MONITOR_USER_LEN 512
|
#define MAX_MONITOR_USER_LEN 512
|
||||||
#define MAX_MONITOR_PASSWORD_LEN 512
|
#define MAX_MONITOR_PASSWORD_LEN 512
|
||||||
|
|
||||||
/**
|
// Monitor state enum
|
||||||
* Monitor state bit mask values
|
|
||||||
*/
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
MONITOR_STATE_ALLOC = 0x00,
|
MONITOR_STATE_RUNNING,
|
||||||
MONITOR_STATE_RUNNING = 0x01,
|
MONITOR_STATE_STOPPING,
|
||||||
MONITOR_STATE_STOPPING = 0x02,
|
MONITOR_STATE_STOPPED
|
||||||
MONITOR_STATE_STOPPED = 0x04,
|
|
||||||
MONITOR_STATE_FREED = 0x08
|
|
||||||
} monitor_state_t;
|
} monitor_state_t;
|
||||||
|
|
||||||
/* Return type of mon_ping_or_connect_to_db(). */
|
/* Return type of mon_ping_or_connect_to_db(). */
|
||||||
|
|||||||
@ -52,7 +52,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool is_running() const
|
bool is_running() const
|
||||||
{
|
{
|
||||||
return state() == MXS_MONITOR_RUNNING;
|
return state() == MONITOR_STATE_RUNNING;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -83,6 +83,7 @@ static SPINLOCK monLock = SPINLOCK_INIT;
|
|||||||
static void monitor_server_free_all(MXS_MONITORED_SERVER *servers);
|
static void monitor_server_free_all(MXS_MONITORED_SERVER *servers);
|
||||||
static void remove_server_journal(MXS_MONITOR *monitor);
|
static void remove_server_journal(MXS_MONITOR *monitor);
|
||||||
static bool journal_is_stale(MXS_MONITOR *monitor, time_t max_age);
|
static bool journal_is_stale(MXS_MONITOR *monitor, time_t max_age);
|
||||||
|
static const char* monitor_state_to_string(monitor_state_t state);
|
||||||
|
|
||||||
/** Server type specific bits */
|
/** Server type specific bits */
|
||||||
static uint64_t server_type_bits = SERVER_MASTER | SERVER_SLAVE | SERVER_JOINED | SERVER_NDB;
|
static uint64_t server_type_bits = SERVER_MASTER | SERVER_SLAVE | SERVER_JOINED | SERVER_NDB;
|
||||||
@ -123,7 +124,7 @@ MXS_MONITOR* monitor_create(const char *name, const char *module, MXS_CONFIG_PAR
|
|||||||
|
|
||||||
mon->api = api;
|
mon->api = api;
|
||||||
mon->active = true;
|
mon->active = true;
|
||||||
mon->state = MONITOR_STATE_ALLOC;
|
mon->state = MONITOR_STATE_STOPPED;
|
||||||
mon->name = my_name;
|
mon->name = my_name;
|
||||||
mon->module_name = my_module;
|
mon->module_name = my_module;
|
||||||
mon->monitored_servers = NULL;
|
mon->monitored_servers = NULL;
|
||||||
@ -203,7 +204,6 @@ monitor_destroy(MXS_MONITOR *mon)
|
|||||||
}
|
}
|
||||||
spinlock_release(&monLock);
|
spinlock_release(&monLock);
|
||||||
mon->api->destroyInstance(mon->instance);
|
mon->api->destroyInstance(mon->instance);
|
||||||
mon->state = MONITOR_STATE_FREED;
|
|
||||||
delete mon->disk_space_threshold;
|
delete mon->disk_space_threshold;
|
||||||
config_parameter_free(mon->parameters);
|
config_parameter_free(mon->parameters);
|
||||||
monitor_server_free_all(mon->monitored_servers);
|
monitor_server_free_all(mon->monitored_servers);
|
||||||
@ -237,8 +237,8 @@ monitor_start(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
|
|||||||
{
|
{
|
||||||
spinlock_acquire(&monitor->lock);
|
spinlock_acquire(&monitor->lock);
|
||||||
|
|
||||||
// Only start the monitor if it's newly created or currently stopped.
|
// Only start the monitor if it's stopped.
|
||||||
if (monitor->state == MONITOR_STATE_ALLOC || monitor->state == MONITOR_STATE_STOPPED)
|
if (monitor->state == MONITOR_STATE_STOPPED)
|
||||||
{
|
{
|
||||||
if (journal_is_stale(monitor, monitor->journal_max_age))
|
if (journal_is_stale(monitor, monitor->journal_max_age))
|
||||||
{
|
{
|
||||||
@ -538,30 +538,9 @@ monitor_show_all(DCB *dcb)
|
|||||||
void
|
void
|
||||||
monitor_show(DCB *dcb, MXS_MONITOR *monitor)
|
monitor_show(DCB *dcb, MXS_MONITOR *monitor)
|
||||||
{
|
{
|
||||||
const char *state;
|
|
||||||
|
|
||||||
switch (monitor->state)
|
|
||||||
{
|
|
||||||
case MONITOR_STATE_RUNNING:
|
|
||||||
state = "Running";
|
|
||||||
break;
|
|
||||||
case MONITOR_STATE_STOPPING:
|
|
||||||
state = "Stopping";
|
|
||||||
break;
|
|
||||||
case MONITOR_STATE_STOPPED:
|
|
||||||
state = "Stopped";
|
|
||||||
break;
|
|
||||||
case MONITOR_STATE_ALLOC:
|
|
||||||
state = "Allocated";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
state = "Unknown";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
dcb_printf(dcb, "Monitor: %p\n", monitor);
|
dcb_printf(dcb, "Monitor: %p\n", monitor);
|
||||||
dcb_printf(dcb, "Name: %s\n", monitor->name);
|
dcb_printf(dcb, "Name: %s\n", monitor->name);
|
||||||
dcb_printf(dcb, "State: %s\n", state);
|
dcb_printf(dcb, "State: %s\n", monitor_state_to_string(monitor->state));
|
||||||
dcb_printf(dcb, "Times monitored: %lu\n", monitor->ticks);
|
dcb_printf(dcb, "Times monitored: %lu\n", monitor->ticks);
|
||||||
dcb_printf(dcb, "Sampling interval: %lu milliseconds\n", monitor->interval);
|
dcb_printf(dcb, "Sampling interval: %lu milliseconds\n", monitor->interval);
|
||||||
dcb_printf(dcb, "Connect Timeout: %i seconds\n", monitor->connect_timeout);
|
dcb_printf(dcb, "Connect Timeout: %i seconds\n", monitor->connect_timeout);
|
||||||
@ -1774,7 +1753,7 @@ void mon_process_state_changes(MXS_MONITOR *monitor, const char *script, uint64_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* monitor_state_to_string(int state)
|
static const char* monitor_state_to_string(monitor_state_t state)
|
||||||
{
|
{
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
@ -1787,9 +1766,6 @@ static const char* monitor_state_to_string(int state)
|
|||||||
case MONITOR_STATE_STOPPED:
|
case MONITOR_STATE_STOPPED:
|
||||||
return "Stopped";
|
return "Stopped";
|
||||||
|
|
||||||
case MONITOR_STATE_ALLOC:
|
|
||||||
return "Allocated";
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ss_dassert(false);
|
ss_dassert(false);
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
@ -2480,7 +2456,7 @@ namespace maxscale
|
|||||||
MonitorInstance::MonitorInstance(MXS_MONITOR* pMonitor)
|
MonitorInstance::MonitorInstance(MXS_MONITOR* pMonitor)
|
||||||
: m_monitor(pMonitor)
|
: m_monitor(pMonitor)
|
||||||
, m_master(NULL)
|
, m_master(NULL)
|
||||||
, m_state(MXS_MONITOR_STOPPED)
|
, m_state(MONITOR_STATE_STOPPED)
|
||||||
, m_shutdown(0)
|
, m_shutdown(0)
|
||||||
, m_checked(false)
|
, m_checked(false)
|
||||||
, m_loop_called(0)
|
, m_loop_called(0)
|
||||||
@ -2499,14 +2475,14 @@ int32_t MonitorInstance::state() const
|
|||||||
void MonitorInstance::stop()
|
void MonitorInstance::stop()
|
||||||
{
|
{
|
||||||
// This is always called in single-thread context.
|
// This is always called in single-thread context.
|
||||||
ss_dassert(m_state == MXS_MONITOR_RUNNING);
|
ss_dassert(m_state == MONITOR_STATE_RUNNING);
|
||||||
|
|
||||||
if (state() == MXS_MONITOR_RUNNING)
|
if (state() == MONITOR_STATE_RUNNING)
|
||||||
{
|
{
|
||||||
atomic_store_int32(&m_state, MXS_MONITOR_STOPPING);
|
atomic_store_int32(&m_state, MONITOR_STATE_STOPPING);
|
||||||
Worker::shutdown();
|
Worker::shutdown();
|
||||||
Worker::join();
|
Worker::join();
|
||||||
atomic_store_int32(&m_state, MXS_MONITOR_STOPPED);
|
atomic_store_int32(&m_state, MONITOR_STATE_STOPPED);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2528,9 +2504,9 @@ bool MonitorInstance::start(const MXS_CONFIG_PARAMETER* pParams)
|
|||||||
bool started = false;
|
bool started = false;
|
||||||
|
|
||||||
ss_dassert(Worker::state() == Worker::STOPPED);
|
ss_dassert(Worker::state() == Worker::STOPPED);
|
||||||
ss_dassert(m_state == MXS_MONITOR_STOPPED);
|
ss_dassert(m_state == MONITOR_STATE_STOPPED);
|
||||||
|
|
||||||
if (state() == MXS_MONITOR_STOPPED)
|
if (state() == MONITOR_STATE_STOPPED)
|
||||||
{
|
{
|
||||||
if (!m_checked)
|
if (!m_checked)
|
||||||
{
|
{
|
||||||
@ -2562,7 +2538,7 @@ bool MonitorInstance::start(const MXS_CONFIG_PARAMETER* pParams)
|
|||||||
// state has been updated.
|
// state has been updated.
|
||||||
m_semaphore.wait();
|
m_semaphore.wait();
|
||||||
|
|
||||||
started = (atomic_load_int32(&m_state) == MXS_MONITOR_RUNNING);
|
started = (atomic_load_int32(&m_state) == MONITOR_STATE_RUNNING);
|
||||||
|
|
||||||
if (!started)
|
if (!started)
|
||||||
{
|
{
|
||||||
@ -2866,7 +2842,7 @@ bool MonitorInstance::pre_run()
|
|||||||
{
|
{
|
||||||
rv = true;
|
rv = true;
|
||||||
|
|
||||||
atomic_store_int32(&m_state, MXS_MONITOR_RUNNING);
|
atomic_store_int32(&m_state, MONITOR_STATE_RUNNING);
|
||||||
m_semaphore.post();
|
m_semaphore.post();
|
||||||
|
|
||||||
load_server_journal(m_monitor, &m_master);
|
load_server_journal(m_monitor, &m_master);
|
||||||
|
|||||||
@ -1014,7 +1014,7 @@ bool MariaDBMonitor::check_sql_files()
|
|||||||
bool MariaDBMonitor::execute_manual_command(std::function<void (void)> command, json_t** error_out)
|
bool MariaDBMonitor::execute_manual_command(std::function<void (void)> command, json_t** error_out)
|
||||||
{
|
{
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
if (state() != MXS_MONITOR_RUNNING)
|
if (state() != MONITOR_STATE_RUNNING)
|
||||||
{
|
{
|
||||||
PRINT_MXS_JSON_ERROR(error_out, "The monitor is not running, cannot execute manual command.");
|
PRINT_MXS_JSON_ERROR(error_out, "The monitor is not running, cannot execute manual command.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user