From b7294a28afab44c2294bf70baa296bdb81b847c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 18 Jun 2019 07:23:16 +0300 Subject: [PATCH 1/5] MXS-2547: Assert that workers aren't stopped If a worker is stopped, none of the Worker::execute or post_message methods should be called. --- server/core/worker.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/core/worker.cc b/server/core/worker.cc index 728cbca72..6d6990caa 100644 --- a/server/core/worker.cc +++ b/server/core/worker.cc @@ -718,6 +718,8 @@ size_t Worker::execute_concurrently(Task& task) bool Worker::post_message(uint32_t msg_id, intptr_t arg1, intptr_t arg2) { + ss_dassert(state() != Worker::STOPPED); + // NOTE: No logging here, this function must be signal safe. MessageQueue::Message message(msg_id, arg1, arg2); From 69b3879357c35cd21e4952cf109fee0e1ae8664a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 18 Jun 2019 11:00:58 +0300 Subject: [PATCH 2/5] MXS-2547: Don't post messages to stopped workers If a worker has been stopped, tasks must not be executed on it. To prevent this, the calling code should check whether the worker has been stopped. This does not prevent the case where a message is successfully posted to a worker but the worker is stopped before it processes it. --- server/core/worker.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/core/worker.cc b/server/core/worker.cc index 6d6990caa..b92ef49c4 100644 --- a/server/core/worker.cc +++ b/server/core/worker.cc @@ -718,12 +718,17 @@ size_t Worker::execute_concurrently(Task& task) bool Worker::post_message(uint32_t msg_id, intptr_t arg1, intptr_t arg2) { + // NOTE: No logging here, this function must be signal safe. + bool rval = false; ss_dassert(state() != Worker::STOPPED); - // NOTE: No logging here, this function must be signal safe. - MessageQueue::Message message(msg_id, arg1, arg2); + if (state() != Worker::STOPPED) + { + MessageQueue::Message message(msg_id, arg1, arg2); + rval = m_pQueue->post(message); + } - return m_pQueue->post(message); + return rval; } bool mxs_worker_post_message(MXS_WORKER* pWorker, uint32_t msg_id, intptr_t arg1, intptr_t arg2) From 27fb397041c340eb757bd52086271e17bc99f83f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 18 Jun 2019 11:23:14 +0300 Subject: [PATCH 3/5] MXS-2547: Do shutdown on main worker By stopping the REST API before the workers and moving the shutdown to the same worker that handles REST API requests, we prevent the hang on shutdown. This also makes the signal handler signal-safe. --- server/core/admin.cc | 1 + server/core/gateway.cc | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/server/core/admin.cc b/server/core/admin.cc index 266226b5c..58396473a 100644 --- a/server/core/admin.cc +++ b/server/core/admin.cc @@ -410,6 +410,7 @@ bool mxs_admin_init() void mxs_admin_shutdown() { MHD_stop_daemon(http_daemon); + MXS_NOTICE("Stopped MaxScale REST API"); } bool mxs_admin_https_enabled() diff --git a/server/core/gateway.cc b/server/core/gateway.cc index 91da2c46d..aaf22e581 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -2293,9 +2293,6 @@ int main(int argc, char **argv) /*< Stop all the monitors */ monitorStopAll(); - /** Stop administrative interface */ - mxs_admin_shutdown(); - /*< Stop all the monitors */ monitorStopAll(); @@ -2380,6 +2377,19 @@ return_main: return rc; } /*< End of main */ +class ShutdownTask: public Worker::DisposableTask +{ +public: + void execute(mxs::Worker& w) + { + mxs_admin_shutdown(); + service_shutdown(); + Worker::shutdown_all(); + hkshutdown(); + log_flush_shutdown(); + } +}; + /*< * Shutdown MaxScale server */ @@ -2391,10 +2401,8 @@ int maxscale_shutdown() if (n == 0) { - service_shutdown(); - Worker::shutdown_all(); - hkshutdown(); - log_flush_shutdown(); + mxs::Worker* worker = Worker::get(0); + worker->post(std::auto_ptr(new ShutdownTask), mxs::Worker::EXECUTE_QUEUED); } return n + 1; From 96d5c575f8debdece8cf977ffc52c37c151a725a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 18 Jun 2019 12:52:34 +0300 Subject: [PATCH 4/5] Document required `create service` parameters When a service is created via MaxCtrl, the `user` and `password` parameters must be defined. This was not documented in the command help output. --- maxctrl/lib/create.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maxctrl/lib/create.js b/maxctrl/lib/create.js index 954c4cd92..c0078332d 100644 --- a/maxctrl/lib/create.js +++ b/maxctrl/lib/create.js @@ -200,7 +200,8 @@ exports.builder = function(yargs) { .command('service ', 'Create a new service', function(yargs) { return yargs.epilog('The last argument to this command is a list of key=value parameters ' + 'given as the service parameters. If the --servers or --filters options ' + - 'are used, they must be defined after the service parameters.') + 'are used, they must be defined after the service parameters.' + + '\n\nNote that the `user` and `password` parameters must be defined.') .usage('Usage: service ') }, function(argv) { maxctrl(argv, function(host) { From 35b5f2099b796a0ba7cda4dcf65d034f9af74fe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 18 Jun 2019 13:08:30 +0300 Subject: [PATCH 5/5] Regenerate MaxCtrl documentation --- Documentation/Reference/MaxCtrl.md | 65 +++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/Documentation/Reference/MaxCtrl.md b/Documentation/Reference/MaxCtrl.md index 1e0d71b8f..36dd41e6d 100644 --- a/Documentation/Reference/MaxCtrl.md +++ b/Documentation/Reference/MaxCtrl.md @@ -53,17 +53,17 @@ All command accept the following global options. --tsv Print tab separated output [boolean] [default: false] HTTPS/TLS Options: - -s, --secure Enable HTTPS requests [boolean] [default: false] - --tls-key Path to TLS private key [string] - --tls-cert Path to TLS public certificate [string] - --tls-ca-cert Path to TLS CA certificate [string] - --tls-verify-server-cert Whether to verify server TLS certificates + -s, --secure Enable HTTPS requests [boolean] [default: false] + --tls-key Path to TLS private key [string] + --tls-passphrase Password for the TLS private key [string] + --tls-cert Path to TLS public certificate [string] + --tls-ca-cert Path to TLS CA certificate [string] + -n, --tls-verify-server-cert Whether to verify server TLS certificates [boolean] [default: true] Options: - --version Show version number [boolean] - --tls-passphrase Password for the TLS private key [string] - --help Show help [boolean] + --version Show version number [boolean] + --help Show help [boolean] If no commands are given, maxctrl is started in interactive mode. Use `exit` to exit the interactive mode. @@ -83,7 +83,7 @@ Commands: filters List filters modules List loaded modules threads List threads - users List created network users + users List created users commands List module commands ``` @@ -140,7 +140,8 @@ List all worker threads. `Usage: list users` -List the users that can be used to connect to the MaxScale REST API. +List network the users that can be used to connect to the MaxScale REST API as +well as enabled local accounts. ### list commands @@ -298,6 +299,10 @@ Usage: set Commands: server Set server state +Set options: + --force Forcefully close all connections to the target server + [boolean] [default: false] + ``` ### set server @@ -471,6 +476,8 @@ The last argument to this command is a list of key=value parameters given as the service parameters. If the --servers or --filters options are used, they must be defined after the service parameters. +Note that the `user` and `password` parameters must be defined. + ### create filter `Usage: filter [params...]` @@ -610,7 +617,7 @@ Usage: start Commands: service Start a service monitor Start a monitor - maxscale Start MaxScale by starting all services + services Start all services [aliases: maxscale] ``` @@ -626,9 +633,9 @@ This starts a service stopped by `stop service ` This starts a monitor stopped by `stop monitor ` -### start maxscale +### start services -`Usage: start maxscale` +`Usage: start [services|maxscale]` This command will execute the `start service` command for all services in MaxScale. @@ -641,7 +648,7 @@ Usage: stop Commands: service Stop a service monitor Stop a monitor - maxscale Stop MaxScale by stopping all services + services Stop all services [aliases: maxscale] ``` @@ -660,9 +667,9 @@ until they are closed. Stopping a monitor will pause the monitoring of the servers. This can be used to manually control server states with the `set server` command. -### stop maxscale +### stop services -`Usage: stop maxscale` +`Usage: stop [services|maxscale]` This command will execute the `stop service` command for all services in MaxScale. @@ -679,6 +686,7 @@ Commands: service-filters [filters...] Alter filters of a service logging Alter logging parameters maxscale Alter MaxScale parameters + user Alter admin user passwords ``` @@ -698,8 +706,11 @@ To display the monitor parameters, execute `show monitor ` `Usage: alter service ` -To display the service parameters, execute `show service `. The -following list of parameters can be altered at runtime: +To display the service parameters, execute `show service `. Some +routers support runtime configuration changes to all parameters. Currently all +readconnroute, readwritesplit and schemarouter parameters can be changed at +runtime. In addition to module specific parameters, the following list of common +service parameters can be altered at runtime: [ "user", @@ -712,7 +723,8 @@ following list of parameters can be altered at runtime: "strip_db_esc", "localhost_match_wildcard_host", "max_slave_connections", - "max_slave_replication_lag" + "max_slave_replication_lag", + "retain_last_statements" ] ### alter service-filters @@ -747,9 +759,22 @@ of parameters can be altered at runtime: "auth_write_timeout", "admin_auth", "admin_log_auth_failures", - "passive" + "passive", + "ms_timestamp", + "skip_permission_checks", + "query_retries", + "query_retry_timeout", + "retain_last_statements", + "dump_last_statements" ] +### alter user + +`Usage: alter user ` + +Changes the password for a user. To change the user type, destroy the user and +then create it again. + ## rotate ```