Optimise the backup node choosing method
Because we always choose dbs01 as backup node, other services work
slowly or with timeout errors. This commit exclude the most loaded
node from the list of available primary nodes for backup procedure.
Related-PROD: PROD-36334
Change-Id: Ife434226979365eaef35882bd37ea717ca184596
diff --git a/galera-database-backup-pipeline.groovy b/galera-database-backup-pipeline.groovy
index 8239aa6..466c7ea 100644
--- a/galera-database-backup-pipeline.groovy
+++ b/galera-database-backup-pipeline.groovy
@@ -8,6 +8,8 @@
primaryNodes = []
syncedNodes = []
galeraMembers = []
+maxValue = 0
+masterNode = "none"
if (common.validInputParam('OVERRIDE_BACKUP_NODE')) {
backupNode = OVERRIDE_BACKUP_NODE
@@ -37,8 +39,29 @@
}
}
stage('Choose backup node') {
- backupNode = primaryNodes.sort()[0] // STEP 2 - Use node with lowest hostname number (last option if everything previous fails)
- }
+ primaryNodes = primaryNodes.sort()
+ for (node in primaryNodes.reverse()) { // Looking for the node with the highest mysql_queries value
+ try {
+ queriesValue = galera.getWsrepParameters(pepperEnv, node, "Queries", false).get('Queries')
+ common.infoMsg("Queries for ${node} - ${queriesValue}")
+ if (queriesValue >= maxValue) {
+ maxValue = queriesValue
+ masterNode = node
+ common.infoMsg("Current main node in galera cluster: ${masterNode}")
+ }
+ } catch (Exception e) {
+ common.warningMsg("Minion '${node}' unavailable.")
+ }
+ }
+ if (masterNode.equals("none")) {
+ backupNode = primaryNodes[-1] // STEP 2 - Use node with highest hostname number (last option if everything previous fails)
+ } else {
+ common.infoMsg("Master node is ${masterNode}.")
+ primaryNodes = primaryNodes.minus(masterNode)
+ backupNode = primaryNodes[-1]
+ }
+ common.infoMsg("Choose backup node as ${backupNode}.")
+ }
} else {
stage('Choose backup node') {
common.infoMsg("Backup node backup was overriden to ${backupNode}.")
@@ -72,4 +95,4 @@
}
}
}
-}
\ No newline at end of file
+}