From 12cad0c3468d734e041d4ef0cd5a26d2a28606fc Mon Sep 17 00:00:00 2001
From: Daniele Sciascia <daniele.sciascia@galeracluster.com>
Date: Tue, 25 Jan 2022 16:39:13 +0100
Subject: [PATCH] MDEV-27615 Assertion `server_id.is_undefined() == false'
 failed
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add test case that reproduces the issue and update wsrep-lib submodule
to include the fix.

Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
---
 .../suite/galera_sr/r/MDEV-27615.result       | 27 +++++++
 mysql-test/suite/galera_sr/t/MDEV-27615.test  | 72 +++++++++++++++++++
 wsrep-lib                                     |  2 +-
 3 files changed, 100 insertions(+), 1 deletion(-)
 create mode 100644 mysql-test/suite/galera_sr/r/MDEV-27615.result
 create mode 100644 mysql-test/suite/galera_sr/t/MDEV-27615.test

diff --git a/mysql-test/suite/galera_sr/r/MDEV-27615.result b/mysql-test/suite/galera_sr/r/MDEV-27615.result
new file mode 100644
index 00000000000..a3475811285
--- /dev/null
+++ b/mysql-test/suite/galera_sr/r/MDEV-27615.result
@@ -0,0 +1,27 @@
+connection node_2;
+connection node_1;
+connection node_1;
+connection node_2;
+connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2;
+connection node_2;
+CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) Engine=InnoDB;
+SET DEBUG_SYNC='wsrep_before_fragment_certification SIGNAL before_fragment WAIT_FOR continue';
+SET SESSION wsrep_trx_fragment_size=1;
+START TRANSACTION;
+INSERT INTO t1 VALUES (1);;
+connection node_2a;
+SET SESSION wsrep_sync_wait = 0;
+SET DEBUG_SYNC='now WAIT_FOR before_fragment';
+SET GLOBAL wsrep_cluster_address = '';
+SET DEBUG_SYNC = 'now SIGNAL continue';
+connection node_2;
+ERROR HY000: Lost connection to MySQL server during query
+connection node_2a;
+SELECT * FROM mysql.wsrep_streaming_log;
+node_uuid	trx_id	seqno	flags	frag
+SELECT * FROM t1;
+f1
+DROP TABLE t1;
+SET DEBUG_SYNC = 'RESET';
+disconnect node_2;
+connect node_2, 127.0.0.1, root, , test, $NODE_MYPORT_2;
diff --git a/mysql-test/suite/galera_sr/t/MDEV-27615.test b/mysql-test/suite/galera_sr/t/MDEV-27615.test
new file mode 100644
index 00000000000..121a85fb20c
--- /dev/null
+++ b/mysql-test/suite/galera_sr/t/MDEV-27615.test
@@ -0,0 +1,72 @@
+#
+# MDEV-27615 - Assertion `server_id.is_undefined() == false'
+# failed in wsrep::transaction::certify_fragment()
+#
+
+--source include/galera_cluster.inc
+--source include/have_debug_sync.inc
+
+--let $node_1=node_1
+--let $node_2=node_2
+--source suite/galera/include/auto_increment_offset_save.inc
+
+--connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2
+
+--connection node_2
+CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) Engine=InnoDB;
+
+#
+# Set debug sync point right before the assert
+#
+SET DEBUG_SYNC='wsrep_before_fragment_certification SIGNAL before_fragment WAIT_FOR continue';
+
+SET SESSION wsrep_trx_fragment_size=1;
+START TRANSACTION;
+--send INSERT INTO t1 VALUES (1);
+
+
+#
+# Disconnect node_2 from cluster
+#
+--connection node_2a
+SET SESSION wsrep_sync_wait = 0;
+--let $node_2_cluster_address = `SELECT @@wsrep_cluster_address`
+SET DEBUG_SYNC='now WAIT_FOR before_fragment';
+SET GLOBAL wsrep_cluster_address = '';
+
+--let $wait_condition = SELECT VARIABLE_VALUE = 'Disconnected' FROM information_schema.global_status WHERE VARIABLE_NAME = 'wsrep_cluster_status';
+--source include/wait_condition.inc
+SET DEBUG_SYNC = 'now SIGNAL continue';
+
+
+#
+# Disconnect causes connection to node_2 to be closed
+#
+--connection node_2
+--error 2013 # CR_SERVER_LOST
+--reap
+
+
+#
+# Reconnect node 2
+#
+--connection node_2a
+--disable_query_log
+--eval SET GLOBAL wsrep_cluster_address = '$node_2_cluster_address';
+--enable_query_log
+--source include/wait_wsrep_ready.inc
+
+#
+# Expect the transaction to be rolled back and cleanup
+#
+SELECT * FROM mysql.wsrep_streaming_log;
+SELECT * FROM t1;
+
+DROP TABLE t1;
+SET DEBUG_SYNC = 'RESET';
+
+--disconnect node_2
+--connect node_2, 127.0.0.1, root, , test, $NODE_MYPORT_2
+
+
+--source suite/galera/include/auto_increment_offset_restore.inc
diff --git a/wsrep-lib b/wsrep-lib
index da5098b622b..edd141127c1 160000
--- a/wsrep-lib
+++ b/wsrep-lib
@@ -1 +1 @@
-Subproject commit da5098b622bc6f92c9265bacf4c1168fd69b38b5
+Subproject commit edd141127c11d78ef073f9f3ca61708821f20b32