Master Galera cluster management with Mydbops! Galera 4 came up with the lot of new features , which helps to effectively handle the cluster . In this blog I am going to explain in detail about the Galera 4 functions which were introduced for Global Transaction ID ( GTID ) .
GTID functions in Galera 4
- wsrep_last_written_gtid()
- wsrep_last_seen_gtid()
- wsrep_sync_wait_upto_gtid()
Actually i have planned to test these functions on Percona XtraDB Cluster 8.0.15 experimental release. But, the function wsrep_sync_wait_upto_gtid was not supported in PXC 8 experimental release .
BUG link : https://jira.percona.com/browse/PXC-2688
So, I have installed MariaDB Galera cluster 10.4.11 and started my testing.
wsrep_last_written_gtid
- The function will returns the GTID of the last write transaction made by the client.
- This can differ between different nodes in a single cluster group and different client sessions within a node.
- This function can be used with wsrep_sync_wait_upto_gtid to identify the transaction upon which it should wait before unblocking the client.
wsrep_last_seen_gtid
- The function returns the GTID of the last committed transaction observed by the client.
- This can differ between the different nodes within a cluster group as galera is Virtually Synchronous .
- The function can be used with wsrep_sync_wait_upto_gtid to identify the transaction upon which it should wait before unblocking the client.
wsrep_sync_wait_upto_gtid
- This function can be used to blocks the other transactions ( sessions) until the node applies and commits the provided GTID.
- We have the option to provide the timeout, If we don’t provide a timeout, it will take the defaults value of repl.causal_read_timeout.
- This function is helpful in case, you don’t want to allow the writes to happen in the node until committing the give GTID.
Lab section
Let us simulate a work load to test out these wsrep functions.
Setup
- 2 Node Galera Cluster ( Same Hardware )
- 192.168.33.21
- 192.168.33.22
- 2 two tables ( sbtest1, sbtest2).
- 1M records in each table.
Steps in Test case:
- Disable the cluster sync between the nodes.
- Perform a full table UPDATE on both tables sbtest1 and sbtest2 (without any WHERE clause) on node1.
- Fetch the last updated GTID on node1 using function wsrep_last_seen_gtid.
- Enable sync on node2 with function wsrep_sync_wait_upto_gtid (ex, wsrep_last_seen_gtid,500) .
- Make a write/read on node2 and validate it.
Testing phase
Validate the cluster nodes and load the data for testing.
Disabling the cluster sync between the nodes.
Performing a full table UPDATE on tables.
Fetching the last executed gtid in node1 and Enabling sync on node2 with function wsrep_sync_wait_upto_gtid.
On node 1,
On node2
wsrep_sync_wait_upto_gtid took 3 mins 5 sec to apply the UPDATE events .
When the wsrep_sync_wait_upto_gtid was in progress ,cluster prevents the operations by new client session (read/write).
Note : Based on my experience, it was affecting the newly created MySQL sessions, the existing client sessions were not affected.
I have also created the BUG with MariaDB to understand this behaviour
BUG link : https://jira.mariadb.org/browse/MDEV-21338
Additionally , We can also integrate these functions with the existing MySQL GTID functions.
i,e ) To know the lag ( flow control ) between two servers , you can use the below
wait_for_executed_gtid_set ( for GTID replication ) function is the partially equivalent to wsrep_sync_wait_upto_gtid ( for Galera replication )
Hope this blog helps to someone who is looking for the Galera functions for GTID . At Mydbops, We are keep testing the new things on MySQL and related tools, will be coming back with new blog soon.
Empower Your Galera Cluster with Mydbops!
Mydbops offers comprehensive MySQL services to elevate your database environment.
{{cta}}