feat(binlog): refs #4409 New function for binlog queue monitoring
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Juan Ferrer 2024-04-15 09:31:24 +02:00
parent 40473d0cc9
commit 50d6c234be
1 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,45 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`binlogQueue_getDelay`(vCode VARCHAR(255))
RETURNS BIGINT
NOT DETERMINISTIC
BEGIN
/**
* Returns the difference between the current position of the binary log and
* the passed queue.
*
* @param vCode The queue code
* @return The difference in MB
*/
DECLARE vCurLogName VARCHAR(255);
DECLARE vCurPosition BIGINT;
DECLARE vQueueLogName VARCHAR(255);
DECLARE vQueuePosition BIGINT;
DECLARE vDelay BIGINT;
SELECT VARIABLE_VALUE INTO vCurLogName
FROM information_schema.GLOBAL_STATUS
WHERE VARIABLE_NAME = 'BINLOG_SNAPSHOT_FILE';
SELECT VARIABLE_VALUE INTO vCurPosition
FROM information_schema.GLOBAL_STATUS
WHERE VARIABLE_NAME = 'BINLOG_SNAPSHOT_POSITION';
SELECT logName, `position`
INTO vQueueLogName, vQueuePosition
FROM binlogQueue
WHERE code = vCode;
IF vQueuePosition IS NULL THEN
RETURN NULL;
END IF;
SET vDelay =
vCurPosition - CAST(vQueuePosition AS SIGNED) +
@@max_binlog_size * (
CAST(REGEXP_SUBSTR(vCurLogName, '[0-9]+') AS SIGNED) -
CAST(REGEXP_SUBSTR(vQueueLogName, '[0-9]+') AS SIGNED)
);
RETURN ROUND(vDelay / POW(1024, 2));
END$$
DELIMITER ;