From b457da31e5fe2d1f5dfe159d4260ed460a5a4992 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 18 Jul 2024 12:33:35 +0200 Subject: [PATCH] feat: refs #7486 Fix no DO_RELEASE --- back/methods/collection/assign.js | 33 ++++++++++++++++--- .../vn/procedures/collection_assign.sql | 13 -------- db/routines/vn/procedures/collection_get.sql | 5 --- db/routines/vn/procedures/collection_new.sql | 14 -------- .../vn/procedures/productionControl.sql | 5 --- db/routines/vn/procedures/ticket_Clone.sql | 5 --- .../ticket_splitItemPackingType.sql | 14 -------- 7 files changed, 28 insertions(+), 61 deletions(-) diff --git a/back/methods/collection/assign.js b/back/methods/collection/assign.js index 0484eb5a8..ff7a83e22 100644 --- a/back/methods/collection/assign.js +++ b/back/methods/collection/assign.js @@ -20,13 +20,36 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const [, , [{collectionFk}]] = - await Self.rawSql('CALL vn.collection_assign(?, @vCollectionFk); SELECT @vCollectionFk collectionFk', + let threadId; + + try { + const result = + await Self.rawSql(` + CALL vn.collection_assign(?, @vCollectionFk); + SELECT @vCollectionFk collectionFk, + CONNECTION_ID() threadId + `, [userId], myOptions); - if (!collectionFk) throw new UserError('There are not picking tickets'); - await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk], myOptions); + threadId = result[2][0].threadId; + const collectionFk = result[2][0].collectionFk; + if (!collectionFk) throw new UserError('There are not picking tickets'); - return collectionFk; + await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk], myOptions); + + return collectionFk; + } catch (e) { + // Error deadlock refs #7486 + if (e.code === 'ER_LOCK_DEADLOCK') { + const [hasLock] = await Self.rawSql(` + SELECT COUNT(*) FROM INFORMATION_SCHEMA.METADATA_LOCK_INFO + WHERE LOCK_MODE = 'MDL_SHARED_NO_WRITE' + AND THREAD_ID = ? + `, + [threadId], myOptions); + if (hasLock) await Self.rawSql(`KILL ?`, [threadId], myOptions); + } + throw e; + } }; }; diff --git a/db/routines/vn/procedures/collection_assign.sql b/db/routines/vn/procedures/collection_assign.sql index f9032a91d..29c9b3e08 100644 --- a/db/routines/vn/procedures/collection_assign.sql +++ b/db/routines/vn/procedures/collection_assign.sql @@ -17,22 +17,9 @@ BEGIN DECLARE vWarehouseFk INT; DECLARE vLockName VARCHAR(215); DECLARE vLockTime INT DEFAULT 30; - DECLARE vErrorNumber INT; - DECLARE vErrorMsg TEXT; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - GET DIAGNOSTICS CONDITION 1 - vErrorNumber = MYSQL_ERRNO, - vErrorMsg = MESSAGE_TEXT; - - CALL util.debugAdd('collection_assign', JSON_OBJECT( - 'errorNumber', vErrorNumber, - 'errorMsg', vErrorMsg, - 'lockName', vLockName, - 'userFk', vUserFk - )); -- Tmp - IF vLockName IS NOT NULL THEN DO RELEASE_LOCK(vLockName); END IF; diff --git a/db/routines/vn/procedures/collection_get.sql b/db/routines/vn/procedures/collection_get.sql index d29f14ca9..84ca9303c 100644 --- a/db/routines/vn/procedures/collection_get.sql +++ b/db/routines/vn/procedures/collection_get.sql @@ -7,11 +7,6 @@ BEGIN * @param vWorkerFk id del worker. * @table Devuelve tabla temporal con las colecciones pendientes */ - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - RESIGNAL; - END; - CREATE OR REPLACE TEMPORARY TABLE tmp.collection ENGINE = MEMORY SELECT c.id collectionFk, diff --git a/db/routines/vn/procedures/collection_new.sql b/db/routines/vn/procedures/collection_new.sql index 0bd6e1b25..20c3d61b5 100644 --- a/db/routines/vn/procedures/collection_new.sql +++ b/db/routines/vn/procedures/collection_new.sql @@ -28,8 +28,6 @@ BEGIN DECLARE vLockName VARCHAR(215); DECLARE vLockTime INT DEFAULT 30; DECLARE vFreeWagonFk INT; - DECLARE vErrorNumber INT; - DECLARE vErrorMsg TEXT; DECLARE c1 CURSOR FOR SELECT ticketFk, `lines`, m3 @@ -49,18 +47,6 @@ BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - GET DIAGNOSTICS CONDITION 1 - vErrorNumber = MYSQL_ERRNO, - vErrorMsg = MESSAGE_TEXT; - - CALL util.debugAdd('collection_new', JSON_OBJECT( - 'errorNumber', vErrorNumber, - 'errorMsg', vErrorMsg, - 'lockName', vLockName, - 'userFk', vUserFk, - 'ticketFk', vTicketFk - )); -- Tmp - IF vLockName IS NOT NULL THEN DO RELEASE_LOCK(vLockName); END IF; diff --git a/db/routines/vn/procedures/productionControl.sql b/db/routines/vn/procedures/productionControl.sql index dad46393d..df2d07148 100644 --- a/db/routines/vn/procedures/productionControl.sql +++ b/db/routines/vn/procedures/productionControl.sql @@ -15,11 +15,6 @@ proc: BEGIN DECLARE vEndingDate DATETIME; DECLARE vIsTodayRelative BOOLEAN; - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - RESIGNAL; - END; - SELECT util.dayEnd(util.VN_CURDATE()) + INTERVAL LEAST(vScopeDays, maxProductionScopeDays) DAY INTO vEndingDate FROM productionConfig; diff --git a/db/routines/vn/procedures/ticket_Clone.sql b/db/routines/vn/procedures/ticket_Clone.sql index d22d3c7ff..7670e832e 100644 --- a/db/routines/vn/procedures/ticket_Clone.sql +++ b/db/routines/vn/procedures/ticket_Clone.sql @@ -9,11 +9,6 @@ BEGIN */ DECLARE vStateFk INT; - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - RESIGNAL; - END; - INSERT INTO ticket ( clientFk, shipped, diff --git a/db/routines/vn/procedures/ticket_splitItemPackingType.sql b/db/routines/vn/procedures/ticket_splitItemPackingType.sql index e2c55e28a..f90650020 100644 --- a/db/routines/vn/procedures/ticket_splitItemPackingType.sql +++ b/db/routines/vn/procedures/ticket_splitItemPackingType.sql @@ -27,20 +27,6 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - GET DIAGNOSTICS CONDITION 1 - vErrorNumber = MYSQL_ERRNO, - vErrorMsg = MESSAGE_TEXT; - - CALL util.debugAdd('ticket_splitItemPackingType', JSON_OBJECT( - 'errorNumber', vErrorNumber, - 'errorMsg', vErrorMsg, - 'ticketFk', vTicketFk - )); -- Tmp - RESIGNAL; - END; - DELETE FROM vn.sale WHERE quantity = 0 AND ticketFk = vTicketFk; -- 2.40.1