From fb5b55613d8279f0f87be74334f5caaa77a67a1f Mon Sep 17 00:00:00 2001 From: Manuel Finelli Date: Wed, 2 Oct 2024 13:08:01 +0100 Subject: [PATCH] Issue #312 fixed --- controllers/transaction_recovery.go | 37 +++++++++++++++++------------ pkg/util/wildfly_mgmt.go | 2 +- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/controllers/transaction_recovery.go b/controllers/transaction_recovery.go index 2208b879..7acacdd7 100644 --- a/controllers/transaction_recovery.go +++ b/controllers/transaction_recovery.go @@ -19,6 +19,7 @@ import ( var ( recoveryErrorRegExp = regexp.MustCompile("ERROR.*Periodic Recovery") + heuristic_types = [5]string{"HEURISTIC", "HEURISTIC_ROLLBACK", "HEURISTIC_COMMIT", "HEURISTIC_MIXED", "HEURISTIC_HAZARD"} ) const ( @@ -152,24 +153,30 @@ func (r *WildFlyServerReconciler) checkRecovery(reqLogger logr.Logger, scaleDown } // Is the number of in-doubt transactions equal to zero? transactions := jsonResult["result"] - txnMap, isMap := transactions.(map[string]interface{}) // typing the variable to be a map of interfaces + // typing the variable to be a map of interfaces + txnMap, isMap := transactions.(map[string]interface{}) if isMap && len(txnMap) > 0 { // Check for HEURISTIC transactions - jsonResult, err := wfly.ExecuteMgmtOp(scaleDownPod, wfly.MgmtOpTxnReadHeuristic) - if err != nil { - return genericError, "", fmt.Errorf("Cannot read HEURISTIC transactions from the log store of the pod %v, error: %v", scaleDownPodName, err) - } - if !wfly.IsMgmtOutcomeSuccesful(jsonResult) { - return genericError, "", fmt.Errorf("Cannot read HEURISTIC transactions from the log store of the pod %v", scaleDownPodName) - } - // Is the number of HEURISTIC transactions equal to zero? - transactions := jsonResult["result"] - heuristicTxnArray, isArray := transactions.([]interface{}) // typing the variable to be an array of interfaces - if isArray && len(heuristicTxnArray) > 0 { - retString := fmt.Sprintf("There are HEURISTIC transactions in the log store of the pod %v. Please, resolve them manually, "+ - "transaction list: %v", scaleDownPodName, heuristicTxnArray) - return heuristic, retString, nil + for _, heuristic_type := range heuristic_types { + jsonResult, err := wfly.ExecuteMgmtOp(scaleDownPod, fmt.Sprintf(wfly.MgmtOpTxnReadHeuristicPattern, heuristic_type)) + if err != nil { + return genericError, "", fmt.Errorf("Cannot read %s transactions from the log store of the pod %v, error: %v", heuristic_type, scaleDownPodName, err) + } + if !wfly.IsMgmtOutcomeSuccesful(jsonResult) { + return genericError, "", fmt.Errorf("Cannot read %s transactions from the log store of the pod %v", heuristic_type, scaleDownPodName) + } + + // Is the number of HEURISTIC transactions equal to zero? + transactions := jsonResult["result"] + // typing the variable to be an array of interfaces + heuristicTxnArray, isArray := transactions.([]interface{}) + + if isArray && len(heuristicTxnArray) > 0 { + retString := fmt.Sprintf("There are %s transactions in the log store of the pod %v. Please, resolve them manually, "+ + "transaction list: %v", heuristic_type, scaleDownPodName, heuristicTxnArray) + return heuristic, retString, nil + } } retString := fmt.Sprintf("A recovery scan is needed as the log store of the pod %v is not empty, "+ diff --git a/pkg/util/wildfly_mgmt.go b/pkg/util/wildfly_mgmt.go index 868954d8..2b792986 100644 --- a/pkg/util/wildfly_mgmt.go +++ b/pkg/util/wildfly_mgmt.go @@ -31,7 +31,7 @@ var ( // MgmtOpTxnRead is a JBoss CLI command for reading transaction log store MgmtOpTxnRead = "/subsystem=transactions/log-store=log-store:read-children-resources(child-type=transactions,recursive=true,include-runtime=true)" // MgmtOpTxnReadHeuristic is a JBoss CLI command for scanning the log store in search of transactions in HEURISTIC status - MgmtOpTxnReadHeuristic = "/subsystem=transactions/log-store=log-store/transactions=*/participants=*:query(where={\"status\"=\"HEURISTIC\"}" + MgmtOpTxnReadHeuristicPattern = "/subsystem=transactions/log-store=log-store/transactions=*/participants=*:query(where={\"status\"=\"%s\"}" // MgmtOpTxnRecoverySocketBindingRead is a JBoss CLI command for reading name of recovery socket binding MgmtOpTxnRecoverySocketBindingRead = "/subsystem=transactions:read-attribute(name=socket-binding)" // MgmtOpSocketBindingRead is a JBoss CLI command for reading all data on the socket binding group