[MDEV-32215] Add Mariabackup option to set gtid_slave_pos to original server's gtid_current_pos during prepare Created: 2019-10-03 Updated: 2023-09-20 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major |
| Reporter: | Cole Busby (Inactive) | Assignee: | Rick Pizzi |
| Resolution: | Unresolved | Votes: | 2 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
This was originally created as MDEV-18405. Many users use Mariabackup to build slaves using the process outlined in the following documentation page: https://mariadb.com/kb/en/library/setting-up-a-replication-slave-with-mariabackup/ One problem with this process is that Mariabackup doesn't back up and restore the original server's entire GTID state, which can be considered to be the value of gtid_current_pos. https://mariadb.com/kb/en/library/gtid/#gtid_current_pos The value of gtid_current_pos is constructed from the values of two other system variables--gtid_slave_pos and gtid_binlog_pos. https://mariadb.com/kb/en/library/gtid/#gtid_slave_pos https://mariadb.com/kb/en/library/gtid/#gtid_binlog_pos Mariabackup does back up and restores the original server's value for gtid_slave_pos, because that information is stored in mysql.gtid_slave_pos, which is an InnoDB table. https://mariadb.com/kb/en/library/mysqlgtid_slave_pos-table/ Mariabackup does not currently back up and restore the original server's gtid_binlog_pos, because that information is stored in the binary logs, which are not backed up. This means that a server restored from a backup is missing some GTID state by default. Mariabackup does back up the original server's value of gtid_current_pos in the xtrabackup_binlog_info file. https://mariadb.com/kb/en/library/files-created-by-mariabackup/#xtrabackup_binlog_info This means that if a user wants to build a slave using a backup, then they can restore the backup, and then they can extract the original server's gtid_current_pos from xtrabackup_binlog_info:
And then the user would need to use this value to set the value of gtid_slave_pos, and then they could set up replication:
Some users would prefer if the value of gtid_slave_pos would automatically be set to the original server's gtid_current_pos when a backup was prepared. That way, users would not have to worry about manually fixing the GTID state, and they could just set up replication from a slave created from a backup by doing something like this:
And the slave would automatically know where to start replicating from. |
| Comments |
| Comment by Julien Fritsch [ 2019-10-28 ] | |||||||||||||||||
|
ralf.gebhardt@mariadb.com it's assigned to you because we have 3 customer issues pending a decision from you on it. | |||||||||||||||||
| Comment by Vladislav Vaintroub [ 2021-04-02 ] | |||||||||||||||||
|
Elkin, I have no idea what GeoffMontee is asking me to, I see gtid => I forward to replication. | |||||||||||||||||
| Comment by Geoff Montee (Inactive) [ 2021-04-02 ] | |||||||||||||||||
|
If anyone has any questions for me, please feel free to ask. Thanks! | |||||||||||||||||
| Comment by Andrei Elkin [ 2021-04-06 ] | |||||||||||||||||
|
wlad, GeoffMontee may correct my understanding of this FR. To my reading of the case xtrabackup_binlog_info should instead contain the value of @@global.gtid_binlog_pos
of the backup donor "master". And then the slave's var could be set to it. The references to about-to-be-deprecated (see | |||||||||||||||||
| Comment by Geoff Montee (Inactive) [ 2021-04-06 ] | |||||||||||||||||
This was my original thought when I initially submitted this feature request, but I spoke with you and Kristian about that idea in My latest proposal is: 1.) Keep writing gtid_current_pos to xtrabackup_binlog_info. I don't see any reason to change this behavior. 2.) Add some option (e.g. --set-gtid-slave-pos) to control whether gtid_slave_pos is set during the prepare phase:
If this option is set, then mariadb-backup would do something like this: a.) Prepare the backup, as normal
Steps b and c sound pretty unusual, but mariadb-backup already does something similar to execute FLUSH TABLES ... FOR EXPORT when you execute the following:
When the --export option is provided, mariadb-backup bootstraps mariadbd using the prepared backup here: https://github.com/MariaDB/server/blob/mariadb-10.5.9/extra/mariabackup/xtrabackup.cc#L1752 And then it executes the SQL script defined here against the bootstrapped mariadbd process:: https://github.com/MariaDB/server/blob/mariadb-10.5.9/extra/mariabackup/xtrabackup.cc#L1726 We could use a similar technique to set gtid_slave_pos during the prepare. However, the last time I spoke to wlad about this, he said that he really disliked that mariadb-backup had to bootstrap mariadbd to perform operations like this, so I know that he probably does not want to reuse this technique for other new features. Ideally, it might be best if mariadb-backup could set gtid_slave_pos without executing SQL. The value of gtid_slave_pos is stored in mysql.gtid_slave_pos, which is almost always an InnoDB table. Can mariadb-backup safely write to InnoDB tables without executing SQL? | |||||||||||||||||
| Comment by Andrei Elkin [ 2021-04-13 ] | |||||||||||||||||
|
GeoffMontee: howdy. Sorry for superficial comment above - already 'cos gtid_binlog_pos is read-only. Now to the proper understanding, the Let us work out a plan not involving gtid_current_pos. It feels a fifth wheel which I'd love to (start) dismantling in Do you seen any issue in having both @@global.gtid_binlog_state and @@global.gtid_slave_pos in xtrabackup_binlog_info? | |||||||||||||||||
| Comment by Geoff Montee (Inactive) [ 2021-04-13 ] | |||||||||||||||||
|
Hi Elkin.
No worries. Right. gtid_binlog_state is the writable system variable that affects gtid_binlog_pos.
Right.
Currently, xtrabackup_binlog_info does not contain either gtid_binlog_state or gtid_slave_pos. It only contains gtid_current_pos, which is built from a combination of the two GTID positions. If you completely redesign how MariaDB Backup tracks GTIDs, then maybe it makes sense to store the new details in a new location that uses MariaDB branding, rather than redesigning the file format of a file that uses Percona's Xtrabackup branding. See It probably makes sense to back up gtid_binlog_pos / gtid_binlog_state, but it probably does not make sense to restore the value as-is in most cases. The discussion in I submitted this feature request, because customers had a specific use case in mind: they want to be able to build replicas using MariaDB Backup without requiring any manual steps to set the proper GTID on the new replica. Since MariaDB Backup does automatically back up the GTID position, it should also be able to automatically set the GTID position. Since the specific use case involves building replicas, I think the GTID position on the new replica needs to be set to gtid_slave_pos--not gtid_binlog_pos / gtid_binlog_state, even if you back up both gtid_binlog_pos / gtid_binlog_state and gtid_slave_pos. However, the GTID position set to gtid_slave_pos should probably be formed from the combination of gtid_binlog_pos / gtid_binlog_state and gtid_slave_pos in the backup, so that the full GTID position is taken into account. Are you proposing to implement something that would work like this?: 1.) The customer backs up their primary server:
In the new implementation:
2.) The customer prepares the backup, and provides an option to set gtid_slave_pos:
In the new implementation:
3.) The customer restores the backup to the new replica:
In the new implementation:
4.) The customer sets up replication on the new replica:
In the new implementation:
Does that sound accurate? Thanks! | |||||||||||||||||
| Comment by Andrei Elkin [ 2021-04-14 ] | |||||||||||||||||
|
GeoffMontee, wlad, salave. First to answer questions, | |||||||||||||||||
| Comment by Andrei Elkin [ 2021-04-14 ] | |||||||||||||||||
|
> Both gtid_binlog_pos / gtid_binlog_state and gtid_slave_pos would be included somewhere in the backup. So I'd rather we go with your plan, GeoffMontee. Why won't we just set the slave and binlog state on the recipient from the donor's | |||||||||||||||||
| Comment by Andrei Elkin [ 2021-04-14 ] | |||||||||||||||||
|
More to
I think they should be added to the backup configuration (xtrabackup_binlog_info) at least for flexibility. | |||||||||||||||||
| Comment by Geoff Montee (Inactive) [ 2021-04-22 ] | |||||||||||||||||
|
Hi Elkin,
If I understand correctly, this approach sounds a bit different than what I am suggesting. It sounds like you are suggesting to implement it like this: 1.) The customer backs up their primary server:
In the new implementation:
2.) The customer prepares the backup, and provides an option to set both gtid_slave_pos and gtid_binlog_state:
In the new implementation:
Unfortunately, I don't think this approach will be a viable solution for the problems reported by some customers. The problem with this approach is the same problem described by
Since the GTIDs in gtid_binlog_state will not be used for replication, this proposal does not seem to provide the solution requested by this Jira issue, which is to make it easier to configure new replication slaves from a backup of the master. Am I understanding your proposal correctly? If so, what specific use case is your proposal designed to solve?
If we want to make it easier to configure new replication slaves from a backup of the master, then I think this is the approach we should take. If the old master's GTIDs are not migrated from gtid_binlog_state to gtid_slave_pos, then even if we restore gtid_binlog_state on the new slave, those GTIDs in gtid_binlog_state will not be used for replication at all, regardless of whether you specify MASTER_USE_GTID=current_pos or MASTER_USE_GTID=slave_pos. In my opinion, it makes the most sense to migrate gtid_binlog_state to gtid_slave_pos. However, you may have other use cases in mind than I do. Thanks! | |||||||||||||||||
| Comment by Andrei Elkin [ 2021-05-06 ] | |||||||||||||||||
|
GeoffMontee, thanks for a pretty detailed reply! To clear out some questions, in I intended to set both recipient's gtid states to the same value of the current gtid pos computed as if the computation happened to the donor's side variable (that is on the donor). But it's rude actually. What if D is a slave that updated binlog locally so gained gtid:s which were not replicated. And I was not really correct on the master role safety. E.g should binlog files also be copied with the backup image/configuration, possibly not-binlogged (log-slave-updates=0) slave role GTID:s would not be found. Considering what you said and the above I still strive for the idea that you seem to support:
Let backup --prepare sets straight R.gtid_binlog_state = D.gtid_binlog_state and The new option applies to:
but not
Could you please review this. Cheers! | |||||||||||||||||
| Comment by Sergei Golubchik [ 2021-11-11 ] | |||||||||||||||||
|
GeoffMontee, I'm leaning towards the thought that it's not mariabackup job to do. mariabackup is a backup/restore tool. Its job is to back the data up and to restore it, as close as possible to the original, ideally 1:1. Intentionally modifying tables as a part of the restore (that is, making changes in mysql.gtid_slave_pos table) is contrary to what a backup/restore is. It could be a different tool or a mariabackup wrapper, like "restore a backup and prepare the slave for replication". But I think these are two different steps. First one restores a backup, getting an identical copy of the original, then one prepares it for replication, which causes the data no longer be an "identical copy of the original", so, technically, not a restored backup anymore. |