Skip to content

Commit 39e7133

Browse files
committed
MDEV-37857 : Galera replication does not preserve the character set and collation associated with views, etc
In Query_log_event::do_apply_event there is comparison is used character set in event same as cached charset and if not used charset is changed. Unfortunately, it was done only if thread is replica thread. Fixed by adding condition for Galera applier thread so that comparison is done leading to charset change if event had different charset.
1 parent f1aaa75 commit 39e7133

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
connection node_2;
2+
connection node_1;
3+
drop table if exists t1;
4+
drop view if exists t1;
5+
connection node_2;
6+
SELECT @@character_set_server, @@collation_server;
7+
@@character_set_server @@collation_server
8+
latin1 latin1_swedish_ci
9+
SELECT @@character_set_client, @@collation_connection;
10+
@@character_set_client @@collation_connection
11+
latin1 latin1_swedish_ci
12+
connection node_1;
13+
SET NAMES latin1 COLLATE latin1_bin;
14+
SELECT @@character_set_server, @@collation_server;
15+
@@character_set_server @@collation_server
16+
latin1 latin1_swedish_ci
17+
SELECT @@character_set_client, @@collation_connection;
18+
@@character_set_client @@collation_connection
19+
latin1 latin1_bin
20+
create table t1 (a int);
21+
insert into t1 values (1);
22+
create view v1 as select a from t1;
23+
SHOW CREATE VIEW v1;
24+
View Create View character_set_client collation_connection
25+
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` latin1 latin1_bin
26+
SHOW CREATE TABLE t1;
27+
Table Create Table
28+
t1 CREATE TABLE `t1` (
29+
`a` int(11) DEFAULT NULL
30+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
31+
connection node_2;
32+
SHOW CREATE VIEW v1;
33+
View Create View character_set_client collation_connection
34+
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` latin1 latin1_bin
35+
SHOW CREATE TABLE t1;
36+
Table Create Table
37+
t1 CREATE TABLE `t1` (
38+
`a` int(11) DEFAULT NULL
39+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
40+
connection node_1;
41+
DROP VIEW v1;
42+
DROP TABLE t1;
43+
disconnect node_2;
44+
disconnect node_1;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--source include/galera_cluster.inc
2+
3+
--disable_warnings
4+
drop table if exists t1;
5+
drop view if exists t1;
6+
--enable_warnings
7+
8+
--connection node_2
9+
SELECT @@character_set_server, @@collation_server;
10+
SELECT @@character_set_client, @@collation_connection;
11+
--connection node_1
12+
SET NAMES latin1 COLLATE latin1_bin;
13+
SELECT @@character_set_server, @@collation_server;
14+
SELECT @@character_set_client, @@collation_connection;
15+
create table t1 (a int);
16+
insert into t1 values (1);
17+
create view v1 as select a from t1;
18+
SHOW CREATE VIEW v1;
19+
SHOW CREATE TABLE t1;
20+
21+
--connection node_2
22+
SHOW CREATE VIEW v1;
23+
SHOW CREATE TABLE t1;
24+
25+
--connection node_1
26+
DROP VIEW v1;
27+
DROP TABLE t1;
28+
29+
--source include/galera_end.inc

sql/log_event_server.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,16 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi,
20212021
if (charset_inited)
20222022
{
20232023
rpl_sql_thread_info *sql_info= thd->system_thread_info.rpl_sql_info;
2024-
if (thd->slave_thread && sql_info->cached_charset_compare(charset))
2024+
const bool applier=
2025+
#ifdef WITH_WSREP
2026+
WSREP(thd) ? thd->wsrep_applier :
2027+
#endif
2028+
false;
2029+
2030+
// Event charset should be compared for slave thread
2031+
// and applier threads
2032+
if ((thd->slave_thread || applier) &&
2033+
sql_info->cached_charset_compare(charset))
20252034
{
20262035
/* Verify that we support the charsets found in the event. */
20272036
if (!(thd->variables.character_set_client=

0 commit comments

Comments
 (0)