Skip to content

Commit

Permalink
MDEV-24978 crash with transaction on table with no PK and long fullte…
Browse files Browse the repository at this point in the history
…xt column

If a table has no unique indexes, write set key information will be collected on all columns in the table.
The write set key information has space only for max 3500 bytes for individual column, and if a varchar colummn of such non-primary key table is longer than
 this limit, currently a crash follows.
The fix in this commit, is to truncate key values extracted from such long varhar columns to max 3500 bytes.
This may potentially lead to false positive certification failures for transactions, which operate on separate cluster nodes, and update/insert/delete table rows, which differ only in the part of such long columns after 3500 bytes border.

Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
  • Loading branch information
sjaakola authored and Jan Lindström committed Sep 30, 2021
1 parent b2a5e0f commit d5a15f0
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 24 deletions.
56 changes: 56 additions & 0 deletions mysql-test/suite/galera/r/galera_fulltext.result
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,59 @@ COUNT(f1) = 1000
1
DROP TABLE t1;
DROP TABLE ten;
connection node_1;
SET @value=REPEAT (1,5001);
CREATE TABLE t (a VARCHAR(5000),FULLTEXT (a)) engine=innodb;
INSERT IGNORE INTO t VALUES(@value);
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
SELECT COUNT(*) FROM t;
COUNT(*)
1
connection node_2;
SELECT COUNT(*) FROM t;
COUNT(*)
1
connection node_1;
DROP TABLE t;
CREATE TABLE t (a VARCHAR(5000)) engine=innodb;
INSERT IGNORE INTO t VALUES(@value);
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
SELECT COUNT(*) FROM t;
COUNT(*)
1
connection node_2;
SELECT COUNT(*) FROM t;
COUNT(*)
1
connection node_1;
DROP TABLE t;
connection node_1;
SET @value=REPEAT (1,5001);
CREATE TABLE t (a VARCHAR(5000),FULLTEXT (a)) engine=innodb DEFAULT CHARSET=utf8;
INSERT IGNORE INTO t VALUES(@value);
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
SELECT COUNT(*) FROM t;
COUNT(*)
1
connection node_2;
SELECT COUNT(*) FROM t;
COUNT(*)
1
connection node_1;
DROP TABLE t;
CREATE TABLE t (a VARCHAR(5000)) engine=innodb DEFAULT CHARSET=utf8;
INSERT IGNORE INTO t VALUES(@value);
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
SELECT COUNT(*) FROM t;
COUNT(*)
1
connection node_2;
SELECT COUNT(*) FROM t;
COUNT(*)
1
connection node_1;
DROP TABLE t;
64 changes: 43 additions & 21 deletions mysql-test/suite/galera/t/galera_fulltext.test
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,50 @@ SELECT COUNT(f1) = 1000 FROM t1 WHERE MATCH(f1) AGAINST ('abcdefjhk');

DROP TABLE t1;
DROP TABLE ten;

#
# Case 2: UTF-8
# TODO: MDEV-24978
#
#--connection node_1
#SET @value=REPEAT (1,5001);
#CREATE TABLE t (a VARCHAR(5000),FULLTEXT (a)) engine=innodb DEFAULT CHARSET=utf8;
#INSERT IGNORE INTO t VALUES(@value);
#SELECT COUNT(*) FROM t;
# MDEV-24978 : SIGABRT in __libc_message
#
#--connection node_2
#SELECT COUNT(*) FROM t;
#
#--connection node_1
#DROP TABLE t;
#CREATE TABLE t (a VARCHAR(5000)) engine=innodb DEFAULT CHARSET=utf8;
#INSERT IGNORE INTO t VALUES(@value);
#SELECT COUNT(*) FROM t;
--connection node_1
SET @value=REPEAT (1,5001);
CREATE TABLE t (a VARCHAR(5000),FULLTEXT (a)) engine=innodb;
INSERT IGNORE INTO t VALUES(@value);
SELECT COUNT(*) FROM t;

--connection node_2
SELECT COUNT(*) FROM t;

--connection node_1
DROP TABLE t;
CREATE TABLE t (a VARCHAR(5000)) engine=innodb;
INSERT IGNORE INTO t VALUES(@value);
SELECT COUNT(*) FROM t;

--connection node_2
SELECT COUNT(*) FROM t;

--connection node_1
DROP TABLE t;

#
#--connection node_2
#SELECT COUNT(*) FROM t;
# Case 2: UTF-8
#
#--connection node_1
#DROP TABLE t;
--connection node_1
SET @value=REPEAT (1,5001);
CREATE TABLE t (a VARCHAR(5000),FULLTEXT (a)) engine=innodb DEFAULT CHARSET=utf8;
INSERT IGNORE INTO t VALUES(@value);
SELECT COUNT(*) FROM t;

--connection node_2
SELECT COUNT(*) FROM t;

--connection node_1
DROP TABLE t;
CREATE TABLE t (a VARCHAR(5000)) engine=innodb DEFAULT CHARSET=utf8;
INSERT IGNORE INTO t VALUES(@value);
SELECT COUNT(*) FROM t;

--connection node_2
SELECT COUNT(*) FROM t;

--connection node_1
DROP TABLE t;
10 changes: 7 additions & 3 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7218,10 +7218,14 @@ wsrep_store_key_val_for_row(

/* In a column prefix index, we may need to truncate
the stored value: */

if (true_len > key_len) {
true_len = key_len;
}
/* cannot exceed max column lenght either, we may need to truncate
the stored value: */
if (true_len > sizeof(sorted)) {
true_len = sizeof(sorted);
}

memcpy(sorted, data, true_len);
true_len = wsrep_innobase_mysql_sort(
Expand All @@ -7234,8 +7238,8 @@ wsrep_store_key_val_for_row(
actual data. The rest of the space was reset to zero
in the bzero() call above. */
if (true_len > buff_space) {
fprintf (stderr,
"WSREP: key truncated: %s\n",
WSREP_DEBUG (
"write set key truncated for: %s\n",
wsrep_thd_query(thd));
true_len = buff_space;
}
Expand Down

0 comments on commit d5a15f0

Please sign in to comment.