diff options
author | Monty <monty@mariadb.org> | 2021-09-15 21:21:03 +0300 |
---|---|---|
committer | Monty <monty@mariadb.org> | 2021-09-15 21:21:03 +0300 |
commit | 0d47945b58c0f12ca35f4803af9bfa8cc498f5cc (patch) | |
tree | 89133d8ae2804d3b47f789a260ee2bdc00cfa9be | |
parent | b4f24c745a42d69fca2d67ce827c30632ef4b5fc (diff) | |
download | mariadb-git-0d47945b58c0f12ca35f4803af9bfa8cc498f5cc.tar.gz |
Fixed bug in aria_chk that overwrote sort_buffer_length
This bug happens when one runs aria_chk on multiple tables. It does not
affect REPAIR TABLE.
aria_chk tries to optimize the sort buffer size to minimize memory usage
when used with small tables. The bug was that the adjusted value was
used as a base for the next table, which could cause problems.
-rw-r--r-- | include/myisamchk.h | 2 | ||||
-rw-r--r-- | storage/maria/aria_chk.c | 4 | ||||
-rw-r--r-- | storage/maria/ha_maria.cc | 8 | ||||
-rw-r--r-- | storage/maria/ma_check.c | 4 |
4 files changed, 10 insertions, 8 deletions
diff --git a/include/myisamchk.h b/include/myisamchk.h index f9a55ba467f..c494c672ec7 100644 --- a/include/myisamchk.h +++ b/include/myisamchk.h @@ -87,7 +87,7 @@ typedef struct st_handler_check_param /* Following is used to check if rows are visible */ ulonglong max_trid, max_found_trid; ulonglong not_visible_rows_found; - ulonglong sort_buffer_length; + ulonglong sort_buffer_length, orig_sort_buffer_length; ulonglong use_buffers; /* Used as param to getopt() */ size_t read_buffer_length, write_buffer_length, sort_key_blocks; time_t backup_time; /* To sign backup files */ diff --git a/storage/maria/aria_chk.c b/storage/maria/aria_chk.c index 7463adf34c1..30bb2cf0d96 100644 --- a/storage/maria/aria_chk.c +++ b/storage/maria/aria_chk.c @@ -434,8 +434,8 @@ static struct my_option my_long_options[] = ~0UL, (long) MALLOC_OVERHEAD, (long) 1L, 0}, { "sort_buffer_size", OPT_SORT_BUFFER_SIZE, "Size of sort buffer. Used by --recover", - &check_param.sort_buffer_length, - &check_param.sort_buffer_length, 0, GET_ULL, REQUIRED_ARG, + &check_param.orig_sort_buffer_length, + &check_param.orig_sort_buffer_length, 0, GET_ULL, REQUIRED_ARG, SORT_BUFFER_INIT, MIN_SORT_BUFFER, SIZE_T_MAX, MALLOC_OVERHEAD, 1L, 0}, { "sort_key_blocks", OPT_SORT_KEY_BLOCKS, "Internal buffer for sorting keys; Don't touch :)", diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index 79bebc90837..80d3d669703 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -1481,7 +1481,7 @@ int ha_maria::repair(THD * thd, HA_CHECK_OPT *check_opt) param->testflag= ((check_opt->flags & ~(T_EXTEND)) | T_SILENT | T_FORCE_CREATE | T_CALC_CHECKSUM | (check_opt->flags & T_EXTEND ? T_REP : T_REP_BY_SORT)); - param->sort_buffer_length= THDVAR(thd, sort_buffer_size); + param->orig_sort_buffer_length= THDVAR(thd, sort_buffer_size); param->backup_time= check_opt->start_time; start_records= file->state->records; old_proc_info= thd_proc_info(thd, "Checking table"); @@ -1552,7 +1552,7 @@ int ha_maria::zerofill(THD * thd, HA_CHECK_OPT *check_opt) param->thd= thd; param->op_name= "zerofill"; param->testflag= check_opt->flags | T_SILENT | T_ZEROFILL; - param->sort_buffer_length= THDVAR(thd, sort_buffer_size); + param->orig_sort_buffer_length= THDVAR(thd, sort_buffer_size); param->db_name= table->s->db.str; param->table_name= table->alias.c_ptr(); @@ -1588,7 +1588,7 @@ int ha_maria::optimize(THD * thd, HA_CHECK_OPT *check_opt) param->op_name= "optimize"; param->testflag= (check_opt->flags | T_SILENT | T_FORCE_CREATE | T_REP_BY_SORT | T_STATISTICS | T_SORT_INDEX); - param->sort_buffer_length= THDVAR(thd, sort_buffer_size); + param->orig_sort_buffer_length= THDVAR(thd, sort_buffer_size); thd_progress_init(thd, 1); if ((error= repair(thd, param, 1)) && param->retry_repair) { @@ -2056,7 +2056,7 @@ int ha_maria::enable_indexes(uint mode) } param->myf_rw &= ~MY_WAIT_IF_FULL; - param->sort_buffer_length= THDVAR(thd,sort_buffer_size); + param->orig_sort_buffer_length= THDVAR(thd,sort_buffer_size); param->stats_method= (enum_handler_stats_method)THDVAR(thd,stats_method); param->tmpdir= &mysql_tmpdir_list; if ((error= (repair(thd, param, 0) != HA_ADMIN_OK)) && param->retry_repair) diff --git a/storage/maria/ma_check.c b/storage/maria/ma_check.c index 358d563b63a..a244a9326ab 100644 --- a/storage/maria/ma_check.c +++ b/storage/maria/ma_check.c @@ -114,7 +114,7 @@ void maria_chk_init(HA_CHECK *param) param->use_buffers= PAGE_BUFFER_INIT; param->read_buffer_length=READ_BUFFER_INIT; param->write_buffer_length=READ_BUFFER_INIT; - param->sort_buffer_length=SORT_BUFFER_INIT; + param->orig_sort_buffer_length=SORT_BUFFER_INIT; param->sort_key_blocks=BUFFERS_WHEN_SORTING; param->tmpfile_createflag=O_RDWR | O_TRUNC | O_EXCL; param->myf_rw=MYF(MY_NABP | MY_WME | MY_WAIT_IF_FULL); @@ -2483,6 +2483,8 @@ static int initialize_variables_for_repair(HA_CHECK *param, tmp= (size_t) MY_MIN(sort_info->filelength, (my_off_t) (SIZE_T_MAX/10/threads)); tmp= MY_MAX(tmp * 8 * threads, (size_t) 65536); /* Some margin */ + param->sort_buffer_length= MY_MIN(param->orig_sort_buffer_length, + tmp); set_if_smaller(param->sort_buffer_length, tmp); /* Protect against too big sort buffer length */ #if SIZEOF_SIZE_T >= 8 |