diff options
author | Monty <monty@mariadb.org> | 2017-05-17 00:34:48 +0300 |
---|---|---|
committer | Monty <monty@mariadb.org> | 2017-05-17 00:34:48 +0300 |
commit | 6378c95ee07cccc2f2187b2caddc4496e14827d9 (patch) | |
tree | 1e7b9066e15288e3471f0c800e5dda820d3d0daf /storage | |
parent | 314350a722e65081472113c53657ad239f3bef72 (diff) | |
download | mariadb-git-6378c95ee07cccc2f2187b2caddc4496e14827d9.tar.gz |
Fix that end_bulk_insert() doesn't write to to-be-deleted files
This affected mainly MyISAM and Aria engines.
Also fixed that end_bulk_insert() detects errors from
internal mi_end_bulk_insert() and ma_end_bulk_insert()
- delete_tree() and delete_tree_element() now has an
extra argument that marks if future calls to
tree->free should be ignored.
- tree->free changed to function returning int, to be
able to signal errors.
- Restored deleting flag in MyISAM that was accidently
disabled in mi_extra(PREPARE_FOR_DROP)
Diffstat (limited to 'storage')
-rw-r--r-- | storage/heap/hp_clear.c | 2 | ||||
-rw-r--r-- | storage/maria/ha_maria.cc | 33 | ||||
-rw-r--r-- | storage/maria/ma_ft_boolean_search.c | 2 | ||||
-rw-r--r-- | storage/maria/ma_ft_nlq_search.c | 4 | ||||
-rw-r--r-- | storage/maria/ma_ft_parser.c | 4 | ||||
-rw-r--r-- | storage/maria/ma_write.c | 13 | ||||
-rw-r--r-- | storage/maria/maria_pack.c | 8 | ||||
-rw-r--r-- | storage/myisam/ft_boolean_search.c | 2 | ||||
-rw-r--r-- | storage/myisam/ft_nlq_search.c | 4 | ||||
-rw-r--r-- | storage/myisam/ft_parser.c | 4 | ||||
-rw-r--r-- | storage/myisam/ft_stopwords.c | 7 | ||||
-rw-r--r-- | storage/myisam/ha_myisam.cc | 28 | ||||
-rw-r--r-- | storage/myisam/mi_extra.c | 2 | ||||
-rw-r--r-- | storage/myisam/mi_write.c | 11 | ||||
-rw-r--r-- | storage/myisam/myisamlog.c | 4 | ||||
-rw-r--r-- | storage/myisam/myisampack.c | 8 |
16 files changed, 86 insertions, 50 deletions
diff --git a/storage/heap/hp_clear.c b/storage/heap/hp_clear.c index 2b1502e6475..b940fd87264 100644 --- a/storage/heap/hp_clear.c +++ b/storage/heap/hp_clear.c @@ -91,7 +91,7 @@ void hp_clear_keys(HP_SHARE *info) HP_KEYDEF *keyinfo = info->keydef + key; if (keyinfo->algorithm == HA_KEY_ALG_BTREE) { - delete_tree(&keyinfo->rb_tree); + delete_tree(&keyinfo->rb_tree, 0); } else { diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index 548c4a2112e..9d258982fdc 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -2207,14 +2207,23 @@ void ha_maria::start_bulk_insert(ha_rows rows, uint flags) int ha_maria::end_bulk_insert() { - int err; + int first_error, error; + my_bool abort= file->s->deleting; DBUG_ENTER("ha_maria::end_bulk_insert"); - maria_end_bulk_insert(file); - if ((err= maria_extra(file, HA_EXTRA_NO_CACHE, 0))) - goto end; - if (can_enable_indexes && !file->s->deleting) - err= enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE); -end: + + if ((first_error= maria_end_bulk_insert(file, abort))) + abort= 1; + + if ((error= maria_extra(file, HA_EXTRA_NO_CACHE, 0))) + { + first_error= first_error ? first_error : error; + abort= 1; + } + + if (!abort && can_enable_indexes) + if ((error= enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE))) + first_error= first_error ? first_error : error; + if (bulk_insert_single_undo != BULK_INSERT_NONE) { DBUG_ASSERT(can_enable_indexes); @@ -2222,12 +2231,12 @@ end: Table was transactional just before start_bulk_insert(). No need to flush pages if we did a repair (which already flushed). */ - err|= - _ma_reenable_logging_for_table(file, - bulk_insert_single_undo == - BULK_INSERT_SINGLE_UNDO_AND_NO_REPAIR); + if ((error= _ma_reenable_logging_for_table(file, + bulk_insert_single_undo == + BULK_INSERT_SINGLE_UNDO_AND_NO_REPAIR))) + first_error= first_error ? first_error : error; } - DBUG_RETURN(err); + DBUG_RETURN(first_error); } diff --git a/storage/maria/ma_ft_boolean_search.c b/storage/maria/ma_ft_boolean_search.c index a37a1322ad0..4f98bb3db41 100644 --- a/storage/maria/ma_ft_boolean_search.c +++ b/storage/maria/ma_ft_boolean_search.c @@ -1036,7 +1036,7 @@ void maria_ft_boolean_close_search(FT_INFO *ftb) { if (is_tree_inited(& ftb->no_dupes)) { - delete_tree(& ftb->no_dupes); + delete_tree(&ftb->no_dupes, 0); } free_root(& ftb->mem_root, MYF(0)); my_free(ftb); diff --git a/storage/maria/ma_ft_nlq_search.c b/storage/maria/ma_ft_nlq_search.c index 8d0ac74c131..3252b95e89e 100644 --- a/storage/maria/ma_ft_nlq_search.c +++ b/storage/maria/ma_ft_nlq_search.c @@ -320,8 +320,8 @@ FT_INFO *maria_ft_init_nlq_search(MARIA_HA *info, uint keynr, uchar *query, (qsort2_cmp)&FT_DOC_cmp, 0); err: - delete_tree(&aio.dtree); - delete_tree(&wtree); + delete_tree(&aio.dtree, 0); + delete_tree(&wtree, 0); info->cur_row.lastpos= saved_lastpos; DBUG_RETURN(dlist); } diff --git a/storage/maria/ma_ft_parser.c b/storage/maria/ma_ft_parser.c index f0a2e1e1425..00d5baacaa1 100644 --- a/storage/maria/ma_ft_parser.c +++ b/storage/maria/ma_ft_parser.c @@ -61,7 +61,7 @@ FT_WORD * maria_ft_linearize(TREE *wtree, MEM_ROOT *mem_root) docstat.sum=0; tree_walk(wtree,(tree_walk_action)&walk_and_copy,&docstat,left_root_right); } - delete_tree(wtree); + delete_tree(wtree, 0); if (!wlist) DBUG_RETURN(NULL); @@ -283,7 +283,7 @@ static int maria_ft_add_word(MYSQL_FTPARSER_PARAM *param, w.len= word_len; if (!tree_insert(wtree, &w, 0, wtree->custom_arg)) { - delete_tree(wtree); + delete_tree(wtree, 0); DBUG_RETURN(1); } DBUG_RETURN(0); diff --git a/storage/maria/ma_write.c b/storage/maria/ma_write.c index fdcb5abd090..1261379f4d6 100644 --- a/storage/maria/ma_write.c +++ b/storage/maria/ma_write.c @@ -1786,8 +1786,10 @@ void maria_flush_bulk_insert(MARIA_HA *info, uint inx) } } -void maria_end_bulk_insert(MARIA_HA *info) + +int maria_end_bulk_insert(MARIA_HA *info, my_bool abort) { + int first_error= 0; DBUG_ENTER("maria_end_bulk_insert"); if (info->bulk_insert) { @@ -1796,15 +1798,20 @@ void maria_end_bulk_insert(MARIA_HA *info) { if (is_tree_inited(&info->bulk_insert[i])) { + int error; if (info->s->deleting) reset_free_element(&info->bulk_insert[i]); - delete_tree(&info->bulk_insert[i]); + if ((error= delete_tree(&info->bulk_insert[i], abort))) + { + first_error= first_error ? first_error : error; + abort= 1; + } } } my_free(info->bulk_insert); info->bulk_insert= 0; } - DBUG_VOID_RETURN; + DBUG_RETURN(first_error); } diff --git a/storage/maria/maria_pack.c b/storage/maria/maria_pack.c index 814c50e1db8..c087697bf0b 100644 --- a/storage/maria/maria_pack.c +++ b/storage/maria/maria_pack.c @@ -836,7 +836,7 @@ static void free_counts_and_tree_and_queue(HUFF_TREE *huff_trees, uint trees, if (huff_counts[i].tree_buff) { my_free(huff_counts[i].tree_buff); - delete_tree(&huff_counts[i].int_tree); + delete_tree(&huff_counts[i].int_tree, 0); } } my_free(huff_counts); @@ -934,7 +934,7 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts) (count->field_length == 1 && count->int_tree.elements_in_tree > 1)) { - delete_tree(&count->int_tree); + delete_tree(&count->int_tree, 0); my_free(count->tree_buff); count->tree_buff=0; } @@ -1333,7 +1333,7 @@ static void check_counts(HUFF_COUNTS *huff_counts, uint trees, else { my_free(huff_counts->tree_buff); - delete_tree(&huff_counts->int_tree); + delete_tree(&huff_counts->int_tree, 0); huff_counts->tree_buff=0; } if (tree.element_buffer) @@ -3156,7 +3156,7 @@ static void fakebigcodes(HUFF_COUNTS *huff_counts, HUFF_COUNTS *end_count) if (huff_counts->tree_buff) { my_free(huff_counts->tree_buff); - delete_tree(&huff_counts->int_tree); + delete_tree(&huff_counts->int_tree, 0); huff_counts->tree_buff= NULL; DBUG_PRINT("fakebigcodes", ("freed distinct column values")); } diff --git a/storage/myisam/ft_boolean_search.c b/storage/myisam/ft_boolean_search.c index a44e24c9db1..dee57513912 100644 --- a/storage/myisam/ft_boolean_search.c +++ b/storage/myisam/ft_boolean_search.c @@ -1039,7 +1039,7 @@ void ft_boolean_close_search(FT_INFO *ftb) { if (is_tree_inited(& ftb->no_dupes)) { - delete_tree(& ftb->no_dupes); + delete_tree(&ftb->no_dupes, 0); } free_root(& ftb->mem_root, MYF(0)); my_free(ftb); diff --git a/storage/myisam/ft_nlq_search.c b/storage/myisam/ft_nlq_search.c index d9a9a03919e..3945484c8eb 100644 --- a/storage/myisam/ft_nlq_search.c +++ b/storage/myisam/ft_nlq_search.c @@ -316,8 +316,8 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, uchar *query, 0); err: - delete_tree(&aio.dtree); - delete_tree(&wtree); + delete_tree(&aio.dtree, 0); + delete_tree(&wtree, 0); info->lastpos=saved_lastpos; DBUG_RETURN(dlist); } diff --git a/storage/myisam/ft_parser.c b/storage/myisam/ft_parser.c index c8d99b68e8a..fc3a649dd53 100644 --- a/storage/myisam/ft_parser.c +++ b/storage/myisam/ft_parser.c @@ -59,7 +59,7 @@ FT_WORD * ft_linearize(TREE *wtree, MEM_ROOT *mem_root) docstat.sum=0; tree_walk(wtree,(tree_walk_action)&walk_and_copy,&docstat,left_root_right); } - delete_tree(wtree); + delete_tree(wtree, 0); if (!wlist) DBUG_RETURN(NULL); @@ -277,7 +277,7 @@ static int ft_add_word(MYSQL_FTPARSER_PARAM *param, w.len= word_len; if (!tree_insert(wtree, &w, 0, wtree->custom_arg)) { - delete_tree(wtree); + delete_tree(wtree, 0); DBUG_RETURN(1); } DBUG_RETURN(0); diff --git a/storage/myisam/ft_stopwords.c b/storage/myisam/ft_stopwords.c index 3bf31bf3d66..7c743743adc 100644 --- a/storage/myisam/ft_stopwords.c +++ b/storage/myisam/ft_stopwords.c @@ -38,11 +38,12 @@ static int FT_STOPWORD_cmp(void* cmp_arg __attribute__((unused)), (uchar *)w2->pos,w2->len,0); } -static void FT_STOPWORD_free(FT_STOPWORD *w, TREE_FREE action, - void *arg __attribute__((unused))) +static int FT_STOPWORD_free(FT_STOPWORD *w, TREE_FREE action, + void *arg __attribute__((unused))) { if (action == free_free) my_free((void*)w->pos); + return 0; } static int ft_add_stopword(const char *w) @@ -134,7 +135,7 @@ void ft_free_stopwords() if (stopwords3) { - delete_tree(stopwords3); /* purecov: inspected */ + delete_tree(stopwords3, 0); /* purecov: inspected */ my_free(stopwords3); stopwords3=0; } diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 210111d89ff..3c6684623e9 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -1689,8 +1689,9 @@ void ha_myisam::start_bulk_insert(ha_rows rows, uint flags) which have been activated by start_bulk_insert(). SYNOPSIS - end_bulk_insert() - no arguments + end_bulk_insert(fatal_error) + abort 0 normal end, store everything + 1 abort quickly. No need to flush/write anything. Table will be deleted RETURN 0 OK @@ -1699,10 +1700,20 @@ void ha_myisam::start_bulk_insert(ha_rows rows, uint flags) int ha_myisam::end_bulk_insert() { + int first_error, error; + my_bool abort= file->s->deleting; DBUG_ENTER("ha_myisam::end_bulk_insert"); - mi_end_bulk_insert(file); - int err=mi_extra(file, HA_EXTRA_NO_CACHE, 0); - if (!err && !file->s->deleting) + + if ((first_error= mi_end_bulk_insert(file, abort))) + abort= 1; + + if ((error= mi_extra(file, HA_EXTRA_NO_CACHE, 0))) + { + first_error= first_error ? first_error : error; + abort= 1; + } + + if (!abort) { if (can_enable_indexes) { @@ -1713,16 +1724,17 @@ int ha_myisam::end_bulk_insert() setting the indexes as active and trying to recreate them. */ - if (((err= enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE)) != 0) && + if (((first_error= enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE)) != 0) && table->in_use->killed) { delete_all_rows(); /* not crashed, despite being killed during repair */ file->s->state.changed&= ~(STATE_CRASHED|STATE_CRASHED_ON_REPAIR); } - } + } } - DBUG_RETURN(err); + DBUG_PRINT("exit", ("first_error: %d", first_error)); + DBUG_RETURN(first_error); } diff --git a/storage/myisam/mi_extra.c b/storage/myisam/mi_extra.c index 3d6049c0172..8a2bc82d166 100644 --- a/storage/myisam/mi_extra.c +++ b/storage/myisam/mi_extra.c @@ -259,7 +259,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) break; case HA_EXTRA_PREPARE_FOR_DROP: /* Signals about intent to delete this table */ - //share->deleting= TRUE; + share->deleting= TRUE; share->global_changed= FALSE; /* force writing changed flag */ _mi_mark_file_changed(info); /* Fall trough */ diff --git a/storage/myisam/mi_write.c b/storage/myisam/mi_write.c index ff12f335af1..6603eb789a1 100644 --- a/storage/myisam/mi_write.c +++ b/storage/myisam/mi_write.c @@ -1033,8 +1033,9 @@ void mi_flush_bulk_insert(MI_INFO *info, uint inx) } } -void mi_end_bulk_insert(MI_INFO *info) +int mi_end_bulk_insert(MI_INFO *info, my_bool abort) { + int first_error= 0; if (info->bulk_insert) { uint i; @@ -1042,10 +1043,16 @@ void mi_end_bulk_insert(MI_INFO *info) { if (is_tree_inited(& info->bulk_insert[i])) { - delete_tree(& info->bulk_insert[i]); + int error; + if ((error= delete_tree(& info->bulk_insert[i], abort))) + { + first_error= first_error ? first_error : error; + abort= 1; + } } } my_free(info->bulk_insert); info->bulk_insert=0; } + return first_error; } diff --git a/storage/myisam/myisamlog.c b/storage/myisam/myisamlog.c index 7ce03ca9485..eb06c75f0e0 100644 --- a/storage/myisam/myisamlog.c +++ b/storage/myisam/myisamlog.c @@ -649,7 +649,7 @@ static int examine_log(char * file_name, char **table_names) } } end_key_cache(dflt_key_cache,1); - delete_tree(&tree); + delete_tree(&tree, 0); (void) end_io_cache(&cache); (void) my_close(file,MYF(0)); if (write_file && my_fclose(write_file,MYF(MY_WME))) @@ -669,7 +669,7 @@ static int examine_log(char * file_name, char **table_names) fflush(stderr); end: end_key_cache(dflt_key_cache, 1); - delete_tree(&tree); + delete_tree(&tree, 0); (void) end_io_cache(&cache); (void) my_close(file,MYF(0)); if (write_file) diff --git a/storage/myisam/myisampack.c b/storage/myisam/myisampack.c index 966edc877cd..6fb2a5a69d5 100644 --- a/storage/myisam/myisampack.c +++ b/storage/myisam/myisampack.c @@ -861,7 +861,7 @@ static void free_counts_and_tree_and_queue(HUFF_TREE *huff_trees, uint trees, if (huff_counts[i].tree_buff) { my_free(huff_counts[i].tree_buff); - delete_tree(&huff_counts[i].int_tree); + delete_tree(&huff_counts[i].int_tree, 0); } } my_free(huff_counts); @@ -967,7 +967,7 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts) (count->field_length == 1 && count->int_tree.elements_in_tree > 1)) { - delete_tree(&count->int_tree); + delete_tree(&count->int_tree, 0); my_free(count->tree_buff); count->tree_buff=0; } @@ -1366,7 +1366,7 @@ static void check_counts(HUFF_COUNTS *huff_counts, uint trees, else { my_free(huff_counts->tree_buff); - delete_tree(&huff_counts->int_tree); + delete_tree(&huff_counts->int_tree, 0); huff_counts->tree_buff=0; } if (tree.element_buffer) @@ -3166,7 +3166,7 @@ static void fakebigcodes(HUFF_COUNTS *huff_counts, HUFF_COUNTS *end_count) if (huff_counts->tree_buff) { my_free(huff_counts->tree_buff); - delete_tree(&huff_counts->int_tree); + delete_tree(&huff_counts->int_tree, 0); huff_counts->tree_buff= NULL; DBUG_PRINT("fakebigcodes", ("freed distinct column values")); } |