From 3ab684ae83168d0a40537cb9ac526e215aa4ab48 Mon Sep 17 00:00:00 2001 From: "alexey.lazarenko" Date: Wed, 26 Apr 2023 17:16:23 +0300 Subject: [PATCH 1/2] JE-66101 [MySQL Autofailover] Promote new primary on only available Proxy nodes --- .../scripts/promote-master-with-proxy.js | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/addons/promote-new-primary/scripts/promote-master-with-proxy.js b/addons/promote-new-primary/scripts/promote-master-with-proxy.js index 6a876d6f..39f5d349 100644 --- a/addons/promote-new-primary/scripts/promote-master-with-proxy.js +++ b/addons/promote-new-primary/scripts/promote-master-with-proxy.js @@ -11,11 +11,11 @@ function promoteNewPrimary() { let TMP_FILE = "/var/lib/jelastic/promotePrimary"; let session = getParam("session", ""); let CLUSTER_FAILED = 98; + let NOT_RUNNING = 4110; let WARNING = "warning"; this.run = function() { let resp = this.auth(); - this.log("auth resp ->" + resp); if (resp.result != 0) return resp; resp = this.newPrimaryOnProxy(); @@ -314,11 +314,40 @@ function promoteNewPrimary() { return { result: 0 } }; - this.cmdByGroup = function(command, nodeGroup, timeout) { + this.checkNodesAvailability = function(nodeGroup) { + let nodeid; + + let resp = this.cmdByGroup("echo 1", nodeGroup, null, true); + if (resp.result == NOT_RUNNING) { + let nodeResp; + for (let i = 0, n = resp.responses.length; i < n; i++) { + nodeResp = resp.responses[i]; + if (nodeResp.result == 0) { + nodeid = nodeResp.nodeid; + break; + } + } + } + if (resp.result != 0 && resp.result != NOT_RUNNING) return resp; + + return { + result: 0, + nodeid: nodeid + } + }; + + this.cmdByGroup = function(command, nodeGroup, timeout, test) { if (timeout) { command = "timeout " + timeout + "s bash -c \"" + command + "\""; } + if (nodeGroup == PROXY && !test) { + let resp = this.checkNodesAvailability(PROXY); + if (resp.nodeid) { + return this.cmdById(resp.nodeid, command); + } + } + return api.env.control.ExecCmdByGroup(envName, session, nodeGroup, toJSON([{ command: command }]), true, false, ROOT); }; From 24c59f50cc1e8a0f11bbb2b2a9b2015ba624b772 Mon Sep 17 00:00:00 2001 From: "alexey.lazarenko" Date: Thu, 27 Apr 2023 10:13:14 +0300 Subject: [PATCH 2/2] JE-66101 [MySQL Autofailover] Promote new primary on only available Proxy nodes --- .../scripts/promote-master-with-proxy.js | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/addons/promote-new-primary/scripts/promote-master-with-proxy.js b/addons/promote-new-primary/scripts/promote-master-with-proxy.js index 39f5d349..e2d9876a 100644 --- a/addons/promote-new-primary/scripts/promote-master-with-proxy.js +++ b/addons/promote-new-primary/scripts/promote-master-with-proxy.js @@ -11,7 +11,6 @@ function promoteNewPrimary() { let TMP_FILE = "/var/lib/jelastic/promotePrimary"; let session = getParam("session", ""); let CLUSTER_FAILED = 98; - let NOT_RUNNING = 4110; let WARNING = "warning"; this.run = function() { @@ -314,25 +313,41 @@ function promoteNewPrimary() { return { result: 0 } }; + this.getAvailableProxy = function() { + return this.availableProxy || ""; + }; + + this.setAvailableProxy = function(nodeid) { + this.availableProxy = nodeid; + }; + this.checkNodesAvailability = function(nodeGroup) { let nodeid; + if (this.getAvailableProxy()) { + return { + result: 0, + nodeid: this.getAvailableProxy() + } + } + let resp = this.cmdByGroup("echo 1", nodeGroup, null, true); - if (resp.result == NOT_RUNNING) { + this.log("checkNodesAvailability resp1 ->" + resp); + if (resp.result != 0) { let nodeResp; for (let i = 0, n = resp.responses.length; i < n; i++) { nodeResp = resp.responses[i]; if (nodeResp.result == 0) { nodeid = nodeResp.nodeid; + this.setAvailableProxy(nodeResp.nodeid); break; } } } - if (resp.result != 0 && resp.result != NOT_RUNNING) return resp; return { result: 0, - nodeid: nodeid + nodeid: this.getAvailableProxy() } };