From 93aff0640c2e196faa1bd7ef3054992ed96a0178 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Fri, 4 Jan 2019 17:18:35 +0200 Subject: [PATCH] MXS-2220 Cleanup server header Moved items around in preparation for more changes. --- include/maxscale/server.hh | 198 +++++++++++++++++++------------------ server/core/monitor.cc | 15 +-- server/core/server.cc | 12 +-- 3 files changed, 114 insertions(+), 111 deletions(-) diff --git a/include/maxscale/server.hh b/include/maxscale/server.hh index a3257023a..67f5e80d2 100644 --- a/include/maxscale/server.hh +++ b/include/maxscale/server.hh @@ -31,25 +31,83 @@ extern const char CN_PERSISTPOOLMAX[]; extern const char CN_PROXY_PROTOCOL[]; /** - * Maintenance mode request constants. + * Status bits in the SERVER->status member, which describes the general state of a server. Although the + * individual bits are independent, not all combinations make sense or are used. The bitfield is 64bits wide. */ -const int MAINTENANCE_OFF = -100; -const int MAINTENANCE_NO_CHANGE = 0; -const int MAINTENANCE_ON = 100; -const int MAINTENANCE_FLAG_NOCHECK = 0; -const int MAINTENANCE_FLAG_CHECK = -1; +// Bits used by most monitors +#define SERVER_RUNNING (1 << 0) /**<< The server is up and running */ +#define SERVER_MAINT (1 << 1) /**<< Server is in maintenance mode */ +#define SERVER_AUTH_ERROR (1 << 2) /**<< Authentication error from monitor */ +#define SERVER_MASTER (1 << 3) /**<< The server is a master, i.e. can handle writes */ +#define SERVER_SLAVE (1 << 4) /**<< The server is a slave, i.e. can handle reads */ +// Bits used by MariaDB Monitor (mostly) +#define SERVER_SLAVE_OF_EXT_MASTER (1 << 5) /**<< Server is slave of a non-monitored master */ +#define SERVER_RELAY (1 << 6) /**<< Server is a relay */ +#define SERVER_WAS_MASTER (1 << 7) /**<< Server was a master but lost all slaves. */ +// Bits used by other monitors +#define SERVER_JOINED (1 << 8) /**<< The server is joined in a Galera cluster */ +#define SERVER_NDB (1 << 9) /**<< The server is part of a MySQL cluster setup */ +#define SERVER_MASTER_STICKINESS (1 << 10) /**<< Server Master stickiness */ +// Bits providing general information +#define SERVER_DISK_SPACE_EXHAUSTED (1 << 31) /**<< The disk space of the server is exhausted */ -/* Server connection and usage statistics */ -struct SERVER_STATS +inline bool status_is_usable(uint64_t status) { - int n_connections = 0; /**< Number of connections */ - int n_current = 0; /**< Current connections */ - int n_current_ops = 0; /**< Current active operations */ - int n_persistent = 0; /**< Current persistent pool */ - uint64_t n_new_conn = 0; /**< Times the current pool was empty */ - uint64_t n_from_pool = 0; /**< Times when a connection was available from the pool */ - uint64_t packets = 0; /**< Number of packets routed to this server */ -}; + return (status & (SERVER_RUNNING | SERVER_MAINT)) == SERVER_RUNNING; +} + +inline bool status_is_running(uint64_t status) +{ + return status & SERVER_RUNNING; +} + +inline bool status_is_down(uint64_t status) +{ + return (status & SERVER_RUNNING) == 0; +} + +inline bool status_is_in_maint(uint64_t status) +{ + return status & SERVER_MAINT; +} + +inline bool status_is_master(uint64_t status) +{ + return (status & (SERVER_RUNNING | SERVER_MASTER | SERVER_MAINT)) == (SERVER_RUNNING | SERVER_MASTER); +} + +inline bool status_is_slave(uint64_t status) +{ + return (status & (SERVER_RUNNING | SERVER_SLAVE | SERVER_MAINT)) == (SERVER_RUNNING | SERVER_SLAVE); +} + +inline bool status_is_relay(uint64_t status) +{ + return (status & (SERVER_RUNNING | SERVER_RELAY | SERVER_MAINT)) \ + == (SERVER_RUNNING | SERVER_RELAY); +} + +inline bool status_is_joined(uint64_t status) +{ + return (status & (SERVER_RUNNING | SERVER_JOINED | SERVER_MAINT)) + == (SERVER_RUNNING | SERVER_JOINED); +} + +inline bool status_is_ndb(uint64_t status) +{ + return (status & (SERVER_RUNNING | SERVER_NDB | SERVER_MAINT)) == (SERVER_RUNNING | SERVER_NDB); +} + +inline bool status_is_slave_of_ext_master(uint64_t status) +{ + return (status & (SERVER_RUNNING | SERVER_SLAVE_OF_EXT_MASTER)) + == (SERVER_RUNNING | SERVER_SLAVE_OF_EXT_MASTER); +} + +inline bool status_is_disk_space_exhausted(uint64_t status) +{ + return status & SERVER_DISK_SPACE_EXHAUSTED; +} /** * The SERVER structure defines a backend server. Each server has a name @@ -66,6 +124,15 @@ public: static const int MAX_VERSION_LEN = 256; 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; + enum class Type { MARIADB, @@ -81,6 +148,18 @@ public: uint32_t patch = 0; /**< Patch version */ }; + /* Server connection and usage statistics */ + struct ConnStats + { + int n_connections = 0; /**< Number of connections */ + int n_current = 0; /**< Current connections */ + int n_current_ops = 0; /**< Current active operations */ + int n_persistent = 0; /**< Current persistent pool */ + uint64_t n_new_conn = 0; /**< Times the current pool was empty */ + uint64_t n_from_pool = 0; /**< Times when a connection was available from the pool */ + uint64_t packets = 0; /**< Number of packets routed to this server */ + }; + // Base settings char address[MAX_ADDRESS_LEN] = {'\0'}; /**< Server hostname/IP-address */ int port = -1; /**< Server port */ @@ -97,10 +176,10 @@ public: uint8_t charset = DEFAULT_CHARSET;/**< Character set. Read from backend and sent to client. */ // Statistics and events - SERVER_STATS stats; /**< The server statistics, e.g. number of connections */ - int persistmax = 0; /**< Maximum pool size actually achieved since startup */ - int last_event = 0; /**< The last event that occurred on this server */ - int64_t triggered_at = 0; /**< Time when the last event was triggered */ + ConnStats stats; /**< The server statistics, e.g. number of connections */ + int persistmax = 0; /**< Maximum pool size actually achieved since startup */ + int last_event = 0; /**< The last event that occurred on this server */ + int64_t triggered_at = 0; /**< Time when the last event was triggered */ // Status descriptors. Updated automatically by a monitor or manually by the admin uint64_t status = 0; /**< Current status flag bitmap */ @@ -230,32 +309,6 @@ private: static const int DEFAULT_CHARSET = 0x08; /** The latin1 charset */ }; -/** - * Status bits in the SERVER->status member, which describes the general state of a server. Although the - * individual bits are independent, not all combinations make sense or are used. The bitfield is 64bits wide. - */ -// Bits used by most monitors -#define SERVER_RUNNING (1 << 0) /**<< The server is up and running */ -#define SERVER_MAINT (1 << 1) /**<< Server is in maintenance mode */ -#define SERVER_AUTH_ERROR (1 << 2) /**<< Authentication error from monitor */ -#define SERVER_MASTER (1 << 3) /**<< The server is a master, i.e. can handle writes */ -#define SERVER_SLAVE (1 << 4) /**<< The server is a slave, i.e. can handle reads */ -// Bits used by MariaDB Monitor (mostly) -#define SERVER_SLAVE_OF_EXT_MASTER (1 << 5) /**<< Server is slave of a non-monitored master */ -#define SERVER_RELAY (1 << 6) /**<< Server is a relay */ -#define SERVER_WAS_MASTER (1 << 7) /**<< Server was a master but lost all slaves. */ -// Bits used by other monitors -#define SERVER_JOINED (1 << 8) /**<< The server is joined in a Galera cluster */ -#define SERVER_NDB (1 << 9) /**<< The server is part of a MySQL cluster setup */ -#define SERVER_MASTER_STICKINESS (1 << 10) /**<< Server Master stickiness */ -// Bits providing general information -#define SERVER_DISK_SPACE_EXHAUSTED (1 << 31) /**<< The disk space of the server is exhausted */ - -inline bool status_is_usable(uint64_t status) -{ - return (status & (SERVER_RUNNING | SERVER_MAINT)) == SERVER_RUNNING; -} - /** * Is the server running and not in maintenance? * @@ -267,10 +320,7 @@ inline bool server_is_usable(const SERVER* server) return status_is_usable(server->status); } -inline bool status_is_running(uint64_t status) -{ - return status & SERVER_RUNNING; -} + /** * Is the server running? @@ -283,11 +333,6 @@ inline bool server_is_running(const SERVER* server) return status_is_running(server->status); } -inline bool status_is_down(uint64_t status) -{ - return (status & SERVER_RUNNING) == 0; -} - /** * Is the server down? * @@ -299,11 +344,6 @@ inline bool server_is_down(const SERVER* server) return status_is_down(server->status); } -inline bool status_is_in_maint(uint64_t status) -{ - return status & SERVER_MAINT; -} - /** * Is the server in maintenance mode? * @@ -315,11 +355,6 @@ inline bool server_is_in_maint(const SERVER* server) return status_is_in_maint(server->status); } -inline bool status_is_master(uint64_t status) -{ - return (status & (SERVER_RUNNING | SERVER_MASTER | SERVER_MAINT)) == (SERVER_RUNNING | SERVER_MASTER); -} - /** * Is the server a master? * @@ -331,11 +366,6 @@ inline bool server_is_master(const SERVER* server) return status_is_master(server->status); } -inline bool status_is_slave(uint64_t status) -{ - return (status & (SERVER_RUNNING | SERVER_SLAVE | SERVER_MAINT)) == (SERVER_RUNNING | SERVER_SLAVE); -} - /** * Is the server a slave. * @@ -347,23 +377,11 @@ inline bool server_is_slave(const SERVER* server) return status_is_slave(server->status); } -inline bool status_is_relay(uint64_t status) -{ - return (status & (SERVER_RUNNING | SERVER_RELAY | SERVER_MAINT)) \ - == (SERVER_RUNNING | SERVER_RELAY); -} - inline bool server_is_relay(const SERVER* server) { return status_is_relay(server->status); } -inline bool status_is_joined(uint64_t status) -{ - return (status & (SERVER_RUNNING | SERVER_JOINED | SERVER_MAINT)) - == (SERVER_RUNNING | SERVER_JOINED); -} - /** * Is the server joined Galera node? The server must be running and joined. */ @@ -372,11 +390,6 @@ inline bool server_is_joined(const SERVER* server) return status_is_joined(server->status); } -inline bool status_is_ndb(uint64_t status) -{ - return (status & (SERVER_RUNNING | SERVER_NDB | SERVER_MAINT)) == (SERVER_RUNNING | SERVER_NDB); -} - /** * Is the server a SQL node in MySQL Cluster? The server must be running and with NDB status */ @@ -391,22 +404,11 @@ inline bool server_is_in_cluster(const SERVER* server) & (SERVER_MASTER | SERVER_SLAVE | SERVER_RELAY | SERVER_JOINED | SERVER_NDB)) != 0; } -inline bool status_is_slave_of_ext_master(uint64_t status) -{ - return (status & (SERVER_RUNNING | SERVER_SLAVE_OF_EXT_MASTER)) - == (SERVER_RUNNING | SERVER_SLAVE_OF_EXT_MASTER); -} - inline bool server_is_slave_of_ext_master(const SERVER* server) { return status_is_slave_of_ext_master(server->status); } -inline bool status_is_disk_space_exhausted(uint64_t status) -{ - return status & SERVER_DISK_SPACE_EXHAUSTED; -} - inline bool server_is_disk_space_exhausted(const SERVER* server) { return status_is_disk_space_exhausted(server->status); diff --git a/server/core/monitor.cc b/server/core/monitor.cc index f8f441b0a..1144d7618 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -140,7 +140,7 @@ MXS_MONITOR* monitor_create(const char* name, const char* module, MXS_CONFIG_PAR mon->script_timeout = config_get_integer(params, CN_SCRIPT_TIMEOUT); mon->script = config_get_string(params, CN_SCRIPT); mon->events = config_get_enum(params, CN_EVENTS, mxs_monitor_event_enum_values); - mon->check_maintenance_flag = MAINTENANCE_FLAG_NOCHECK; + mon->check_maintenance_flag = SERVER::MAINTENANCE_FLAG_NOCHECK; mon->ticks = 0; mon->parameters = NULL; memset(mon->journal_hash, 0, sizeof(mon->journal_hash)); @@ -1696,20 +1696,21 @@ void monitor_check_maintenance_requests(MXS_MONITOR* monitor) { /* 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. */ - int flags_changed = atomic_exchange_int(&monitor->check_maintenance_flag, MAINTENANCE_FLAG_NOCHECK); - if (flags_changed != MAINTENANCE_FLAG_NOCHECK) + int flags_changed = atomic_exchange_int(&monitor->check_maintenance_flag, + SERVER::MAINTENANCE_FLAG_NOCHECK); + if (flags_changed != SERVER::MAINTENANCE_FLAG_NOCHECK) { MXS_MONITORED_SERVER* ptr = monitor->monitored_servers; while (ptr) { // The only server status bit the admin may change is the [Maintenance] bit. - int admin_msg = atomic_exchange_int(&ptr->server->maint_request, MAINTENANCE_NO_CHANGE); - if (admin_msg == MAINTENANCE_ON) + int admin_msg = atomic_exchange_int(&ptr->server->maint_request, SERVER::MAINTENANCE_NO_CHANGE); + if (admin_msg == SERVER::MAINTENANCE_ON) { // TODO: Change to writing MONITORED_SERVER->pending status instead once cleanup done. server_set_status_nolock(ptr->server, SERVER_MAINT); } - else if (admin_msg == MAINTENANCE_OFF) + else if (admin_msg == SERVER::MAINTENANCE_OFF) { server_clear_status_nolock(ptr->server, SERVER_MAINT); } @@ -2927,7 +2928,7 @@ bool MonitorInstance::call_run_one_tick(Worker::Call::action_t action) // Enough time has passed, if ((now - m_loop_called > static_cast(m_monitor->interval)) // or maintenance flag is set, - || atomic_load_int(&m_monitor->check_maintenance_flag) == MAINTENANCE_FLAG_CHECK + || atomic_load_int(&m_monitor->check_maintenance_flag) == SERVER::MAINTENANCE_FLAG_CHECK // or a monitor-specific condition is met. || immediate_tick_required()) { diff --git a/server/core/server.cc b/server/core/server.cc index 89bcef451..b4d3c4d33 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -1070,13 +1070,13 @@ bool mxs::server_set_status(SERVER* srv, int bit, string* errmsg_out) else if (bit & SERVER_MAINT) { // Warn if the previous request hasn't been read. - int previous_request = atomic_exchange_int(&server->maint_request, MAINTENANCE_ON); + int previous_request = atomic_exchange_int(&server->maint_request, SERVER::MAINTENANCE_ON); written = true; - if (previous_request != MAINTENANCE_NO_CHANGE) + if (previous_request != SERVER::MAINTENANCE_NO_CHANGE) { MXS_WARNING(WRN_REQUEST_OVERWRITTEN); } - atomic_store_int(&mon->check_maintenance_flag, MAINTENANCE_FLAG_CHECK); + atomic_store_int(&mon->check_maintenance_flag, SERVER::MAINTENANCE_FLAG_CHECK); } } else @@ -1117,13 +1117,13 @@ bool mxs::server_clear_status(SERVER* srv, int bit, string* errmsg_out) else if (bit & SERVER_MAINT) { // Warn if the previous request hasn't been read. - int previous_request = atomic_exchange_int(&server->maint_request, MAINTENANCE_OFF); + int previous_request = atomic_exchange_int(&server->maint_request, SERVER::MAINTENANCE_OFF); written = true; - if (previous_request != MAINTENANCE_NO_CHANGE) + if (previous_request != SERVER::MAINTENANCE_NO_CHANGE) { MXS_WARNING(WRN_REQUEST_OVERWRITTEN); } - atomic_store_int(&mon->check_maintenance_flag, MAINTENANCE_FLAG_CHECK); + atomic_store_int(&mon->check_maintenance_flag, SERVER::MAINTENANCE_FLAG_CHECK); } } else