From 9f4739a3fa45a716f2f699ac5f4614c6d43b8fea Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Fri, 24 Jun 2011 16:43:25 +0400 Subject: [PATCH 1/2] Fix compile failure --- storage/maria/ma_pagecache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/maria/ma_pagecache.c b/storage/maria/ma_pagecache.c index 0a1d700e476..0b6c543459f 100644 --- a/storage/maria/ma_pagecache.c +++ b/storage/maria/ma_pagecache.c @@ -1624,8 +1624,8 @@ static void wait_for_flush(PAGECACHE *pagecache PAGECACHE_BLOCK_LINK *block __attribute__((unused))) { - DBUG_ENTER("wait_for_flush"); struct st_my_thread_var *thread= my_thread_var; + DBUG_ENTER("wait_for_flush"); wqueue_add_to_queue(&block->wqueue[COND_FOR_SAVED], thread); do { From 5e876bd3003870afe4e3e2dae866bcb0954c2298 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Thu, 30 Jun 2011 00:37:12 +0300 Subject: [PATCH 2/2] Aria bug fixes and improvements: - Fixed performance bug in alter table with Aria; Aria didn't use disable keys + enable keys - Fixed wrong warning about 'Wrong CRC on datapage' from REPAIR TABLE with aria block tables. - Fixed bug in aria_chk that disabled performance counters. - Added --translog_buffer_size to maria_read_log. storage/maria/ha_maria.cc: Fixed performance bug in alter table with Aria; Aria didn't use disable keys + enable keys storage/maria/ma_bitmap.c: Added some DBUG_ASSERT()'s and made code more uniform storage/maria/ma_check.c: Fixed wrong warning about 'Wrong CRC on datapage' from REPAIR TABLE with aria block tables. storage/maria/ma_pagecache.c: Copy read pages to buffer even if there was an error (to be able to detect zero filled pages) storage/maria/maria_chk.c: Fixed bug in aria_chk that disabled performance counters. storage/maria/maria_read_log.c: Added option to set translog_buffer_size --- storage/maria/ha_maria.cc | 20 +++++++++++--------- storage/maria/ma_bitmap.c | 11 +++++++---- storage/maria/ma_check.c | 29 ++++++++++++++++++++++++++--- storage/maria/ma_pagecache.c | 4 ++-- storage/maria/maria_chk.c | 2 +- storage/maria/maria_read_log.c | 15 ++++++++++----- 6 files changed, 57 insertions(+), 24 deletions(-) diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index be8f4c4dde5..58264513da9 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -1966,19 +1966,21 @@ void ha_maria::start_bulk_insert(ha_rows rows) we don't want to update the key statistics based of only a few rows. Index file rebuild requires an exclusive lock, so if versioning is on don't do it (see how ha_maria::store_lock() tries to predict repair). - We can repair index only if we have an exclusive (TL_WRITE) lock. To - see if table is empty, we shouldn't rely on the old records' count from - our transaction's start (if that old count is 0 but now there are - records in the table, we would wrongly destroy them). - So we need to look at share->state.state.records. - As a safety net for now, we don't remove the test of - file->state->records, because there is uncertainty on what will happen - during repair if the two states disagree. + We can repair index only if we have an exclusive (TL_WRITE) lock or + if this is inside an ALTER TABLE, in which case lock_type == TL_UNLOCK. + + To see if table is empty, we shouldn't rely on the old record + count from our transaction's start (if that old count is 0 but + now there are records in the table, we would wrongly destroy + them). So we need to look at share->state.state.records. As a + safety net for now, we don't remove the test of + file->state->records, because there is uncertainty on what will + happen during repair if the two states disagree. */ if ((file->state->records == 0) && (share->state.state.records == 0) && can_enable_indexes && (!rows || rows >= MARIA_MIN_ROWS_TO_DISABLE_INDEXES) && - (file->lock.type == TL_WRITE)) + (file->lock.type == TL_WRITE || file->lock.type == TL_UNLOCK)) { /** @todo for a single-row INSERT SELECT, we will go into repair, which diff --git a/storage/maria/ma_bitmap.c b/storage/maria/ma_bitmap.c index 4198f340ed7..2469ce238cc 100644 --- a/storage/maria/ma_bitmap.c +++ b/storage/maria/ma_bitmap.c @@ -1061,14 +1061,18 @@ static my_bool move_to_next_bitmap(MARIA_HA *info, MARIA_FILE_BITMAP *bitmap) MARIA_STATE_INFO *state= &info->s->state; DBUG_ENTER("move_to_next_bitmap"); - if (state->first_bitmap_with_space != ~(ulonglong) 0 && + if (state->first_bitmap_with_space != ~(pgcache_page_no_t) 0 && state->first_bitmap_with_space != page) { page= state->first_bitmap_with_space; - state->first_bitmap_with_space= ~(ulonglong) 0; + state->first_bitmap_with_space= ~(pgcache_page_no_t) 0; + DBUG_ASSERT(page % bitmap->pages_covered == 0); } else + { page+= bitmap->pages_covered; + DBUG_ASSERT(page % bitmap->pages_covered == 0); + } DBUG_RETURN(_ma_change_bitmap_page(info, bitmap, page)); } @@ -2039,8 +2043,7 @@ my_bool _ma_bitmap_find_new_place(MARIA_HA *info, MARIA_ROW *row, goto abort; /* Switch bitmap to current head page */ - bitmap_page= page / share->bitmap.pages_covered; - bitmap_page*= share->bitmap.pages_covered; + bitmap_page= page - page % share->bitmap.pages_covered; if (share->bitmap.page != bitmap_page && _ma_change_bitmap_page(info, &share->bitmap, bitmap_page)) diff --git a/storage/maria/ma_check.c b/storage/maria/ma_check.c index 082c6056a3b..0719df4e2fa 100644 --- a/storage/maria/ma_check.c +++ b/storage/maria/ma_check.c @@ -6511,6 +6511,17 @@ static void copy_data_file_state(MARIA_STATE_INFO *to, } +/* Return 1 if block is full of zero's */ + +static my_bool zero_filled_block(uchar *tmp, uint length) +{ + while (length--) + if (*(tmp++) != 0) + return 0; + return 1; +} + + /* Read 'safely' next record while scanning table. @@ -6612,9 +6623,21 @@ read_next_page: { if (my_errno == HA_ERR_WRONG_CRC) { - _ma_check_print_info(sort_info->param, - "Wrong CRC on datapage at %s", - llstr(page, llbuff)); + /* + Don't give errors for zero filled blocks. These can + sometimes be found at end of a bitmap when we wrote a big + record last that was moved to the next bitmap. + */ + if (!zero_filled_block(info->scan.page_buff, share->block_size) || + _ma_check_bitmap_data(info, UNALLOCATED_PAGE, 0, + _ma_bitmap_get_page_bits(info, + &share->bitmap, + page))) + { + _ma_check_print_info(sort_info->param, + "Wrong CRC on datapage at %s", + llstr(page, llbuff)); + } continue; } DBUG_RETURN(my_errno); diff --git a/storage/maria/ma_pagecache.c b/storage/maria/ma_pagecache.c index 0b6c543459f..097650dadd7 100644 --- a/storage/maria/ma_pagecache.c +++ b/storage/maria/ma_pagecache.c @@ -3519,7 +3519,7 @@ restart: } else { - if (!(status & PCBLOCK_ERROR)) + if (status & PCBLOCK_READ) { #if !defined(SERIALIZED_READ_FROM_CACHE) pagecache_pthread_mutex_unlock(&pagecache->cache_lock); @@ -3533,7 +3533,7 @@ restart: pagecache_pthread_mutex_lock(&pagecache->cache_lock); #endif } - else + if (status & PCBLOCK_ERROR) my_errno= block->error; } diff --git a/storage/maria/maria_chk.c b/storage/maria/maria_chk.c index ec8af652fe3..4043457be17 100644 --- a/storage/maria/maria_chk.c +++ b/storage/maria/maria_chk.c @@ -878,9 +878,9 @@ static void get_options(register int *argc,register char ***argv) load_defaults("my", load_default_groups, argc, argv); default_argv= *argv; + check_param.testflag= T_UPDATE_STATE; if (isatty(fileno(stdout))) check_param.testflag|=T_WRITE_LOOP; - check_param.testflag= T_UPDATE_STATE; if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option))) exit(ho_error); diff --git a/storage/maria/maria_read_log.c b/storage/maria/maria_read_log.c index 9471f01dbc8..b3f3eb345be 100644 --- a/storage/maria/maria_read_log.c +++ b/storage/maria/maria_read_log.c @@ -32,7 +32,7 @@ const char *default_dbug_option= "d:t:o,/tmp/aria_read_log.trace"; static my_bool opt_display_only, opt_apply, opt_apply_undo, opt_silent; static my_bool opt_check; static const char *opt_tmpdir; -static ulong opt_page_buffer_size; +static ulong opt_page_buffer_size, opt_translog_buffer_size; static ulonglong opt_start_from_lsn, opt_end_lsn, opt_start_from_checkpoint; static MY_TMPDIR maria_chk_tmpdir; @@ -80,9 +80,8 @@ int main(int argc, char **argv) But if it finds a log and this log was crashed, it will create a new log, which is useless. TODO: start log handler in read-only mode. */ - if (init_pagecache(maria_log_pagecache, - TRANSLOG_PAGECACHE_SIZE, 0, 0, - TRANSLOG_PAGE_SIZE, MY_WME) == 0 || + if (init_pagecache(maria_log_pagecache, opt_translog_buffer_size, + 0, 0, TRANSLOG_PAGE_SIZE, MY_WME) == 0 || translog_init(maria_data_root, TRANSLOG_FILE_SIZE, 0, 0, maria_log_pagecache, TRANSLOG_DEFAULT_FLAGS, opt_display_only)) @@ -166,7 +165,7 @@ err: #include "ma_check_standalone.h" enum options_mc { - OPT_CHARSETS_DIR=256, OPT_FORCE_CRASH + OPT_CHARSETS_DIR=256, OPT_FORCE_CRASH, OPT_TRANSLOG_BUFFER_SIZE }; static struct my_option my_long_options[] = @@ -228,6 +227,12 @@ static struct my_option my_long_options[] = "colon (:)" #endif , (char**) &opt_tmpdir, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + { "translog-buffer-size", OPT_TRANSLOG_BUFFER_SIZE, + "The size of the buffer used for transaction log for Aria tables", + &opt_translog_buffer_size, &opt_translog_buffer_size, 0, + GET_ULONG, REQUIRED_ARG, (long) TRANSLOG_PAGECACHE_SIZE, + 1024L*1024L, (long) ~(ulong) 0, (long) MALLOC_OVERHEAD, + (long) IO_SIZE, 0}, {"undo", 'u', "Apply UNDO records to tables. (disable with --disable-undo)", (uchar **) &opt_apply_undo, (uchar **) &opt_apply_undo, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},