Skip to content

Commit 51abae5

Browse files
committed
MDEV-25923: Aria parallel repair MY_THREAD_SPECIFIC mismatch in realloc
maria_repair_parallel() clears the MY_THREAD_SPECIFIC flag for allocations since it uses different threads. But it still did one _ma_alloc_buffer() call as thread-specific which would later assert if another thread needed to extend the buffer with realloc. This patch, due to Monty, removes the MY_THREAD_SPECIFIC flag for allocations that need to realloc in different threads, and preserves it for those that are allocated/freed in the user's thread. Also fixes MDEV-33562. Reviewed-by: Monty <monty@mariadb.org> Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
1 parent 77b9b28 commit 51abae5

File tree

3 files changed

+67
-11
lines changed

3 files changed

+67
-11
lines changed

mysql-test/suite/maria/alter.result

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,29 @@ ALTER TABLE t1 DISABLE KEYS;
193193
INSERT INTO t1 VALUES (1, 'Nine chars or more');
194194
ALTER TABLE t1 ENABLE KEYS;
195195
DROP TABLE t1;
196+
#
197+
# MDEV-25923 Memory not freed or Assertion `old_flags == ((my_flags &
198+
# 0x10000U) ? 1 : 0)' failed in my_realloc upon ALTER on Aria table
199+
# with GIS column
200+
#
201+
CREATE TABLE t1 (pk INT PRIMARY KEY, a POINT DEFAULT ST_GEOMFROMTEXT('Point(1 1)')) ENGINE=Aria;
202+
INSERT INTO t1 (pk) SELECT seq FROM seq_1_to_100;
203+
SET @old_threads= @@SESSION.aria_repair_threads;
204+
SET SESSION aria_repair_threads= 2;
205+
ALTER TABLE t1 ROW_FORMAT=DYNAMIC;
206+
DROP TABLE t1;
207+
#
208+
# MDEV-33562: Assertion `(old_flags & 1) == ((my_flags & 0x10000U) ?
209+
# 1 : 0)' failed in my_realloc from sort_get_next_record on INSERT
210+
#
211+
SET @old_mode= @@SESSION.sql_mode;
212+
SET sql_mode='';
213+
CREATE TEMPORARY TABLE t (b TEXT, INDEX s(b(300))) ROW_FORMAT=DYNAMIC ENGINE=Aria;
214+
INSERT INTO t VALUES (REPEAT ('a',10000000));
215+
Warnings:
216+
Warning 1265 Data truncated for column 'b' at row 1
217+
CREATE TABLE ti LIKE t;
218+
INSERT INTO ti SELECT * FROM t;
219+
DROP TABLE t, ti;
220+
SET SESSION aria_repair_threads= @old_threads;
221+
SET SESSION sql_mode= @old_mode;

mysql-test/suite/maria/alter.test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,31 @@ ALTER TABLE t1 DISABLE KEYS;
203203
INSERT INTO t1 VALUES (1, 'Nine chars or more');
204204
ALTER TABLE t1 ENABLE KEYS;
205205
DROP TABLE t1;
206+
207+
--echo #
208+
--echo # MDEV-25923 Memory not freed or Assertion `old_flags == ((my_flags &
209+
--echo # 0x10000U) ? 1 : 0)' failed in my_realloc upon ALTER on Aria table
210+
--echo # with GIS column
211+
--echo #
212+
213+
CREATE TABLE t1 (pk INT PRIMARY KEY, a POINT DEFAULT ST_GEOMFROMTEXT('Point(1 1)')) ENGINE=Aria;
214+
INSERT INTO t1 (pk) SELECT seq FROM seq_1_to_100;
215+
SET @old_threads= @@SESSION.aria_repair_threads;
216+
SET SESSION aria_repair_threads= 2;
217+
ALTER TABLE t1 ROW_FORMAT=DYNAMIC;
218+
DROP TABLE t1;
219+
220+
--echo #
221+
--echo # MDEV-33562: Assertion `(old_flags & 1) == ((my_flags & 0x10000U) ?
222+
--echo # 1 : 0)' failed in my_realloc from sort_get_next_record on INSERT
223+
--echo #
224+
225+
SET @old_mode= @@SESSION.sql_mode;
226+
SET sql_mode='';
227+
CREATE TEMPORARY TABLE t (b TEXT, INDEX s(b(300))) ROW_FORMAT=DYNAMIC ENGINE=Aria;
228+
INSERT INTO t VALUES (REPEAT ('a',10000000));
229+
CREATE TABLE ti LIKE t;
230+
INSERT INTO ti SELECT * FROM t;
231+
DROP TABLE t, ti;
232+
SET SESSION aria_repair_threads= @old_threads;
233+
SET SESSION sql_mode= @old_mode;

storage/maria/ma_check.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ void maria_chk_init(HA_CHECK *param)
125125
param->max_stage= 1;
126126
param->stack_end_ptr= &my_thread_var->stack_ends_here;
127127
param->max_allowed_lsn= (LSN) ~0ULL;
128+
/* Flag when initializing buffers possible used by parallel repair threads */
128129
param->malloc_flags= MY_THREAD_SPECIFIC;
129130
}
130131

@@ -2130,7 +2131,7 @@ int maria_chk_data_link(HA_CHECK *param, MARIA_HA *info, my_bool extend)
21302131

