feat: refs #7144 DiagnoseProducionFailure first commit

This commit is contained in:
Guillermo Bonet 2024-05-21 07:09:26 +02:00
parent 9cba2be00d
commit 14068085d1
3 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,22 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`diagnoseProductionFailure`(
vWarehouseFk INT
)
BEGIN
/**
* Comprueba si hay fallos en producción.
*/
CREATE OR REPLACE TEMPORARY TABLE tmp.diagnoseProductionFailure (
`message` TEXT NOT NULL,
hasError TINYINT(1) NOT NULL
);
CALL vn.diagnoseProductionFailure_dbFreeze();
CALL vn.diagnoseProductionFailure_dbGetLock();
SELECT * FROM tmp.diagnoseProductionFailure;
DROP TEMPORARY TABLE tmp.diagnoseProductionFailure;
END$$
DELIMITER ;

View File

@ -0,0 +1,19 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`diagnoseProductionFailure_dbFreeze`()
BEGIN
/**
* Comprueba si la db está congelada.
*
* @table tmp.diagnoseProductionFailure(message, hasError)
*/
DECLARE vHasError BOOL;
SELECT IF(COUNT(ID) > 5, TRUE, FALSE) INTO vHasError # Variable en tabla
FROM information_schema.PROCESSLIST
WHERE COMMAND = 'Query'
AND `time` > 60; # Variable en tabla
INSERT INTO tmp.diagnoseProductionFailure
SELECT 'Base de datos congelada', vHasError;
END$$
DELIMITER ;

View File

@ -0,0 +1,20 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`diagnoseProductionFailure_dbGetLock`()
BEGIN
/**
* Comprueba si la db está congelada.
*
* @table tmp.diagnoseProductionFailure(message, hasError)
*/
DECLARE vHasError BOOL;
SELECT COUNT(*) INTO vHasError
FROM information_schema.METADATA_LOCK_INFO mli
JOIN information_schema.PROCESSLIST pl ON pl.ID = mli.THREAD_ID
WHERE mli.LOCK_MODE = 'MDL_SHARED_NO_WRITE'
AND pl.`time` > 30; # Variable en tabla
INSERT INTO tmp.diagnoseProductionFailure
SELECT 'Get lock bloqueando para asignar colecciones', vHasError;
END$$
DELIMITER ;