From 14068085d1fea1aef74d18ef3a84201b51a8ced0 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 21 May 2024 07:09:26 +0200 Subject: [PATCH] feat: refs #7144 DiagnoseProducionFailure first commit --- .../procedures/diagnoseProductionFailure.sql | 22 +++++++++++++++++++ .../diagnoseProductionFailure_dbFreeze.sql | 19 ++++++++++++++++ .../diagnoseProductionFailure_dbGetLock.sql | 20 +++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 db/routines/vn/procedures/diagnoseProductionFailure.sql create mode 100644 db/routines/vn/procedures/diagnoseProductionFailure_dbFreeze.sql create mode 100644 db/routines/vn/procedures/diagnoseProductionFailure_dbGetLock.sql diff --git a/db/routines/vn/procedures/diagnoseProductionFailure.sql b/db/routines/vn/procedures/diagnoseProductionFailure.sql new file mode 100644 index 000000000..e2f72e0a5 --- /dev/null +++ b/db/routines/vn/procedures/diagnoseProductionFailure.sql @@ -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 ; diff --git a/db/routines/vn/procedures/diagnoseProductionFailure_dbFreeze.sql b/db/routines/vn/procedures/diagnoseProductionFailure_dbFreeze.sql new file mode 100644 index 000000000..bf562235d --- /dev/null +++ b/db/routines/vn/procedures/diagnoseProductionFailure_dbFreeze.sql @@ -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 ; diff --git a/db/routines/vn/procedures/diagnoseProductionFailure_dbGetLock.sql b/db/routines/vn/procedures/diagnoseProductionFailure_dbGetLock.sql new file mode 100644 index 000000000..af09b8f93 --- /dev/null +++ b/db/routines/vn/procedures/diagnoseProductionFailure_dbGetLock.sql @@ -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 ;