21312132
if (!(record= (uchar*) my_malloc(PSI_INSTRUMENT_ME,
21322133
share->base.default_rec_buff_size,
2133-
MYF(param->malloc_flags))))
2134+
MYF(MY_THREAD_SPECIFIC))))
21342135
{
21352136
_ma_check_print_error(param,"Not enough memory for record");
21362137
DBUG_RETURN(-1);
@@ -2766,10 +2767,10 @@ int maria_repair(HA_CHECK *param, register MARIA_HA *info,
27662767
if (!(sort_param.record=
27672768
(uchar *) my_malloc(PSI_INSTRUMENT_ME, (uint)
27682769
share->base.default_rec_buff_size,
2769-
MYF(param->malloc_flags))) ||
2770+
MYF(MY_THREAD_SPECIFIC))) ||
27702771
_ma_alloc_buffer(&sort_param.rec_buff, &sort_param.rec_buff_size,
27712772
share->base.default_rec_buff_size,
2772-
MYF(param->malloc_flags)))
2773+
MYF(MY_THREAD_SPECIFIC)))
27732774
{
27742775
_ma_check_print_error(param, "Not enough memory for extra record");
27752776
goto err;
@@ -3721,7 +3722,7 @@ int maria_filecopy(HA_CHECK *param, File to,File from,my_off_t start,
37213722

37223723
buff_length=(ulong) MY_MIN(param->write_buffer_length,length);
37233724
if (!(buff=my_malloc(PSI_INSTRUMENT_ME, buff_length,
3724-
MYF(param->malloc_flags))))
3725+
MYF(MY_THREAD_SPECIFIC))))
37253726
{
37263727
buff=tmp_buff; buff_length=IO_SIZE;
37273728
}
@@ -3867,10 +3868,10 @@ int maria_repair_by_sort(HA_CHECK *param, register MARIA_HA *info,
38673868
if (!(sort_param.record=
38683869
(uchar*) my_malloc(PSI_INSTRUMENT_ME,
38693870
(size_t) share->base.default_rec_buff_size,
3870-
MYF(param->malloc_flags))) ||
3871+
MYF(MY_THREAD_SPECIFIC))) ||
38713872
_ma_alloc_buffer(&sort_param.rec_buff, &sort_param.rec_buff_size,
38723873
share->base.default_rec_buff_size,
3873-
MYF(param->malloc_flags)))
3874+
MYF(MY_THREAD_SPECIFIC)))
38743875
{
38753876
_ma_check_print_error(param, "Not enough memory for extra record");
38763877
goto err;
@@ -3889,7 +3890,7 @@ int maria_repair_by_sort(HA_CHECK *param, register MARIA_HA *info,
38893890
sort_param.wordlist=NULL;
38903891
init_alloc_root(PSI_INSTRUMENT_ME, &sort_param.wordroot,
38913892
FTPARSER_MEMROOT_ALLOC_SIZE, 0,
3892-
MYF(param->malloc_flags));
3893+
MYF(MY_THREAD_SPECIFIC));
38933894

38943895
sort_param.key_cmp=sort_key_cmp;
38953896
sort_param.lock_in_memory=maria_lock_memory;
@@ -4457,7 +4458,7 @@ int maria_repair_parallel(HA_CHECK *param, register MARIA_HA *info,
44574458
if (!(sort_param=(MARIA_SORT_PARAM *)
44584459
my_malloc(PSI_INSTRUMENT_ME, (uint) share->base.keys *
44594460
(sizeof(MARIA_SORT_PARAM) + share->base.pack_reclength),
4460-
MYF(MY_ZEROFILL | param->malloc_flags))))
4461+
MYF(MY_ZEROFILL | MY_THREAD_SPECIFIC))))
44614462
{
44624463
_ma_check_print_error(param,"Not enough memory for key!");
44634464
goto err;
@@ -4515,9 +4516,10 @@ int maria_repair_parallel(HA_CHECK *param, register MARIA_HA *info,
45154516

45164517
sort_param[i].record= (((uchar *)(sort_param+share->base.keys))+
45174518
(share->base.pack_reclength * i));
4519+
/* These buffers are per thread */
45184520
if (_ma_alloc_buffer(&sort_param[i].rec_buff, &sort_param[i].rec_buff_size,
45194521
share->base.default_rec_buff_size,
4520-
MYF(param->malloc_flags)))
4522+
MYF(0)))
45214523
{
45224524
_ma_check_print_error(param,"Not enough memory!");
45234525
goto err;
@@ -4546,7 +4548,7 @@ int maria_repair_parallel(HA_CHECK *param, register MARIA_HA *info,
45464548
sort_param[i].key_length+=ft_max_word_len_for_sort-HA_FT_MAXBYTELEN;
45474549
init_alloc_root(PSI_INSTRUMENT_ME, &sort_param[i].wordroot,
45484550
FTPARSER_MEMROOT_ALLOC_SIZE, 0,
4549-
MYF(param->malloc_flags));
4551+
MYF(MY_THREAD_SPECIFIC));
45504552
}
45514553
}
45524554
sort_info.total_keys=i;
@@ -6105,7 +6107,7 @@ static MA_SORT_KEY_BLOCKS *alloc_key_blocks(HA_CHECK *param, uint blocks,
61056107
if (!(block= (MA_SORT_KEY_BLOCKS*)
61066108
my_malloc(PSI_INSTRUMENT_ME,
61076109
(sizeof(MA_SORT_KEY_BLOCKS)+buffer_length+IO_SIZE)*blocks,
6108-
MYF(param->malloc_flags))))
6110+
MYF(MY_THREAD_SPECIFIC))))
61096111
{
61106112
_ma_check_print_error(param,"Not enough memory for sort-key-blocks");
61116113
return(0);

0 commit comments

Comments
 (0)