From 82ebc349fab662d65366fa5958669d653958eaf8 Mon Sep 17 00:00:00 2001 From: Mustafa Kemal Gilor Date: Mon, 26 Sep 2022 13:41:09 +0300 Subject: [PATCH] mysqldump: add --set-gtid-purged=COMMENTED to mysqldump command The backup file taken from a charm-managed mysql instance contains "@@GLOBAL.GTID_PURGED" variable at the beginning, which causes restore operation to fail with the following message: "Cannot update GTID_PURGED with the Group Replication plugin running". The workaround for this issue is to supply "--set-gtid-purged=OFF" to command, which omits the "GTID_PURGED" from the mysqldump output. This patch fixes the issue by adding "--set-gtid-purged=COMMENTED" to mysqldump command, which causes mysqldump to emit the GTID_PURGED variable as a commented out line. In this way, we don't lose the GTID_PURGED variable information which may be needed in some scenarios and can be un-commented out before restoring if needed. Closes-bug: 1989975 Change-Id: Ie3b71a60e4c7afda48114a53cce9cf713b933d71 --- src/lib/charm/openstack/mysql_innodb_cluster.py | 3 ++- unit_tests/test_lib_charm_openstack_mysql_innodb_cluster.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/charm/openstack/mysql_innodb_cluster.py b/src/lib/charm/openstack/mysql_innodb_cluster.py index df886d8..2531c75 100644 --- a/src/lib/charm/openstack/mysql_innodb_cluster.py +++ b/src/lib/charm/openstack/mysql_innodb_cluster.py @@ -1756,7 +1756,8 @@ class MySQLInnoDBClusterCharm(charms_openstack.charm.OpenStackCharm): bucmd = ["/usr/bin/mysqldump", "-u", _user, "--triggers", "--routines", "--events", - "--ignore-table=mysql.event"] + "--ignore-table=mysql.event", + "--set-gtid-purged=COMMENTED"] if databases is not None: _filename = os.path.join( backup_dir, diff --git a/unit_tests/test_lib_charm_openstack_mysql_innodb_cluster.py b/unit_tests/test_lib_charm_openstack_mysql_innodb_cluster.py index 5fc3b89..5a90d97 100644 --- a/unit_tests/test_lib_charm_openstack_mysql_innodb_cluster.py +++ b/unit_tests/test_lib_charm_openstack_mysql_innodb_cluster.py @@ -1502,6 +1502,7 @@ class TestMySQLInnoDBClusterCharm(test_utils.PatchHelper): mock.call( ["/usr/bin/mysqldump", "-u", "root", "--triggers", "--routines", "--events", "--ignore-table=mysql.event", + "--set-gtid-purged=COMMENTED", "--result-file", _filename, "--all-databases"]), mock.call(["/usr/bin/gzip", _filename])] @@ -1517,6 +1518,7 @@ class TestMySQLInnoDBClusterCharm(test_utils.PatchHelper): mock.call( ["/usr/bin/mysqldump", "-u", "root", "-ppass", "--triggers", "--routines", "--events", "--ignore-table=mysql.event", + "--set-gtid-purged=COMMENTED", "--result-file", _filename, "--databases", _dbs]), mock.call(["/usr/bin/gzip", _filename])] self.assertEqual(midbc.mysqldump(_path, databases=_dbs), @@ -1531,6 +1533,7 @@ class TestMySQLInnoDBClusterCharm(test_utils.PatchHelper): mock.call( ["/usr/bin/mysqldump", "-u", "root", "-ppass", "--triggers", "--routines", "--events", "--ignore-table=mysql.event", + "--set-gtid-purged=COMMENTED", "--result-file", _filename, "--databases"].extend( _dbs.split(","))), mock.call(["/usr/bin/gzip", _filename])]