Skip to content

Instantly share code, notes, and snippets.

@lefred
Created March 1, 2016 13:28
Show Gist options
  • Save lefred/07c9e1801ebdd5f7ff1b to your computer and use it in GitHub Desktop.
Save lefred/07c9e1801ebdd5f7ff1b to your computer and use it in GitHub Desktop.
galeraWaitUntilEmptyRecvQueue
USE test; DROP FUNCTION IF EXISTS galeraWaitUntilEmptyRecvQueue;
DELIMITER $$
CREATE
DEFINER=root@localhost FUNCTION galeraWaitUntilEmptyRecvQueue()
RETURNS INT UNSIGNED READS SQL DATA
BEGIN
DECLARE queue INT UNSIGNED;
DECLARE starttime TIMESTAMP;
DECLARE blackhole INT UNSIGNED;
SET starttime = SYSDATE();
SELECT VARIABLE_VALUE AS trx INTO queue
FROM information_schema.GLOBAL_STATUS
WHERE VARIABLE_NAME = 'wsrep_local_recv_queue';
WHILE queue > 1 DO /* we allow the queue to be 1 */
SELECT VARIABLE_VALUE AS trx INTO queue
FROM information_schema.GLOBAL_STATUS
WHERE VARIABLE_NAME = 'wsrep_local_recv_queue';
SELECT SLEEP(1) into blackhole;
END WHILE;
RETURN SYSDATE() - starttime;
END$$
DELIMITER ;[
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment