From eb26e20df563adc928bb64df112832d75d7795a0 Mon Sep 17 00:00:00 2001
From: mkaruza <mario.karuza@galeracluster.com>
Date: Mon, 26 Jul 2021 08:46:36 +0200
Subject: [PATCH] MDEV-22421 Galera assertion !wsrep_has_changes(thd) ||
 (thd->lex->sql_command == SQLCOM_CREATE_TABLE &&
 !thd->is_current_stmt_binlog_format_row())
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Updates to transaction registry table shouldn't be replicated in
cluster so there is no need to append wsrep keys.

Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
---
 mysql-test/suite/galera/r/MDEV-22421.result |  7 +++++++
 mysql-test/suite/galera/t/MDEV-22421.test   | 12 ++++++++++++
 sql/handler.cc                              | 14 ++++++++++++++
 3 files changed, 33 insertions(+)
 create mode 100644 mysql-test/suite/galera/r/MDEV-22421.result
 create mode 100644 mysql-test/suite/galera/t/MDEV-22421.test

diff --git a/mysql-test/suite/galera/r/MDEV-22421.result b/mysql-test/suite/galera/r/MDEV-22421.result
new file mode 100644
index 00000000000..33dc3e449ae
--- /dev/null
+++ b/mysql-test/suite/galera/r/MDEV-22421.result
@@ -0,0 +1,7 @@
+connection node_2;
+connection node_1;
+SET @@local.sql_mode='no_field_options';
+CREATE TABLE t1 (f1 INT, ROW_START BIGINT UNSIGNED AS ROW START INVISIBLE, ROW_END BIGINT UNSIGNED AS ROW END INVISIBLE, PERIOD FOR SYSTEM_TIME(ROW_START, ROW_END)) WITH SYSTEM VERSIONING ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+UPDATE t1 SET f1 = 1 WHERE f1 = 1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/galera/t/MDEV-22421.test b/mysql-test/suite/galera/t/MDEV-22421.test
new file mode 100644
index 00000000000..369e56384a0
--- /dev/null
+++ b/mysql-test/suite/galera/t/MDEV-22421.test
@@ -0,0 +1,12 @@
+#
+# Tables with system versioning should not append keys to wsrep.
+#
+
+--source include/galera_cluster.inc
+--source include/have_innodb.inc
+
+SET @@local.sql_mode='no_field_options';
+CREATE TABLE t1 (f1 INT, ROW_START BIGINT UNSIGNED AS ROW START INVISIBLE, ROW_END BIGINT UNSIGNED AS ROW END INVISIBLE, PERIOD FOR SYSTEM_TIME(ROW_START, ROW_END)) WITH SYSTEM VERSIONING ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+UPDATE t1 SET f1 = 1 WHERE f1 = 1;
+DROP TABLE t1;
diff --git a/sql/handler.cc b/sql/handler.cc
index 99ec0f01320..6b8c39cb0c4 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -1558,13 +1558,27 @@ int ha_commit_trans(THD *thd, bool all)
         goto err;
       }
       DBUG_ASSERT(trx_start_id);
+#ifdef WITH_WSREP
+      bool saved_wsrep_on= thd->variables.wsrep_on;
+      thd->variables.wsrep_on= false;
+#endif
       TR_table trt(thd, true);
       if (trt.update(trx_start_id, trx_end_id))
+#ifdef WITH_WSREP
+      {
+        thd->variables.wsrep_on= saved_wsrep_on;
+#endif
         goto err;
+#ifdef WITH_WSREP
+      }
+#endif
       // Here, the call will not commit inside InnoDB. It is only working
       // around closing thd->transaction.stmt open by TR_table::open().
       if (all)
         commit_one_phase_2(thd, false, &thd->transaction.stmt, false);
+#ifdef WITH_WSREP
+      thd->variables.wsrep_on= saved_wsrep_on;
+#endif
     }
   }
 #endif