diff --git a/server/core/config.cc b/server/core/config.cc index fc4c8f123..ce416d7ca 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -62,7 +62,7 @@ #include "internal/event.hh" #include "internal/filter.hh" #include "internal/modules.h" -#include "internal/monitor.h" +#include "internal/monitor.hh" #include "internal/service.hh" using std::set; diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index 02c580dee..9a73bd6e2 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -37,7 +37,7 @@ #include "internal/config.hh" #include "internal/filter.hh" #include "internal/modules.h" -#include "internal/monitor.h" +#include "internal/monitor.hh" #include "internal/query_classifier.hh" typedef std::set StringSet; diff --git a/server/core/gateway.cc b/server/core/gateway.cc index 980bd5d1e..22b58ec79 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -68,7 +68,7 @@ #include "internal/config.hh" #include "internal/maxscale.h" #include "internal/modules.h" -#include "internal/monitor.h" +#include "internal/monitor.hh" #include "internal/poll.hh" #include "internal/service.hh" diff --git a/server/core/internal/monitor.h b/server/core/internal/monitor.h deleted file mode 100644 index 1f8956c94..000000000 --- a/server/core/internal/monitor.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2018 MariaDB Corporation Ab - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file and at www.mariadb.com/bsl11. - * - * Change Date: 2022-01-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2 or later of the General - * Public License. - */ -#pragma once - -/** - * @file core/maxscale/monitor.h - The private monitor interface - */ - -#include -#include "externcmd.h" - -MXS_BEGIN_DECLS - -#define MON_ARG_MAX 8192 - -#define DEFAULT_CONNECT_TIMEOUT 3 -#define DEFAULT_READ_TIMEOUT 3 -#define DEFAULT_WRITE_TIMEOUT 3 -#define DEFAULT_CONNECTION_ATTEMPTS 1 - -#define DEFAULT_MONITOR_INTERVAL 2000 // in milliseconds - -/** Default maximum journal age in seconds */ -#define DEFAULT_JOURNAL_MAX_AGE 28800 - -/** Default script execution timeout in seconds */ -#define DEFAULT_SCRIPT_TIMEOUT 90 - -/** - * Monitor network timeout types - */ -typedef enum -{ - MONITOR_CONNECT_TIMEOUT = 0, - MONITOR_READ_TIMEOUT = 1, - MONITOR_WRITE_TIMEOUT = 2, - MONITOR_CONNECT_ATTEMPTS = 3 -} monitor_timeouts_t; - -/* Is not really an event as the other values, but is a valid config setting and also the default. - * Bitmask value matches all events. */ -static const MXS_ENUM_VALUE mxs_monitor_event_default_enum = {"all", ~0ULL}; -static const MXS_ENUM_VALUE mxs_monitor_event_enum_values[] = -{ - mxs_monitor_event_default_enum, - {"master_down", MASTER_DOWN_EVENT }, - {"master_up", MASTER_UP_EVENT }, - {"slave_down", SLAVE_DOWN_EVENT }, - {"slave_up", SLAVE_UP_EVENT }, - {"server_down", SERVER_DOWN_EVENT }, - {"server_up", SERVER_UP_EVENT }, - {"synced_down", SYNCED_DOWN_EVENT }, - {"synced_up", SYNCED_UP_EVENT }, - {"donor_down", DONOR_DOWN_EVENT }, - {"donor_up", DONOR_UP_EVENT }, - {"ndb_down", NDB_DOWN_EVENT }, - {"ndb_up", NDB_UP_EVENT }, - {"lost_master", LOST_MASTER_EVENT }, - {"lost_slave", LOST_SLAVE_EVENT }, - {"lost_synced", LOST_SYNCED_EVENT }, - {"lost_donor", LOST_DONOR_EVENT }, - {"lost_ndb", LOST_NDB_EVENT }, - {"new_master", NEW_MASTER_EVENT }, - {"new_slave", NEW_SLAVE_EVENT }, - {"new_synced", NEW_SYNCED_EVENT }, - {"new_donor", NEW_DONOR_EVENT }, - {"new_ndb", NEW_NDB_EVENT }, - {NULL} -}; - -MXS_MONITOR* monitor_create(const char*, const char*, MXS_CONFIG_PARAMETER* params); -void monitor_destroy(MXS_MONITOR*); - -void monitor_start(MXS_MONITOR*, const MXS_CONFIG_PARAMETER*); -void monitor_stop(MXS_MONITOR*); - -/** - * @brief Mark monitor as deactivated - * - * A deactivated monitor appears not to exist, as if it had been - * destroyed. - * - * @param monitor - */ -void monitor_deactivate(MXS_MONITOR* monitor); - -void monitor_stop_all(); -void monitor_start_all(); - -/** - * @brief Destroys all monitors. At this point all monitors should - * have been stopped. - * - * @attn Must only be called in single-thread context at system shutdown. - */ -void monitor_destroy_all(); - -MXS_MONITOR* monitor_find(const char*); -MXS_MONITOR* monitor_repurpose_destroyed(const char* name, const char* module); - -void monitor_show(DCB*, MXS_MONITOR*); -void monitor_show_all(DCB*); - -void monitor_list(DCB*); - -bool monitor_add_server(MXS_MONITOR* mon, SERVER* server); -void monitor_remove_server(MXS_MONITOR* mon, SERVER* server); -void monitor_add_user(MXS_MONITOR*, const char*, const char*); -void monitor_add_parameters(MXS_MONITOR* monitor, MXS_CONFIG_PARAMETER* params); -bool monitor_remove_parameter(MXS_MONITOR* monitor, const char* key); -void monitor_set_parameter(MXS_MONITOR* monitor, const char* key, const char* value); - -void monitor_set_interval(MXS_MONITOR*, unsigned long); -bool monitor_set_network_timeout(MXS_MONITOR*, int, int, const char*); -void monitor_set_journal_max_age(MXS_MONITOR* mon, time_t value); -void monitor_set_script_timeout(MXS_MONITOR* mon, uint32_t value); - -/** - * @brief Serialize a monitor to a file - * - * This converts the static configuration of the monitor into an INI format file. - * - * @param monitor Monitor to serialize - * @return True if serialization was successful - */ -bool monitor_serialize(const MXS_MONITOR* monitor); - -/** - * Check if a server is being monitored and return the monitor. - * @param server Server that is queried - * @return The monitor watching this server, or NULL if not monitored - */ -MXS_MONITOR* monitor_server_in_use(const SERVER* server); - -/** - * Launch a script - * - * @param mon Owning monitor - * @param ptr The server which has changed state - * @param script Script to execute - * @param timeout Timeout in seconds for the script - * - * @return Return value of the executed script or -1 on error - */ -int monitor_launch_script(MXS_MONITOR* mon, MXS_MONITORED_SERVER* ptr, const char* script, uint32_t timeout); - -/** - * Launch a command - * - * @param mon Owning monitor - * @param ptr The server which has changed state - * @param cmd The command to execute. - * - * @note All default script variables will be replaced. - * - * @return Return value of the executed script or -1 on error. - */ -int monitor_launch_command(MXS_MONITOR* mon, MXS_MONITORED_SERVER* ptr, EXTERNCMD* cmd); - -MXS_END_DECLS diff --git a/server/core/internal/monitor.hh b/server/core/internal/monitor.hh index a97f5546f..085655c74 100644 --- a/server/core/internal/monitor.hh +++ b/server/core/internal/monitor.hh @@ -13,11 +13,161 @@ #pragma once /** - * Internal header for the monitor type + * Internal header for the monitor */ -#include "monitor.h" - +#include #include +#include "externcmd.h" + +#define MON_ARG_MAX 8192 + +#define DEFAULT_CONNECT_TIMEOUT 3 +#define DEFAULT_READ_TIMEOUT 3 +#define DEFAULT_WRITE_TIMEOUT 3 +#define DEFAULT_CONNECTION_ATTEMPTS 1 + +#define DEFAULT_MONITOR_INTERVAL 2000 // in milliseconds + +/** Default maximum journal age in seconds */ +#define DEFAULT_JOURNAL_MAX_AGE 28800 + +/** Default script execution timeout in seconds */ +#define DEFAULT_SCRIPT_TIMEOUT 90 + +/** + * Monitor network timeout types + */ +typedef enum +{ + MONITOR_CONNECT_TIMEOUT = 0, + MONITOR_READ_TIMEOUT = 1, + MONITOR_WRITE_TIMEOUT = 2, + MONITOR_CONNECT_ATTEMPTS = 3 +} monitor_timeouts_t; + +/* Is not really an event as the other values, but is a valid config setting and also the default. + * Bitmask value matches all events. */ +static const MXS_ENUM_VALUE mxs_monitor_event_default_enum = {"all", ~0ULL}; +static const MXS_ENUM_VALUE mxs_monitor_event_enum_values[] = +{ + mxs_monitor_event_default_enum, + {"master_down", MASTER_DOWN_EVENT }, + {"master_up", MASTER_UP_EVENT }, + {"slave_down", SLAVE_DOWN_EVENT }, + {"slave_up", SLAVE_UP_EVENT }, + {"server_down", SERVER_DOWN_EVENT }, + {"server_up", SERVER_UP_EVENT }, + {"synced_down", SYNCED_DOWN_EVENT }, + {"synced_up", SYNCED_UP_EVENT }, + {"donor_down", DONOR_DOWN_EVENT }, + {"donor_up", DONOR_UP_EVENT }, + {"ndb_down", NDB_DOWN_EVENT }, + {"ndb_up", NDB_UP_EVENT }, + {"lost_master", LOST_MASTER_EVENT }, + {"lost_slave", LOST_SLAVE_EVENT }, + {"lost_synced", LOST_SYNCED_EVENT }, + {"lost_donor", LOST_DONOR_EVENT }, + {"lost_ndb", LOST_NDB_EVENT }, + {"new_master", NEW_MASTER_EVENT }, + {"new_slave", NEW_SLAVE_EVENT }, + {"new_synced", NEW_SYNCED_EVENT }, + {"new_donor", NEW_DONOR_EVENT }, + {"new_ndb", NEW_NDB_EVENT }, + {NULL} +}; std::unique_ptr monitor_get_list(); + +MXS_BEGIN_DECLS + +MXS_MONITOR* monitor_create(const char*, const char*, MXS_CONFIG_PARAMETER* params); +void monitor_destroy(MXS_MONITOR*); + +void monitor_start(MXS_MONITOR*, const MXS_CONFIG_PARAMETER*); +void monitor_stop(MXS_MONITOR*); + +/** + * @brief Mark monitor as deactivated + * + * A deactivated monitor appears not to exist, as if it had been + * destroyed. + * + * @param monitor + */ +void monitor_deactivate(MXS_MONITOR* monitor); + +void monitor_stop_all(); +void monitor_start_all(); + +/** + * @brief Destroys all monitors. At this point all monitors should + * have been stopped. + * + * @attn Must only be called in single-thread context at system shutdown. + */ +void monitor_destroy_all(); + +MXS_MONITOR* monitor_find(const char*); +MXS_MONITOR* monitor_repurpose_destroyed(const char* name, const char* module); + +void monitor_show(DCB*, MXS_MONITOR*); +void monitor_show_all(DCB*); + +void monitor_list(DCB*); + +bool monitor_add_server(MXS_MONITOR* mon, SERVER* server); +void monitor_remove_server(MXS_MONITOR* mon, SERVER* server); +void monitor_add_user(MXS_MONITOR*, const char*, const char*); +void monitor_add_parameters(MXS_MONITOR* monitor, MXS_CONFIG_PARAMETER* params); +bool monitor_remove_parameter(MXS_MONITOR* monitor, const char* key); +void monitor_set_parameter(MXS_MONITOR* monitor, const char* key, const char* value); + +void monitor_set_interval(MXS_MONITOR*, unsigned long); +bool monitor_set_network_timeout(MXS_MONITOR*, int, int, const char*); +void monitor_set_journal_max_age(MXS_MONITOR* mon, time_t value); +void monitor_set_script_timeout(MXS_MONITOR* mon, uint32_t value); + +/** + * @brief Serialize a monitor to a file + * + * This converts the static configuration of the monitor into an INI format file. + * + * @param monitor Monitor to serialize + * @return True if serialization was successful + */ +bool monitor_serialize(const MXS_MONITOR* monitor); + +/** + * Check if a server is being monitored and return the monitor. + * @param server Server that is queried + * @return The monitor watching this server, or NULL if not monitored + */ +MXS_MONITOR* monitor_server_in_use(const SERVER* server); + +/** + * Launch a script + * + * @param mon Owning monitor + * @param ptr The server which has changed state + * @param script Script to execute + * @param timeout Timeout in seconds for the script + * + * @return Return value of the executed script or -1 on error + */ +int monitor_launch_script(MXS_MONITOR* mon, MXS_MONITORED_SERVER* ptr, const char* script, uint32_t timeout); + +/** + * Launch a command + * + * @param mon Owning monitor + * @param ptr The server which has changed state + * @param cmd The command to execute. + * + * @note All default script variables will be replaced. + * + * @return Return value of the executed script or -1 on error. + */ +int monitor_launch_command(MXS_MONITOR* mon, MXS_MONITORED_SERVER* ptr, EXTERNCMD* cmd); + +MXS_END_DECLS diff --git a/server/core/internal/resource.hh b/server/core/internal/resource.hh index ed9b4a39b..ab5253b32 100644 --- a/server/core/internal/resource.hh +++ b/server/core/internal/resource.hh @@ -24,7 +24,7 @@ #include "httprequest.hh" #include "httpresponse.hh" -#include "monitor.h" +#include "monitor.hh" #include "service.hh" #include "filter.hh" #include "session.h" diff --git a/server/core/modulecmd.cc b/server/core/modulecmd.cc index af0fb5bed..0aeef1331 100644 --- a/server/core/modulecmd.cc +++ b/server/core/modulecmd.cc @@ -21,7 +21,7 @@ #include "internal/filter.hh" #include "internal/modules.h" -#include "internal/monitor.h" +#include "internal/monitor.hh" /** Size of the error buffer */ #define MODULECMD_ERRBUF_SIZE 512 diff --git a/server/core/resource.cc b/server/core/resource.cc index 8e359a56c..6b373f149 100644 --- a/server/core/resource.cc +++ b/server/core/resource.cc @@ -31,7 +31,7 @@ #include "internal/httprequest.hh" #include "internal/httpresponse.hh" #include "internal/modules.h" -#include "internal/monitor.h" +#include "internal/monitor.hh" #include "internal/query_classifier.hh" #include "internal/service.hh" #include "internal/session.h" diff --git a/server/core/server.cc b/server/core/server.cc index 6ac9fffe6..98f4a7d38 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -51,7 +51,7 @@ #include #include -#include "internal/monitor.h" +#include "internal/monitor.hh" #include "internal/poll.hh" #include "internal/config.hh" #include "internal/service.hh" diff --git a/server/core/test/test_modulecmd.cc b/server/core/test/test_modulecmd.cc index 537da994d..459c61186 100644 --- a/server/core/test/test_modulecmd.cc +++ b/server/core/test/test_modulecmd.cc @@ -23,7 +23,7 @@ #include #include -#include "../internal/monitor.h" +#include "../internal/monitor.hh" #define TEST(a, b) do {if (!(a)) {printf("%s:%d " b "\n", __FILE__, __LINE__); return 1;}} while (false) diff --git a/server/modules/monitor/mariadbmon/mariadbmon.cc b/server/modules/monitor/mariadbmon/mariadbmon.cc index ea262c8f1..363a5a21e 100644 --- a/server/modules/monitor/mariadbmon/mariadbmon.cc +++ b/server/modules/monitor/mariadbmon/mariadbmon.cc @@ -28,7 +28,7 @@ #include #include // TODO: For monitor_add_parameters -#include "../../../core/internal/monitor.h" +#include "../../../core/internal/monitor.hh" using std::string; using maxbase::string_printf; diff --git a/server/modules/routing/debugcli/debugcmd.cc b/server/modules/routing/debugcli/debugcmd.cc index 6249fb976..479da8d3a 100644 --- a/server/modules/routing/debugcli/debugcmd.cc +++ b/server/modules/routing/debugcli/debugcmd.cc @@ -60,7 +60,7 @@ #include "../../../core/internal/config_runtime.h" #include "../../../core/internal/maxscale.h" #include "../../../core/internal/modules.h" -#include "../../../core/internal/monitor.h" +#include "../../../core/internal/monitor.hh" #include "../../../core/internal/poll.hh" #include "../../../core/internal/session.h" #include "../../../core/internal/filter.hh" diff --git a/server/modules/routing/maxinfo/maxinfo.cc b/server/modules/routing/maxinfo/maxinfo.cc index 7d9a58075..bf76583c0 100644 --- a/server/modules/routing/maxinfo/maxinfo.cc +++ b/server/modules/routing/maxinfo/maxinfo.cc @@ -52,7 +52,7 @@ #include #include "../../../core/internal/modules.h" -#include "../../../core/internal/monitor.h" +#include "../../../core/internal/monitor.hh" #include "../../../core/internal/session.h" #include "../../../core/internal/session.hh" #include "../../../core/internal/poll.hh" diff --git a/server/modules/routing/maxinfo/maxinfo_exec.cc b/server/modules/routing/maxinfo/maxinfo_exec.cc index 27f0b6dc2..f908ddbaf 100644 --- a/server/modules/routing/maxinfo/maxinfo_exec.cc +++ b/server/modules/routing/maxinfo/maxinfo_exec.cc @@ -47,7 +47,6 @@ #include "../../../core/internal/maxscale.h" #include "../../../core/internal/modules.hh" -#include "../../../core/internal/monitor.h" #include "../../../core/internal/monitor.hh" #include "../../../core/internal/poll.hh" #include "../../../core/internal/session.hh"