MXS-2273 Move constants to more appropriate locations
Constants now used in the context of MXS_MONITORED_SERVER or Monitor are now moved from SERVER to MXS_MONITORED_SERVER or Monitor, respectively.
This commit is contained in:
@ -131,6 +131,13 @@ class MXS_MONITORED_SERVER
|
|||||||
public:
|
public:
|
||||||
MXS_MONITORED_SERVER(SERVER* server);
|
MXS_MONITORED_SERVER(SERVER* server);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maintenance mode request constants.
|
||||||
|
*/
|
||||||
|
static const int MAINTENANCE_OFF = -100;
|
||||||
|
static const int MAINTENANCE_NO_CHANGE = 0;
|
||||||
|
static const int MAINTENANCE_ON = 100;
|
||||||
|
|
||||||
SERVER* server = nullptr; /**< The server being monitored */
|
SERVER* server = nullptr; /**< The server being monitored */
|
||||||
MYSQL* con = nullptr; /**< The MySQL connection */
|
MYSQL* con = nullptr; /**< The MySQL connection */
|
||||||
bool log_version_err = true;
|
bool log_version_err = true;
|
||||||
@ -138,7 +145,7 @@ public:
|
|||||||
uint64_t mon_prev_status = -1; /**< Status before starting the current monitor loop */
|
uint64_t mon_prev_status = -1; /**< Status before starting the current monitor loop */
|
||||||
uint64_t pending_status = 0; /**< Status during current monitor loop */
|
uint64_t pending_status = 0; /**< Status during current monitor loop */
|
||||||
int64_t disk_space_checked = 0; /**< When was the disk space checked the last time */
|
int64_t disk_space_checked = 0; /**< When was the disk space checked the last time */
|
||||||
int maint_request = SERVER::MAINTENANCE_NO_CHANGE; /**< Is admin requesting Maintenance=ON/OFF on the
|
int maint_request = MAINTENANCE_NO_CHANGE; /**< Is admin requesting Maintenance=ON/OFF on the
|
||||||
* server? */
|
* server? */
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -155,6 +162,9 @@ public:
|
|||||||
virtual ~Monitor();
|
virtual ~Monitor();
|
||||||
virtual bool configure(const MXS_CONFIG_PARAMETER* params) = 0;
|
virtual bool configure(const MXS_CONFIG_PARAMETER* params) = 0;
|
||||||
|
|
||||||
|
static const int MAINTENANCE_FLAG_NOCHECK = 0;
|
||||||
|
static const int MAINTENANCE_FLAG_CHECK = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the monitor. If the monitor requires polling of the servers, it should create
|
* Starts the monitor. If the monitor requires polling of the servers, it should create
|
||||||
* a separate monitoring thread.
|
* a separate monitoring thread.
|
||||||
@ -230,7 +240,7 @@ public:
|
|||||||
/** The state of the monitor. This should ONLY be written to by the admin thread. */
|
/** The state of the monitor. This should ONLY be written to by the admin thread. */
|
||||||
monitor_state_t m_state {MONITOR_STATE_STOPPED};
|
monitor_state_t m_state {MONITOR_STATE_STOPPED};
|
||||||
/** Set when admin requests a maintenance status change. */
|
/** Set when admin requests a maintenance status change. */
|
||||||
int m_check_maintenance_flag {SERVER::MAINTENANCE_FLAG_NOCHECK};
|
int check_maintenance_flag = MAINTENANCE_FLAG_NOCHECK;
|
||||||
|
|
||||||
uint64_t m_ticks {0}; /**< Number of performed monitoring intervals */
|
uint64_t m_ticks {0}; /**< Number of performed monitoring intervals */
|
||||||
uint8_t m_journal_hash[SHA_DIGEST_LENGTH]; /**< SHA1 hash of the latest written journal */
|
uint8_t m_journal_hash[SHA_DIGEST_LENGTH]; /**< SHA1 hash of the latest written journal */
|
||||||
|
@ -131,15 +131,6 @@ public:
|
|||||||
static const int MAX_VERSION_LEN = 256;
|
static const int MAX_VERSION_LEN = 256;
|
||||||
static const int RLAG_UNDEFINED = -1; // Default replication lag value
|
static const int RLAG_UNDEFINED = -1; // Default replication lag value
|
||||||
|
|
||||||
/**
|
|
||||||
* Maintenance mode request constants.
|
|
||||||
*/
|
|
||||||
static const int MAINTENANCE_OFF = -100;
|
|
||||||
static const int MAINTENANCE_NO_CHANGE = 0;
|
|
||||||
static const int MAINTENANCE_ON = 100;
|
|
||||||
static const int MAINTENANCE_FLAG_NOCHECK = 0;
|
|
||||||
static const int MAINTENANCE_FLAG_CHECK = -1;
|
|
||||||
|
|
||||||
// A mapping from a path to a percentage, e.g.: "/disk" -> 80.
|
// A mapping from a path to a percentage, e.g.: "/disk" -> 80.
|
||||||
typedef std::unordered_map<std::string, int32_t> DiskSpaceLimits;
|
typedef std::unordered_map<std::string, int32_t> DiskSpaceLimits;
|
||||||
|
|
||||||
|
@ -1588,20 +1588,21 @@ void monitor_check_maintenance_requests(Monitor* monitor)
|
|||||||
{
|
{
|
||||||
/* In theory, the admin may be modifying the server maintenance status during this function. The overall
|
/* In theory, the admin may be modifying the server maintenance status during this function. The overall
|
||||||
* maintenance flag should be read-written atomically to prevent missing a value. */
|
* maintenance flag should be read-written atomically to prevent missing a value. */
|
||||||
int flags_changed = atomic_exchange_int(&monitor->m_check_maintenance_flag,
|
int flags_changed = atomic_exchange_int(&monitor->check_maintenance_flag,
|
||||||
SERVER::MAINTENANCE_FLAG_NOCHECK);
|
Monitor::MAINTENANCE_FLAG_NOCHECK);
|
||||||
if (flags_changed != SERVER::MAINTENANCE_FLAG_NOCHECK)
|
if (flags_changed != Monitor::MAINTENANCE_FLAG_NOCHECK)
|
||||||
{
|
{
|
||||||
for (auto ptr : monitor->m_servers)
|
for (auto ptr : monitor->m_servers)
|
||||||
{
|
{
|
||||||
// The only server status bit the admin may change is the [Maintenance] bit.
|
// The only server status bit the admin may change is the [Maintenance] bit.
|
||||||
int admin_msg = atomic_exchange_int(&ptr->maint_request, SERVER::MAINTENANCE_NO_CHANGE);
|
int admin_msg = atomic_exchange_int(&ptr->maint_request,
|
||||||
if (admin_msg == SERVER::MAINTENANCE_ON)
|
MXS_MONITORED_SERVER::MAINTENANCE_NO_CHANGE);
|
||||||
|
if (admin_msg == MXS_MONITORED_SERVER::MAINTENANCE_ON)
|
||||||
{
|
{
|
||||||
// TODO: Change to writing MONITORED_SERVER->pending status instead once cleanup done.
|
// TODO: Change to writing MONITORED_SERVER->pending status instead once cleanup done.
|
||||||
ptr->server->set_status(SERVER_MAINT);
|
ptr->server->set_status(SERVER_MAINT);
|
||||||
}
|
}
|
||||||
else if (admin_msg == SERVER::MAINTENANCE_OFF)
|
else if (admin_msg == MXS_MONITORED_SERVER::MAINTENANCE_OFF)
|
||||||
{
|
{
|
||||||
ptr->server->clear_status(SERVER_MAINT);
|
ptr->server->clear_status(SERVER_MAINT);
|
||||||
}
|
}
|
||||||
@ -2386,15 +2387,16 @@ bool Monitor::set_server_status(SERVER* srv, int bit, string* errmsg_out)
|
|||||||
{
|
{
|
||||||
/* Maintenance is set/cleared using a special variable which the monitor reads when
|
/* Maintenance is set/cleared using a special variable which the monitor reads when
|
||||||
* starting the next update cycle. */
|
* starting the next update cycle. */
|
||||||
int previous_request = atomic_exchange_int(&msrv->maint_request, SERVER::MAINTENANCE_ON);
|
int previous_request = atomic_exchange_int(&msrv->maint_request,
|
||||||
|
MXS_MONITORED_SERVER::MAINTENANCE_ON);
|
||||||
written = true;
|
written = true;
|
||||||
// Warn if the previous request hasn't been read.
|
// Warn if the previous request hasn't been read.
|
||||||
if (previous_request != SERVER::MAINTENANCE_NO_CHANGE)
|
if (previous_request != MXS_MONITORED_SERVER::MAINTENANCE_NO_CHANGE)
|
||||||
{
|
{
|
||||||
MXS_WARNING(WRN_REQUEST_OVERWRITTEN);
|
MXS_WARNING(WRN_REQUEST_OVERWRITTEN);
|
||||||
}
|
}
|
||||||
// Also set a flag so the next loop happens sooner.
|
// Also set a flag so the next loop happens sooner.
|
||||||
atomic_store_int(&this->check_maintenance_flag, SERVER::MAINTENANCE_FLAG_CHECK);
|
atomic_store_int(&this->check_maintenance_flag, Monitor::MAINTENANCE_FLAG_CHECK);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2440,13 +2442,14 @@ bool Monitor::clear_server_status(SERVER* srv, int bit, string* errmsg_out)
|
|||||||
else if (bit & SERVER_MAINT)
|
else if (bit & SERVER_MAINT)
|
||||||
{
|
{
|
||||||
// Warn if the previous request hasn't been read.
|
// Warn if the previous request hasn't been read.
|
||||||
int previous_request = atomic_exchange_int(&msrv->maint_request, SERVER::MAINTENANCE_OFF);
|
int previous_request = atomic_exchange_int(&msrv->maint_request,
|
||||||
|
MXS_MONITORED_SERVER::MAINTENANCE_OFF);
|
||||||
written = true;
|
written = true;
|
||||||
if (previous_request != SERVER::MAINTENANCE_NO_CHANGE)
|
if (previous_request != MXS_MONITORED_SERVER::MAINTENANCE_NO_CHANGE)
|
||||||
{
|
{
|
||||||
MXS_WARNING(WRN_REQUEST_OVERWRITTEN);
|
MXS_WARNING(WRN_REQUEST_OVERWRITTEN);
|
||||||
}
|
}
|
||||||
atomic_store_int(&this->check_maintenance_flag, SERVER::MAINTENANCE_FLAG_CHECK);
|
atomic_store_int(&this->check_maintenance_flag, Monitor::MAINTENANCE_FLAG_CHECK);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2917,7 +2920,7 @@ bool MonitorWorker::call_run_one_tick(Worker::Call::action_t action)
|
|||||||
// Enough time has passed,
|
// Enough time has passed,
|
||||||
if ((now - m_loop_called > m_settings.interval)
|
if ((now - m_loop_called > m_settings.interval)
|
||||||
// or maintenance flag is set,
|
// or maintenance flag is set,
|
||||||
|| atomic_load_int(&m_check_maintenance_flag) == SERVER::MAINTENANCE_FLAG_CHECK
|
|| atomic_load_int(&this->check_maintenance_flag) == Monitor::MAINTENANCE_FLAG_CHECK
|
||||||
// or a monitor-specific condition is met.
|
// or a monitor-specific condition is met.
|
||||||
|| immediate_tick_required())
|
|| immediate_tick_required())
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user