Galera Functions

Starting with version 4 of Galera Cluster, there are several Galera functions available. At this point, the Galera functions related to Global Transaction ID (GTID). They return a GTID or have effect on transactions related to a GTID.

Function Arguments Initial Version
WSREP_LAST_SEEN_GTID()   4.0
WSREP_LAST_WRITTEN_GTID()   4.0
WSREP_SYNC_WAIT_UPTO_GTID() gtid [timeout] 4.0

WSREP_LAST_SEEN_GTID()

Much like LAST_INSERT_ID() for getting the identification number of the last row inserted in MySQL, this function returns the Global Transaction ID of the last write transaction observed by the client.

Function WSREP_LAST_SEEN_GTID()
Arguments None
Initial Version Version 4.0

This function returns the Global Transaction ID of the last write transaction observed by the client. It can be useful in combination with WSREP_SYNC_WAIT_UPTO_GTID(). You can use this parameter to identify the transaction upon which it should wait before unblocking the client.

Below is an example of how you might use the WSREP_LAST_SEEN_GTID() function to get the Global Transaction ID of the last write transaction observed:

SELECT WSREP_LAST_SEEN_GTID();

WSREP_LAST_WRITTEN_GTID()

This function returns the Global Transaction ID of the last write transaction made by the client.

Function WSREP_LAST_WRITTEN_GTID()
Arguments None
Initial Version Version 4.0

This function returns the Global Transaction ID of the last write transaction made by the client. This can be useful in combination with WSREP_SYNC_WAIT_UPTO_GTID(). You can use this parameter to identify the transaction upon which it should wait before unblocking the client.

Below is an example of how you might use the WSREP_LAST_SEEN_GTID() function to get the Global Transaction ID of the last write transaction observed:

BEGIN;

UPDATE table_name SET id = 0
WHERE field = 'example';

COMMIT;

SELECT WSREP_LAST_WRITTEN_GTID();

WSREP_SYNC_WAIT_UPTO_GTID()

This function blocks the client until the node applies and commits the given transaction.

Function WSREP_SYNC_WAIT_UPTO_GTID()
Required Arguments Global Transaction ID
Optional Arguments timeout
Initial Version Version 4.0

This function blocks the client until the node applies and commits the given Global Transaction ID. Optional argument accepts timeout in seconds. If you don’t provide a timeout, it will continue to block indefinitely. It returns the following values:

  • 1: The node applied and committed the given Global Transaction ID.
  • ER_LOCAL_WAIT_TIMEOUT Error: The function times out before the node can apply the transaction.
  • ER_WRONG_ARGUMENTS Error: The function is given an incorrect Global Transaction ID.

Below is an example of how you might use the WSREP_SYNC_WAIT_UPTO_GTID() function:

$transaction_gtid = SELECT WSREP_LAST_SEEN_GTID();
...
SELECT WSREP_SYNC_WAIT_UPTO_GTID($transaction_gtid);