maria_repair_parallel() clears the MY_THREAD_SPECIFIC flag for allocations since it uses different threads. But it does so too late, after already allocating a couple buffers as thread-specific. This caused assertions when such buffer was later re-allocated from a different thread. Also fixes MDEV-33562. Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org> --- mysql-test/suite/maria/alter.result | 26 ++++++++++++++++++++++++++ mysql-test/suite/maria/alter.test | 28 ++++++++++++++++++++++++++++ storage/maria/ma_check.c | 14 +++++++------- 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/mysql-test/suite/maria/alter.result b/mysql-test/suite/maria/alter.result index cc035426745..17164343163 100644 --- a/mysql-test/suite/maria/alter.result +++ b/mysql-test/suite/maria/alter.result @@ -193,3 +193,29 @@ ALTER TABLE t1 DISABLE KEYS; INSERT INTO t1 VALUES (1, 'Nine chars or more'); ALTER TABLE t1 ENABLE KEYS; DROP TABLE t1; +# +# MDEV-25923 Memory not freed or Assertion `old_flags == ((my_flags & +# 0x10000U) ? 1 : 0)' failed in my_realloc upon ALTER on Aria table +# with GIS column +# +CREATE TABLE t1 (pk INT PRIMARY KEY, a POINT DEFAULT ST_GEOMFROMTEXT('Point(1 1)')) ENGINE=Aria; +INSERT INTO t1 (pk) SELECT seq FROM seq_1_to_100; +SET @old_threads= @@SESSION.aria_repair_threads; +SET SESSION aria_repair_threads= 2; +ALTER TABLE t1 ROW_FORMAT=DYNAMIC; +DROP TABLE t1; +# +# MDEV-33562: Assertion `(old_flags & 1) == ((my_flags & 0x10000U) ? +# 1 : 0)' failed in my_realloc from sort_get_next_record on INSERT +# +SET @old_mode= @@SESSION.sql_mode; +SET sql_mode=''; +CREATE TEMPORARY TABLE t (b TEXT, INDEX s(b(300))) ROW_FORMAT=DYNAMIC ENGINE=Aria; +INSERT INTO t VALUES (REPEAT ('a',10000000)); +Warnings: +Warning 1265 Data truncated for column 'b' at row 1 +CREATE TABLE ti LIKE t; +INSERT INTO ti SELECT * FROM t; +DROP TABLE t, ti; +SET SESSION aria_repair_threads= @old_threads; +SET SESSION sql_mode= @old_mode; diff --git a/mysql-test/suite/maria/alter.test b/mysql-test/suite/maria/alter.test index 525cd80f3d9..a68b5f2e0d7 100644 --- a/mysql-test/suite/maria/alter.test +++ b/mysql-test/suite/maria/alter.test @@ -203,3 +203,31 @@ ALTER TABLE t1 DISABLE KEYS; INSERT INTO t1 VALUES (1, 'Nine chars or more'); ALTER TABLE t1 ENABLE KEYS; DROP TABLE t1; + +--echo # +--echo # MDEV-25923 Memory not freed or Assertion `old_flags == ((my_flags & +--echo # 0x10000U) ? 1 : 0)' failed in my_realloc upon ALTER on Aria table +--echo # with GIS column +--echo # + +CREATE TABLE t1 (pk INT PRIMARY KEY, a POINT DEFAULT ST_GEOMFROMTEXT('Point(1 1)')) ENGINE=Aria; +INSERT INTO t1 (pk) SELECT seq FROM seq_1_to_100; +SET @old_threads= @@SESSION.aria_repair_threads; +SET SESSION aria_repair_threads= 2; +ALTER TABLE t1 ROW_FORMAT=DYNAMIC; +DROP TABLE t1; + +--echo # +--echo # MDEV-33562: Assertion `(old_flags & 1) == ((my_flags & 0x10000U) ? +--echo # 1 : 0)' failed in my_realloc from sort_get_next_record on INSERT +--echo # + +SET @old_mode= @@SESSION.sql_mode; +SET sql_mode=''; +CREATE TEMPORARY TABLE t (b TEXT, INDEX s(b(300))) ROW_FORMAT=DYNAMIC ENGINE=Aria; +INSERT INTO t VALUES (REPEAT ('a',10000000)); +CREATE TABLE ti LIKE t; +INSERT INTO ti SELECT * FROM t; +DROP TABLE t, ti; +SET SESSION aria_repair_threads= @old_threads; +SET SESSION sql_mode= @old_mode; diff --git a/storage/maria/ma_check.c b/storage/maria/ma_check.c index 1d41fb92947..9a6cca6e409 100644 --- a/storage/maria/ma_check.c +++ b/storage/maria/ma_check.c @@ -4336,6 +4336,13 @@ int maria_repair_parallel(HA_CHECK *param, register MARIA_HA *info, printf("Data records: %s\n", llstr(start_records, llbuff)); } + /* + We cannot mark future memory allocations as thread specific when + doing parallel repair as we don't have a THD for each thread. Sharing the + same THD this would requre mutex locks around mallocs/reallocs to ensure + that two threads does not use the same THD at once. + */ + param->malloc_flags= 0; bzero(&new_data_cache, sizeof(new_data_cache)); if (initialize_variables_for_repair(param, &sort_info, &tmp_sort_param, info, rep_quick, &backup_share)) @@ -4587,13 +4594,6 @@ int maria_repair_parallel(HA_CHECK *param, register MARIA_HA *info, (void) pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED); (void) my_setstacksize(&thr_attr, (size_t)my_thread_stack_size); - /* - We cannot mark future memory allocations as thread specific when - doing parallel repair as we don't have a THD for each thread. Sharing the - same THD this would requre mutex locks around mallocs/reallocs to ensure - that two threads does not use the same THD at once. - */ - param->malloc_flags= 0; for (i=0 ; i < sort_info.total_keys ; i++) { /* -- 2.30.2