From 0cb15976e8aafab3d65d327d7421bec34bd15b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 2 Apr 2019 09:32:44 +0300 Subject: [PATCH] Backport: Add force option to set endpoint The new `force=yes` option closes all connections to the server that is being put into maintenance mode. This will immediately close all open connections to the server without allowing results to return. --- include/maxscale/config.h | 2 ++ maxctrl/lib/set.js | 9 +++++++++ server/core/config.cc | 2 ++ server/core/resource.cc | 5 +++++ 4 files changed, 18 insertions(+) diff --git a/include/maxscale/config.h b/include/maxscale/config.h index c609255c8..3fee697ab 100644 --- a/include/maxscale/config.h +++ b/include/maxscale/config.h @@ -124,6 +124,7 @@ extern const char CN_FIELDS[]; extern const char CN_FILTERS[]; extern const char CN_FILTER[]; extern const char CN_FILTER_DIAGNOSTICS[]; +extern const char CN_FORCE[]; extern const char CN_FUNCTIONS[]; extern const char CN_GATEWAY[]; extern const char CN_HAS_WHERE_CLAUSE[]; @@ -202,6 +203,7 @@ extern const char CN_VERSION_STRING[]; extern const char CN_WEIGHTBY[]; extern const char CN_WRITEQ_HIGH_WATER[]; extern const char CN_WRITEQ_LOW_WATER[]; +extern const char CN_YES[]; /* * Global configuration items that are read (or pre_parsed) to be available for diff --git a/maxctrl/lib/set.js b/maxctrl/lib/set.js index af230b93f..72fc75836 100644 --- a/maxctrl/lib/set.js +++ b/maxctrl/lib/set.js @@ -17,6 +17,12 @@ exports.desc = 'Set object state' exports.handler = function() {} exports.builder = function(yargs) { yargs + .group(['force'], 'Set options:') + .option('force', { + describe: 'Forcefully close all connections to the target server', + type: 'boolean', + default: false + }) .command('server ', 'Set server state', function(yargs) { return yargs.epilog('If is monitored by a monitor, this command should ' + 'only be used to set the server into the `maintenance` state. ' + @@ -27,6 +33,9 @@ exports.builder = function(yargs) { .usage('Usage: set server ') }, function(argv) { var target = 'servers/' + argv.server + '/set?state=' + argv.state + if (argv.force) { + target += '&force=yes' + } maxctrl(argv, function(host) { return doRequest(host, target, null, {method: 'PUT'}) }) diff --git a/server/core/config.cc b/server/core/config.cc index bbf906559..0fc27870f 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -105,6 +105,7 @@ const char CN_FIELDS[] = "fields"; const char CN_FILTERS[] = "filters"; const char CN_FILTER[] = "filter"; const char CN_FILTER_DIAGNOSTICS[] = "filter_diagnostics"; +const char CN_FORCE[] = "force"; const char CN_FUNCTIONS[] = "functions"; const char CN_GATEWAY[] = "gateway"; const char CN_HAS_WHERE_CLAUSE[] = "has_where_clause"; @@ -186,6 +187,7 @@ const char CN_VERSION_STRING[] = "version_string"; const char CN_WEIGHTBY[] = "weightby"; const char CN_WRITEQ_HIGH_WATER[] = "writeq_high_water"; const char CN_WRITEQ_LOW_WATER[] = "writeq_low_water"; +const char CN_YES[] = "yes"; extern const char CN_LOGDIR[] = "logdir"; diff --git a/server/core/resource.cc b/server/core/resource.cc index 8e359a56c..c62215f17 100644 --- a/server/core/resource.cc +++ b/server/core/resource.cc @@ -774,6 +774,11 @@ HttpResponse cb_set_server(const HttpRequest& request) string errmsg; if (mxs::server_set_status(server, opt, &errmsg)) { + if (status_is_in_maint(opt) && request.get_option(CN_FORCE) == CN_YES) + { + dcb_hangup_foreach(server); + } + return HttpResponse(MHD_HTTP_NO_CONTENT); } else