From 3dd5cfa8c14d2853c428dbb4ff7db51b4155c9f1 Mon Sep 17 00:00:00 2001 From: "alexey.lazarenko" Date: Mon, 23 Oct 2023 15:57:35 +0300 Subject: [PATCH 01/12] JE-66250 --- .../scripts/promote-master.js | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/addons/promote-new-primary/scripts/promote-master.js b/addons/promote-new-primary/scripts/promote-master.js index 4ba74da7..e24f0ac2 100644 --- a/addons/promote-new-primary/scripts/promote-master.js +++ b/addons/promote-new-primary/scripts/promote-master.js @@ -12,6 +12,7 @@ function promoteNewPrimary() { let TMP_FILE = "/var/lib/jelastic/promotePrimary"; let session = getParam("session", ""); let force = getParam("force", false); + let UNKNOWN_ERROR = 99; let CLUSTER_FAILED = 98; let MySQL_FAILED = 97; let GET_ENVS_FAILED = 96; @@ -220,17 +221,27 @@ function promoteNewPrimary() { }; this.getContainerEnvs = function() { - let resp = this.getEnvInfo(); + let secondaryNodeId = ""; let nodeId, envVars; + let resp = this.getEnvInfo(); if (resp.result != 0) return resp; for (let i = 0, n = resp.nodes.length; i < n; i++) { if (resp.nodes[i].nodeGroup == SQLDB) { - envVars = api.environment.control.GetContainerEnvVars(envName, session, resp.nodes[i].id); - if (envVars.result == 0) return envVars; + if (resp.nodes[i].ismaster) { + nodeId = resp.nodes[i].id; + } else { + secondaryNodeId = secondaryNodeId || resp.nodes[i].id; + } } } - return {result: GET_ENVS_FAILED, error: "Can not get environment variables"}; + + resp = api.environment.control.GetContainerEnvVars(envName, session, nodeId); + if (resp.result == UNKNOWN_ERROR && resp.error.indexOf("No route to host") != -1) { + return api.environment.control.GetContainerEnvVars(envName, session, secondaryNodeId); + } + + return (resp.result == 0) ? resp || {result: GET_ENVS_FAILED, error: "Can not get environment variables"}; }; this.checkAvailability = function() { @@ -554,20 +565,24 @@ function promoteNewPrimary() { if (resp.result != 0) return resp; let nodes = this.getParsedNodes(); + resp = this.getNodesByGroup(SQLDB); - if (nodes) { - for (let i = 0, n = nodes.length; i < n; i++) { - if (nodes[i]) { - if (nodes[i].type == SECONDARY && !alreadySetNewPrimary) { - this.setNewPrimaryNode(nodes[i]); + if (resp && resp.nodes) { + let node; + for (let i = 0, n = resp.nodes.length; i < n; i++) { + node = resp.nodes[i]; + if (node) { + //if (nodes[i].type == "secondary" && !alreadySetNewPrimary) { + if (node.address != containerEnvs["PRIMARY_IP"] && !alreadySetNewPrimary){ + this.setNewPrimaryNode(node); alreadySetNewPrimary = true; } - - if (nodes[i].type == "primary") { - resp = api.env.control.SetNodeDisplayName(envName, session, nodes[i].id, PRIMARY + " - " + FAILED); + // if (nodes[i].type == "primary") { + if (node.address == containerEnvs["PRIMARY_IP"]){ + resp = api.env.control.SetNodeDisplayName(envName, session, node.id, PRIMARY + " - " + FAILED); if (resp.result != 0) return resp; - resp = this.getSQLNodeById(nodes[i].id); + resp = this.getSQLNodeById(node.id); if (resp.result != 0) return resp; if (resp.node) { From 2e00a2ad080ec275dc2c2c22a783b30fa9442978 Mon Sep 17 00:00:00 2001 From: "alexey.lazarenko" Date: Mon, 23 Oct 2023 16:00:51 +0300 Subject: [PATCH 02/12] JE-66250 --- addons/promote-new-primary/scripts/promote-master.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/promote-new-primary/scripts/promote-master.js b/addons/promote-new-primary/scripts/promote-master.js index e24f0ac2..eb66bf83 100644 --- a/addons/promote-new-primary/scripts/promote-master.js +++ b/addons/promote-new-primary/scripts/promote-master.js @@ -241,7 +241,7 @@ function promoteNewPrimary() { return api.environment.control.GetContainerEnvVars(envName, session, secondaryNodeId); } - return (resp.result == 0) ? resp || {result: GET_ENVS_FAILED, error: "Can not get environment variables"}; + return (resp.result == 0) ? resp : {result: GET_ENVS_FAILED, error: "Can not get environment variables"}; }; this.checkAvailability = function() { From b12c6b90e5874487f4fd04aa66fb69a33d99de1e Mon Sep 17 00:00:00 2001 From: "alexey.lazarenko" Date: Mon, 23 Oct 2023 16:58:26 +0300 Subject: [PATCH 03/12] JE-66250 --- addons/promote-new-primary/scripts/promote-master.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/promote-new-primary/scripts/promote-master.js b/addons/promote-new-primary/scripts/promote-master.js index eb66bf83..6e193e0c 100644 --- a/addons/promote-new-primary/scripts/promote-master.js +++ b/addons/promote-new-primary/scripts/promote-master.js @@ -40,15 +40,16 @@ function promoteNewPrimary() { if (resp.isRunning) return {result: 0} //NO PROXY - resp = this.DefinePrimaryNode(); - if (resp.result != 0) return resp; - resp = this.checkAvailability(); if (resp.result != MySQL_FAILED) { return resp; } } + resp = this.DefinePrimaryNode(); + this.log("DefinePrimaryNode resp->" + resp); + if (resp.result != 0) return resp; + resp = this.newPrimaryOnProxy(); if (resp.result != 0) return resp; From c9d7d8265e3d36e97f4c02bfa0d84af5cede820c Mon Sep 17 00:00:00 2001 From: "alexey.lazarenko" Date: Tue, 24 Oct 2023 16:17:23 +0300 Subject: [PATCH 04/12] JE-66250 --- .../scripts/promote-master.js | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/addons/promote-new-primary/scripts/promote-master.js b/addons/promote-new-primary/scripts/promote-master.js index 6e193e0c..74242e57 100644 --- a/addons/promote-new-primary/scripts/promote-master.js +++ b/addons/promote-new-primary/scripts/promote-master.js @@ -29,10 +29,19 @@ function promoteNewPrimary() { let resp = this.defineAddonType(); if (resp.result != 0) return resp; + resp = this.DefinePrimaryNode(); + this.log("DefinePrimaryNode resp->" + resp); + if (resp.result != 0) return resp; + //PROXY if (this.getAddOnType()) { resp = this.auth(); if (resp.result != 0) return resp; + + resp = this.checkAvailability(); + if (resp.result != MySQL_FAILED || resp.result != 0) { + return resp; + } } else { //NO PROXY let resp = this.isProcessRunning(); @@ -41,15 +50,11 @@ function promoteNewPrimary() { //NO PROXY resp = this.checkAvailability(); - if (resp.result != MySQL_FAILED) { + if (resp.result != MySQL_FAILED || resp.result != 0) { return resp; } } - resp = this.DefinePrimaryNode(); - this.log("DefinePrimaryNode resp->" + resp); - if (resp.result != 0) return resp; - resp = this.newPrimaryOnProxy(); if (resp.result != 0) return resp; @@ -99,12 +104,22 @@ function promoteNewPrimary() { if (force || resp.result == 4109 || (resp.responses && resp.responses[0].result == 4109) || (resp.responses[0].out && resp.responses[0].out.indexOf("is alive") == -1)) { - resp = this.addIteration(); - if (resp.result != 0) return resp; + if (this.getAddOnType()) { + resp = this.addIteration(); + if (resp.result != 0) return resp; + } - return this.setIsRunningStatus(false); + if ((resp.iterator >= primary_idle_time / 10) || force) { + if (this.getAddOnType()) { + resp = this.setIsRunningStatus(true); + if (resp.result != 0) return resp; + return { + result: MySQL_FAILED + } + } + } } - if (resp.responses[0].error && resp.responses[0].error.indexOf("No route to host")) { + if (resp.responses[0].error && resp.responses[0].error.indexOf("No route to host") != -1) { return { result: MySQL_FAILED } @@ -223,7 +238,7 @@ function promoteNewPrimary() { this.getContainerEnvs = function() { let secondaryNodeId = ""; - let nodeId, envVars; + let nodeId; let resp = this.getEnvInfo(); if (resp.result != 0) return resp; @@ -245,27 +260,6 @@ function promoteNewPrimary() { return (resp.result == 0) ? resp : {result: GET_ENVS_FAILED, error: "Can not get environment variables"}; }; - this.checkAvailability = function() { - let command = "mysqladmin -u" + containerEnvs["REPLICA_USER"] + " -p" + containerEnvs["REPLICA_PSWD"] + " ping"; - let resp = this.cmdById(this.getPrimaryNode().id, command); - - if (force == "false") force = false; - if (force || resp.result == 4109 || (resp.responses && resp.responses[0].result == 4109) || (resp.responses[0].out && resp.responses[0].out.indexOf("is alive") == -1)) { - resp = this.addIteration(); - if (resp.result != 0) return resp; - - if ((resp.iterator >= primary_idle_time / 10) || force) { - resp = this.setIsRunningStatus(true); - if (resp.result != 0) return resp; - return { - result: MySQL_FAILED - } - } - } - - return { result: 0 } - }; - this.getPromoteData = function() { let resp; if (!dbPromoteData) { @@ -561,9 +555,8 @@ function promoteNewPrimary() { this.newPrimaryOnProxy = function() { let alreadySetNewPrimary = false; - let resp = this.diagnosticNodes(); - - if (resp.result != 0) return resp; + // let resp = this.diagnosticNodes(); + // if (resp.result != 0) return resp; let nodes = this.getParsedNodes(); resp = this.getNodesByGroup(SQLDB); @@ -692,6 +685,13 @@ function promoteNewPrimary() { } } + if (nodeGroup == SQLDB && test) { + let resp = this.checkAvailability(); + if (resp.result == MySQL_FAILED) { + return this.cmdById(resp.nodeid, command); + } + } + return api.env.control.ExecCmdByGroup(envName, session, nodeGroup, toJSON([{ command: command }]), true, false, ROOT); }; From fbd007b3bd412358dbf72552ea06af92582147e3 Mon Sep 17 00:00:00 2001 From: "alexey.lazarenko" Date: Tue, 24 Oct 2023 16:33:13 +0300 Subject: [PATCH 05/12] JE-66250 --- addons/promote-new-primary/scripts/promote-master.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/addons/promote-new-primary/scripts/promote-master.js b/addons/promote-new-primary/scripts/promote-master.js index 74242e57..76cef605 100644 --- a/addons/promote-new-primary/scripts/promote-master.js +++ b/addons/promote-new-primary/scripts/promote-master.js @@ -37,11 +37,6 @@ function promoteNewPrimary() { if (this.getAddOnType()) { resp = this.auth(); if (resp.result != 0) return resp; - - resp = this.checkAvailability(); - if (resp.result != MySQL_FAILED || resp.result != 0) { - return resp; - } } else { //NO PROXY let resp = this.isProcessRunning(); @@ -555,6 +550,7 @@ function promoteNewPrimary() { this.newPrimaryOnProxy = function() { let alreadySetNewPrimary = false; + let resp; // let resp = this.diagnosticNodes(); // if (resp.result != 0) return resp; From 8dc5651c12ef447370b0a83d886797c793b6b475 Mon Sep 17 00:00:00 2001 From: "alexey.lazarenko" Date: Tue, 24 Oct 2023 16:52:25 +0300 Subject: [PATCH 06/12] JE-66250 --- .../scripts/promote-master.js | 57 +++++++++++++++++-- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/addons/promote-new-primary/scripts/promote-master.js b/addons/promote-new-primary/scripts/promote-master.js index 76cef605..8d3cbc9e 100644 --- a/addons/promote-new-primary/scripts/promote-master.js +++ b/addons/promote-new-primary/scripts/promote-master.js @@ -33,6 +33,10 @@ function promoteNewPrimary() { this.log("DefinePrimaryNode resp->" + resp); if (resp.result != 0) return resp; + resp = this.checkAvailability(); + if (resp.result != MySQL_FAILED || resp.result != 0) { + return resp; + } //PROXY if (this.getAddOnType()) { resp = this.auth(); @@ -44,10 +48,10 @@ function promoteNewPrimary() { if (resp.isRunning) return {result: 0} //NO PROXY - resp = this.checkAvailability(); - if (resp.result != MySQL_FAILED || resp.result != 0) { - return resp; - } + // resp = this.checkAvailability(); + // if (resp.result != MySQL_FAILED || resp.result != 0) { + // return resp; + // } } resp = this.newPrimaryOnProxy(); @@ -93,7 +97,7 @@ function promoteNewPrimary() { this.checkAvailability = function() { let command = "mysqladmin -u" + containerEnvs["REPLICA_USER"] + " -p" + containerEnvs["REPLICA_PSWD"] + " ping"; - let resp = this.cmdById(this.getPrimaryNode().id, command); + let resp = this.cmdById(this.getPrimaryNode().id, command, 10); if (force == "false") force = false; if (force || resp.result == 4109 || @@ -115,6 +119,7 @@ function promoteNewPrimary() { } } if (resp.responses[0].error && resp.responses[0].error.indexOf("No route to host") != -1) { + this.setFailedPrimary(this.getPrimaryNode()); return { result: MySQL_FAILED } @@ -357,6 +362,30 @@ function promoteNewPrimary() { }; this.setContainerVar = function() { + let resp; + let aliveSQLNodes; + + if (this.getFailedPrimary()) { + resp = this.getAvailableSQL(); + if (resp.result != 0) return resp; + + aliveSQLNodes = resp.nodes; + + for (let i = 0, n = aliveSQLNodes.length; i < n; i++) { + resp = api.environment.control.AddContainerEnvVars({ + envName: envName, + session: session, + nodeId: aliveSQLNodes[i].id, + vars: { + PRIMARY_IP: this.getNewPrimaryNode().address + } + }); + if (resp.result != 0) return resp; + } + + return { result: 0 } + } + return api.environment.control.AddContainerEnvVars({ envName: envName, session: session, @@ -367,6 +396,24 @@ function promoteNewPrimary() { }); }; + this.getAvailableSQL = function() { + let availableNodes = []; + + let nodes = this.getNodesByGroup(SQLDB); + if (nodes.result != 0) return nodes; + + for (let i = 0, n = nodes.length; i < n; i++) { + if (nodes[i].address != this.getFailedPrimary().address) { + availableNodes.push(nodes[i]); + } + } + + return { + result: 0, + nodes: availableNodes + } + }; + this.diagnosticNodes = function() { let clusterUp = false; let command = "curl -fsSL 'https://github.com/jelastic-jps/mysql-cluster/raw/master/addons/recovery/scripts/db-recovery.sh' -o /tmp/db_recovery.sh\n" + From 3007d895ba27e2183b252c3f50351016656006c7 Mon Sep 17 00:00:00 2001 From: "alexey.lazarenko" Date: Wed, 25 Oct 2023 11:06:02 +0300 Subject: [PATCH 07/12] JE-66250 --- .../scripts/promote-master.js | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/addons/promote-new-primary/scripts/promote-master.js b/addons/promote-new-primary/scripts/promote-master.js index 8d3cbc9e..5b5a6bf9 100644 --- a/addons/promote-new-primary/scripts/promote-master.js +++ b/addons/promote-new-primary/scripts/promote-master.js @@ -33,10 +33,6 @@ function promoteNewPrimary() { this.log("DefinePrimaryNode resp->" + resp); if (resp.result != 0) return resp; - resp = this.checkAvailability(); - if (resp.result != MySQL_FAILED || resp.result != 0) { - return resp; - } //PROXY if (this.getAddOnType()) { resp = this.auth(); @@ -54,10 +50,18 @@ function promoteNewPrimary() { // } } + resp = this.checkAvailability(); + this.log("checkAvailability resp->" + resp); + if (resp.result != MySQL_FAILED && resp.result != 0) { + return resp; + } + resp = this.newPrimaryOnProxy(); + this.log("newPrimaryOnProxy resp->" + resp); if (resp.result != 0) return resp; resp = this.promoteNewSQLPrimary(); + this.log("promoteNewSQLPrimary resp->" + resp); if (resp.result != 0) return resp; resp = this.setDomains(); @@ -67,6 +71,7 @@ function promoteNewPrimary() { if (resp.result != 0) return resp; resp = this.setContainerVar(); + this.log("setContainerVar resp->" + resp); if (resp.result != 0) return resp; resp = this.setNewMasterNode(); @@ -103,13 +108,13 @@ function promoteNewPrimary() { if (force || resp.result == 4109 || (resp.responses && resp.responses[0].result == 4109) || (resp.responses[0].out && resp.responses[0].out.indexOf("is alive") == -1)) { - if (this.getAddOnType()) { + if (!this.getAddOnType()) { resp = this.addIteration(); if (resp.result != 0) return resp; } if ((resp.iterator >= primary_idle_time / 10) || force) { - if (this.getAddOnType()) { + if (!this.getAddOnType()) { resp = this.setIsRunningStatus(true); if (resp.result != 0) return resp; return { @@ -118,8 +123,10 @@ function promoteNewPrimary() { } } } + if (resp.responses[0].error && resp.responses[0].error.indexOf("No route to host") != -1) { this.setFailedPrimary(this.getPrimaryNode()); + this.log("checkAvailability this.getFailedPrimary ->" + this.getFailedPrimary()); return { result: MySQL_FAILED } @@ -382,7 +389,7 @@ function promoteNewPrimary() { }); if (resp.result != 0) return resp; } - + return { result: 0 } } From 016b32163339bf32de605f43704bd862cb51f9a6 Mon Sep 17 00:00:00 2001 From: "alexey.lazarenko" Date: Wed, 25 Oct 2023 12:20:07 +0300 Subject: [PATCH 08/12] JE-66250 --- .../scripts/promote-master.js | 52 +++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/addons/promote-new-primary/scripts/promote-master.js b/addons/promote-new-primary/scripts/promote-master.js index 5b5a6bf9..d245a1b9 100644 --- a/addons/promote-new-primary/scripts/promote-master.js +++ b/addons/promote-new-primary/scripts/promote-master.js @@ -79,12 +79,15 @@ function promoteNewPrimary() { //SAME DONE resp = this.restoreNodes(); + this.log("restoreNodes resp" + resp); if (resp.result != 0) return resp; resp = this.addNode(); + this.log("addNode resp" + resp); if (resp.result != 0) return resp; resp = this.removeFailedPrimary(); + this.log("removeFailedPrimary resp" + resp); if (resp.result != 0) return resp; if (!this.getAddOnType()) { @@ -100,10 +103,11 @@ function promoteNewPrimary() { return { result: 0 } }; - this.checkAvailability = function() { + this.checkAvailability = function(skipIteration) { let command = "mysqladmin -u" + containerEnvs["REPLICA_USER"] + " -p" + containerEnvs["REPLICA_PSWD"] + " ping"; let resp = this.cmdById(this.getPrimaryNode().id, command, 10); + if (skipIteration) return resp; if (force == "false") force = false; if (force || resp.result == 4109 || (resp.responses && resp.responses[0].result == 4109) || @@ -123,7 +127,7 @@ function promoteNewPrimary() { } } } - + if (resp.responses[0].error && resp.responses[0].error.indexOf("No route to host") != -1) { this.setFailedPrimary(this.getPrimaryNode()); this.log("checkAvailability this.getFailedPrimary ->" + this.getFailedPrimary()); @@ -425,7 +429,7 @@ function promoteNewPrimary() { let clusterUp = false; let command = "curl -fsSL 'https://github.com/jelastic-jps/mysql-cluster/raw/master/addons/recovery/scripts/db-recovery.sh' -o /tmp/db_recovery.sh\n" + "bash /tmp/db_recovery.sh --diagnostic" - let resp = this.cmdByGroup(command, SQLDB, 60); + let resp = this.cmdByGroup(command, SQLDB, 60, true); if (resp.result != 0) return resp; let responses = resp.responses, out; @@ -434,14 +438,16 @@ function promoteNewPrimary() { if (responses.length) { for (let i = 0, n = responses.length; i < n; i++) { out = JSON.parse(responses[i].out); - nodes.push({ - address: out.address, - id: responses[i].nodeid, - type: out.node_type - }); - - if (out.service_status == "up" || out.status == "ok") { - clusterUp = true; + if (out.result == 0) { + nodes.push({ + address: out.address, + id: responses[i].nodeid, + type: out.node_type + }); + + if (out.service_status == "up" || out.status == "ok") { + clusterUp = true; + } } } @@ -604,9 +610,8 @@ function promoteNewPrimary() { this.newPrimaryOnProxy = function() { let alreadySetNewPrimary = false; - let resp; - // let resp = this.diagnosticNodes(); - // if (resp.result != 0) return resp; + let resp = this.diagnosticNodes(); + if (resp.result != 0) return resp; let nodes = this.getParsedNodes(); resp = this.getNodesByGroup(SQLDB); @@ -657,12 +662,18 @@ function promoteNewPrimary() { }; this.restoreNodes = function() { - let nodes = this.getParsedNodes(); + // let nodes = this.getParsedNodes(); let newPrimary = this.getNewPrimaryNode(); + let resp = this.getAvailableSQL(SQLDB); + if (resp.result != 0) return resp; + let nodes = resp.nodes; + // node.address != containerEnvs["PRIMARY_IP"] + this.log("this.restoreNodes nodes ->" + nodes); let command = "bash /tmp/db_recovery.sh --scenario restore_secondary_from_primary --donor-ip " + newPrimary.address; for (let i = 0, n = nodes.length; i < n; i++) { - if (nodes[i].id != newPrimary.id && nodes[i].type == SECONDARY) { + // if (nodes[i].id != newPrimary.id && nodes[i].type == SECONDARY) { + if (nodes[i].id != newPrimary.id && nodes[i].address != containerEnvs["PRIMARY_IP"]) { let resp = this.cmdById(nodes[i].id, command); if (resp.result != 0) return resp; } @@ -738,6 +749,15 @@ function promoteNewPrimary() { if (nodeGroup == SQLDB && test) { let resp = this.checkAvailability(); if (resp.result == MySQL_FAILED) { + let resp = this.getAvailableSQL(); + if (resp.result != 0) return resp; + + for (let i = 0, n = resp.nodes.length; i < n; i++) { + if (resp.nodes[i].id) { + resp = this.cmdById(resp.nodes[i].id, command); + if (resp.result != 0) return resp; + } + } return this.cmdById(resp.nodeid, command); } } From 37e6b5c1fcfdc324be2da933947e326d6892c92c Mon Sep 17 00:00:00 2001 From: "alexey.lazarenko" Date: Wed, 25 Oct 2023 12:40:30 +0300 Subject: [PATCH 09/12] Update promote-master.js --- addons/promote-new-primary/scripts/promote-master.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/promote-new-primary/scripts/promote-master.js b/addons/promote-new-primary/scripts/promote-master.js index d245a1b9..96305fd0 100644 --- a/addons/promote-new-primary/scripts/promote-master.js +++ b/addons/promote-new-primary/scripts/promote-master.js @@ -694,7 +694,7 @@ function promoteNewPrimary() { if (nodeGroups.indexOf(String(node.nodeGroup)) == -1) { nodeGroups.push(String(node.nodeGroup)); - resp = this.getNodesByGroup(node.nodeGroup); + let resp = this.getNodesByGroup(node.nodeGroup); if (resp.result != 0) return resp; count = resp.nodes.length; @@ -751,10 +751,11 @@ function promoteNewPrimary() { if (resp.result == MySQL_FAILED) { let resp = this.getAvailableSQL(); if (resp.result != 0) return resp; - + for (let i = 0, n = resp.nodes.length; i < n; i++) { if (resp.nodes[i].id) { resp = this.cmdById(resp.nodes[i].id, command); + this.log("in cmdByGroup cmdById resp->" + resp); if (resp.result != 0) return resp; } } From 52e70a200d96aadaca7bbf06ce386cfa4b906e74 Mon Sep 17 00:00:00 2001 From: "alexey.lazarenko" Date: Tue, 7 Nov 2023 15:18:01 +0200 Subject: [PATCH 10/12] JE-66250 --- .../scripts/promote-master.js | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/addons/promote-new-primary/scripts/promote-master.js b/addons/promote-new-primary/scripts/promote-master.js index 96305fd0..aea2ba2b 100644 --- a/addons/promote-new-primary/scripts/promote-master.js +++ b/addons/promote-new-primary/scripts/promote-master.js @@ -29,17 +29,13 @@ function promoteNewPrimary() { let resp = this.defineAddonType(); if (resp.result != 0) return resp; - resp = this.DefinePrimaryNode(); - this.log("DefinePrimaryNode resp->" + resp); - if (resp.result != 0) return resp; - //PROXY if (this.getAddOnType()) { resp = this.auth(); if (resp.result != 0) return resp; } else { //NO PROXY - let resp = this.isProcessRunning(); + resp = this.isProcessRunning(); if (resp.result != 0) return resp; if (resp.isRunning) return {result: 0} @@ -50,18 +46,18 @@ function promoteNewPrimary() { // } } + resp = this.DefinePrimaryNode(); + if (resp.result != 0) return resp; + resp = this.checkAvailability(); - this.log("checkAvailability resp->" + resp); if (resp.result != MySQL_FAILED && resp.result != 0) { return resp; } resp = this.newPrimaryOnProxy(); - this.log("newPrimaryOnProxy resp->" + resp); if (resp.result != 0) return resp; resp = this.promoteNewSQLPrimary(); - this.log("promoteNewSQLPrimary resp->" + resp); if (resp.result != 0) return resp; resp = this.setDomains(); @@ -71,7 +67,6 @@ function promoteNewPrimary() { if (resp.result != 0) return resp; resp = this.setContainerVar(); - this.log("setContainerVar resp->" + resp); if (resp.result != 0) return resp; resp = this.setNewMasterNode(); @@ -79,15 +74,12 @@ function promoteNewPrimary() { //SAME DONE resp = this.restoreNodes(); - this.log("restoreNodes resp" + resp); if (resp.result != 0) return resp; resp = this.addNode(); - this.log("addNode resp" + resp); if (resp.result != 0) return resp; resp = this.removeFailedPrimary(); - this.log("removeFailedPrimary resp" + resp); if (resp.result != 0) return resp; if (!this.getAddOnType()) { @@ -130,7 +122,7 @@ function promoteNewPrimary() { if (resp.responses[0].error && resp.responses[0].error.indexOf("No route to host") != -1) { this.setFailedPrimary(this.getPrimaryNode()); - this.log("checkAvailability this.getFailedPrimary ->" + this.getFailedPrimary()); + this.setNoRoute(true); return { result: MySQL_FAILED } @@ -214,7 +206,8 @@ function promoteNewPrimary() { this.log("API api.env.control.SetMasterNode"); return api.env.control.SetMasterNode({ envName: envName, - nodeId: this.getNewPrimaryNode().id + nodeId: this.getNewPrimaryNode().id, + ignoreErrors: true }); } else { this.log("Eval SetMasterNode"); @@ -359,7 +352,7 @@ function promoteNewPrimary() { }; this.auth = function() { - if (!session && String(getParam("token", "")).replace(/\s/g, "") != "${token}") { + if (!session && String(getParam("token", "")).replace(/\s/g, "") != "RCmfxWady8") { return { result: Response.PERMISSION_DENIED, error: "wrong token", @@ -410,8 +403,9 @@ function promoteNewPrimary() { this.getAvailableSQL = function() { let availableNodes = []; - let nodes = this.getNodesByGroup(SQLDB); - if (nodes.result != 0) return nodes; + let resp = this.getNodesByGroup(SQLDB); + if (resp.result != 0) return resp; + let nodes = resp.nodes; for (let i = 0, n = nodes.length; i < n; i++) { if (nodes[i].address != this.getFailedPrimary().address) { @@ -525,6 +519,14 @@ function promoteNewPrimary() { this.failedPrimary = node; }; + this.setNoRoute = function(value) { + this.noRoute = value; + }; + + this.getNoRoute = function() { + return this.noRoute; + }; + this.getAvailableProxy = function() { return this.availableProxy || ""; }; @@ -613,7 +615,7 @@ function promoteNewPrimary() { let resp = this.diagnosticNodes(); if (resp.result != 0) return resp; - let nodes = this.getParsedNodes(); + // let nodes = this.getParsedNodes(); resp = this.getNodesByGroup(SQLDB); if (resp && resp.nodes) { @@ -669,7 +671,6 @@ function promoteNewPrimary() { if (resp.result != 0) return resp; let nodes = resp.nodes; // node.address != containerEnvs["PRIMARY_IP"] - this.log("this.restoreNodes nodes ->" + nodes); let command = "bash /tmp/db_recovery.sh --scenario restore_secondary_from_primary --donor-ip " + newPrimary.address; for (let i = 0, n = nodes.length; i < n; i++) { // if (nodes[i].id != newPrimary.id && nodes[i].type == SECONDARY) { @@ -747,19 +748,20 @@ function promoteNewPrimary() { } if (nodeGroup == SQLDB && test) { - let resp = this.checkAvailability(); - if (resp.result == MySQL_FAILED) { + if (this.getNoRoute()) { let resp = this.getAvailableSQL(); if (resp.result != 0) return resp; + let responses = []; for (let i = 0, n = resp.nodes.length; i < n; i++) { if (resp.nodes[i].id) { resp = this.cmdById(resp.nodes[i].id, command); - this.log("in cmdByGroup cmdById resp->" + resp); +// {"result":0,"responses":[{"result":0,"errOut":"","nodeid":8482,"exitStatus":0,"out":"{\"result\":0,\"node_type\":\"secondary\",\"address\":\"192.168.130.79\",\"service_status\":\"up\",\"status\":\"failed\",\"galera_size\":\"\",\"galera_myisam\":\"\",\"error\":\"\"}"}]} if (resp.result != 0) return resp; + responses.push(resp.responses[0]); } } - return this.cmdById(resp.nodeid, command); + return { result: 0, responses: responses } } } From 529fb1d7d5940d02cf5a5fe31101b34d9a146336 Mon Sep 17 00:00:00 2001 From: "alexey.lazarenko" Date: Tue, 7 Nov 2023 15:19:48 +0200 Subject: [PATCH 11/12] JE-66250 --- addons/promote-new-primary/scripts/promote-master.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/promote-new-primary/scripts/promote-master.js b/addons/promote-new-primary/scripts/promote-master.js index aea2ba2b..8f58dc5f 100644 --- a/addons/promote-new-primary/scripts/promote-master.js +++ b/addons/promote-new-primary/scripts/promote-master.js @@ -352,7 +352,7 @@ function promoteNewPrimary() { }; this.auth = function() { - if (!session && String(getParam("token", "")).replace(/\s/g, "") != "RCmfxWady8") { + if (!session && String(getParam("token", "")).replace(/\s/g, "") != "${token}") { return { result: Response.PERMISSION_DENIED, error: "wrong token", @@ -756,7 +756,6 @@ function promoteNewPrimary() { for (let i = 0, n = resp.nodes.length; i < n; i++) { if (resp.nodes[i].id) { resp = this.cmdById(resp.nodes[i].id, command); -// {"result":0,"responses":[{"result":0,"errOut":"","nodeid":8482,"exitStatus":0,"out":"{\"result\":0,\"node_type\":\"secondary\",\"address\":\"192.168.130.79\",\"service_status\":\"up\",\"status\":\"failed\",\"galera_size\":\"\",\"galera_myisam\":\"\",\"error\":\"\"}"}]} if (resp.result != 0) return resp; responses.push(resp.responses[0]); } From c1ae66868f5e4782efe4d02ea68dcadeb69c9873 Mon Sep 17 00:00:00 2001 From: sych74 Date: Tue, 19 Mar 2024 08:15:04 +0100 Subject: [PATCH 12/12] JE-69543 --- addons/promote-new-primary/scripts/promote-master.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/promote-new-primary/scripts/promote-master.js b/addons/promote-new-primary/scripts/promote-master.js index 8f58dc5f..0c22ca4c 100644 --- a/addons/promote-new-primary/scripts/promote-master.js +++ b/addons/promote-new-primary/scripts/promote-master.js @@ -79,8 +79,8 @@ function promoteNewPrimary() { resp = this.addNode(); if (resp.result != 0) return resp; - resp = this.removeFailedPrimary(); - if (resp.result != 0) return resp; +// resp = this.removeFailedPrimary(); +// if (resp.result != 0) return resp; if (!this.getAddOnType()) { resp = this.addIteration(true);