diff options
author | unknown <monty@mysql.com/narttu.mysql.fi> | 2007-04-19 18:48:36 +0300 |
---|---|---|
committer | unknown <monty@mysql.com/narttu.mysql.fi> | 2007-04-19 18:48:36 +0300 |
commit | 6686a3ee53e7260047a2737b854f400f6847b452 (patch) | |
tree | d7e7037c5923ee1fa85396a87975cc6670fb6202 /storage | |
parent | ac0f98dd5e361f38767a89bb4623f250db8fb889 (diff) | |
download | mariadb-git-6686a3ee53e7260047a2737b854f400f6847b452.tar.gz |
After merge fixes
Read blocks through page cache in check_block_record()
Don't read first bitmap on ma_open()
Don't require that a files block_size is equal to maria_block_size, if page cache is not setup yet.
Changed ma_test1, ma_test2, maria_chk and maria_pack to always create a page cache.
The above fixes so that ma_test_all now works again
BitKeeper/etc/ignore:
added storage/maria/unittest/ma_pagecache_consist_1k-t-big storage/maria/unittest/ma_pagecache_consist_1kHC-t-big storage/maria/unittest/ma_pagecache_consist_1kRD-t-big storage/maria/unittest/ma_pagecache_consist_1kWR-t-big storage/maria/unittest/ma_pagecache_consist_64k-t-big storage/maria/unittest/ma_pagecache_consist_64kHC-t-big storage/maria/unittest/ma_pagecache_consist_64kRD-t-big storage/maria/unittest/ma_pagecache_consist_64kWR-t-big storage/maria/unittest/ma_pagecache_single_64k-t-big
include/maria.h:
Added MARIA_MIN_PAGE_CACHE_SIZE
include/pagecache.h:
Filedescriptors should be of type File
storage/maria/ma_bitmap.c:
After merge fixes
Create dummy bitmap on startup (can't read first bitmap becasue page cache may not be set up yet)
storage/maria/ma_blockrec.c:
After merge fixes
storage/maria/ma_check.c:
Use page cache to read rows-in-block rows.
Don't initialize page cache; It's now done in maria_chk
storage/maria/ma_dynrec.c:
Trivial code reorganization
storage/maria/ma_open.c:
Don't give error for conflicting block size if page cache is not initalized.
(Needed for maria_chk to be able to work on tables with different page sizes)
After merge fixes
storage/maria/ma_page.c:
Fix compiler warning
Remove net needed asserts (Guranteed by ma_create())
storage/maria/ma_pagecache.c:
Allow one to create a page cache with just one block
(For trivail scan of table)
Trivial code simplication
storage/maria/ma_test1.c:
Always create a page cache (Maria now requires a page cache to work)
storage/maria/ma_test2.c:
Always create a page cache (Maria now requires a page cache to work)
storage/maria/maria_chk.c:
Remove command line options --maria_block_size and --pagecache_block_size.
Set the global maria_block_size from the data file. This allows maria_chk to work with tables of different block sizes.
Simply DESCRIPT handling; Allows us to remove one indentation level in maria_chk().
Always initialize page cache if we are doing check/repair.
(Most of the patch is reindentation of the code)
storage/maria/maria_def.h:
After merge fix
storage/maria/maria_pack.c:
Set maria_block_size based on the files block_size.
Initalize page cache (needed for getting rows-in-blocks to works)
Diffstat (limited to 'storage')
-rw-r--r-- | storage/maria/ma_bitmap.c | 15 | ||||
-rw-r--r-- | storage/maria/ma_blockrec.c | 15 | ||||
-rw-r--r-- | storage/maria/ma_check.c | 26 | ||||
-rw-r--r-- | storage/maria/ma_dynrec.c | 13 | ||||
-rw-r--r-- | storage/maria/ma_open.c | 11 | ||||
-rw-r--r-- | storage/maria/ma_page.c | 7 | ||||
-rwxr-xr-x | storage/maria/ma_pagecache.c | 19 | ||||
-rw-r--r-- | storage/maria/ma_test1.c | 4 | ||||
-rw-r--r-- | storage/maria/ma_test2.c | 31 | ||||
-rw-r--r-- | storage/maria/maria_chk.c | 377 | ||||
-rw-r--r-- | storage/maria/maria_def.h | 4 | ||||
-rw-r--r-- | storage/maria/maria_pack.c | 13 |
12 files changed, 269 insertions, 266 deletions
diff --git a/storage/maria/ma_bitmap.c b/storage/maria/ma_bitmap.c index 97ebedb5ac4..ed5bd070981 100644 --- a/storage/maria/ma_bitmap.c +++ b/storage/maria/ma_bitmap.c @@ -131,7 +131,7 @@ static inline my_bool write_changed_bitmap(MARIA_SHARE *share, { DBUG_ASSERT(share->pagecache->block_size == bitmap->block_size); return (pagecache_write(share->pagecache, - (PAGECACHE_FILE*)&bitmap->file, bitmap->page, 0, + &bitmap->file, bitmap->page, 0, (byte*) bitmap->map, PAGECACHE_PLAIN_PAGE, PAGECACHE_LOCK_LEFT_UNLOCKED, PAGECACHE_PIN_LEFT_UNPINNED, @@ -168,7 +168,7 @@ my_bool _ma_bitmap_init(MARIA_SHARE *share, File file) if (!(bitmap->map= (uchar*) my_malloc(size, MYF(MY_WME)))) return 1; - bitmap->file= file; + bitmap->file.file= file; bitmap->changed= 0; bitmap->block_size= share->block_size; /* Size needs to be alligned on 6 */ @@ -195,10 +195,15 @@ my_bool _ma_bitmap_init(MARIA_SHARE *share, File file) pthread_mutex_init(&share->bitmap.bitmap_lock, MY_MUTEX_INIT_SLOW); /* - Start by reading first page (assume table scan) - Later code is simpler if it can assume we always have an active bitmap. + We can't read a page yet, as in some case we don't have an active + page cache yet. + Pretend we have a dummy, full and not changed bitmap page in memory. */ - return _ma_read_bitmap_page(share, bitmap, (ulonglong) 0); + + bitmap->page= ~(ulonglong) 0; + bitmap->used_size= bitmap->total_size; + bfill(bitmap->map, share->block_size, 255); + return 0; } diff --git a/storage/maria/ma_blockrec.c b/storage/maria/ma_blockrec.c index e05f2fcfe6f..55b16a64916 100644 --- a/storage/maria/ma_blockrec.c +++ b/storage/maria/ma_blockrec.c @@ -374,21 +374,20 @@ my_bool _ma_once_init_block_record(MARIA_SHARE *share, File data_file) my_bool _ma_once_end_block_record(MARIA_SHARE *share) { int res= _ma_bitmap_end(share); - if (share->bitmap.file >= 0) + if (share->bitmap.file.file >= 0) { - if (flush_pagecache_blocks(share->pagecache, (PAGECACHE_FILE*)&share->bitmap, - if (flush_key_blocks(share->key_cache, share->bitmap.file, - share->temporary ? FLUSH_IGNORE_CHANGED : - FLUSH_RELEASE)) + if (flush_pagecache_blocks(share->pagecache, &share->bitmap.file, + share->temporary ? FLUSH_IGNORE_CHANGED : + FLUSH_RELEASE)) res= 1; - if (my_close(share->bitmap.file, MYF(MY_WME))) + if (my_close(share->bitmap.file.file, MYF(MY_WME))) res= 1; /* Trivial assignment to guard against multiple invocations (May happen if file are closed but we want to keep the maria object around a bit longer) */ - share->bitmap.file= -1; + share->bitmap.file.file= -1; } return res; } @@ -450,7 +449,7 @@ void _ma_end_block_record(MARIA_HA *info) The following protects us from doing an extra, not allowed, close in maria_close() */ - info->dfile= -1; + info->dfile.file= -1; DBUG_VOID_RETURN; } diff --git a/storage/maria/ma_check.c b/storage/maria/ma_check.c index 259ff90478b..4087f12ba43 100644 --- a/storage/maria/ma_check.c +++ b/storage/maria/ma_check.c @@ -1599,8 +1599,12 @@ static int check_block_record(HA_CHECK *param, MARIA_HA *info, int extend, if (((pos / block_size) % info->s->bitmap.pages_covered) == 0) { /* Bitmap page */ - if (_ma_read_cache(¶m->read_cache, bitmap_buff, pos, - block_size, READING_NEXT)) + if (pagecache_read(info->s->pagecache, + &info->dfile, + (pos / block_size), 1, + bitmap_buff, + PAGECACHE_PLAIN_PAGE, + PAGECACHE_LOCK_LEFT_UNLOCKED, 0) == 0) { _ma_check_print_error(param, "Page %9s: Got error: %d when reading datafile", @@ -1624,8 +1628,12 @@ static int check_block_record(HA_CHECK *param, MARIA_HA *info, int extend, continue; } - if (_ma_read_cache(¶m->read_cache, page_buff, pos, - block_size, READING_NEXT)) + if (pagecache_read(info->s->pagecache, + &info->dfile, + (pos / block_size), 1, + page_buff, + PAGECACHE_PLAIN_PAGE, + PAGECACHE_LOCK_LEFT_UNLOCKED, 0) == 0) { _ma_check_print_error(param, "Page %9s: Got error: %d when reading datafile", @@ -1935,10 +1943,6 @@ int maria_repair(HA_CHECK *param, register MARIA_HA *info, if (info->s->options & (HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD)) param->testflag|=T_CALC_CHECKSUM; - if (!param->using_global_keycache) - VOID(init_pagecache(maria_pagecache, param->use_buffers, 0, 0, - param->pagecache_block_size)); - if (init_io_cache(¶m->read_cache, info->dfile.file, (uint) param->read_buffer_length, READ_CACHE,share->pack.header_length,1,MYF(MY_WME))) @@ -2308,8 +2312,6 @@ int _ma_flush_blocks(HA_CHECK *param, PAGECACHE *pagecache, _ma_check_print_error(param,"%d when trying to write bufferts",my_errno); return(1); } - if (!param->using_global_keycache) - end_pagecache(pagecache,1); return 0; } /* _ma_flush_blocks */ @@ -3602,7 +3604,6 @@ static int sort_get_next_record(MARIA_SORT_PARAM *sort_param) int parallel_flag; uint found_record,b_type,left_length; my_off_t pos; - byte *to; MARIA_BLOCK_INFO block_info; MARIA_SORT_INFO *sort_info=sort_param->sort_info; HA_CHECK *param=sort_info->param; @@ -3652,6 +3653,8 @@ static int sort_get_next_record(MARIA_SORT_PARAM *sort_param) } } case DYNAMIC_RECORD: + { + byte *to; LINT_INIT(to); pos=sort_param->pos; searching=(sort_param->fix_datafile && (param->testflag & T_EXTEND)); @@ -3948,6 +3951,7 @@ static int sort_get_next_record(MARIA_SORT_PARAM *sort_param) pos=(sort_param->start_recpos+=MARIA_DYN_ALIGN_SIZE); searching=1; } + } case COMPRESSED_RECORD: for (searching=0 ;; searching=1, sort_param->pos++) { diff --git a/storage/maria/ma_dynrec.c b/storage/maria/ma_dynrec.c index a5f3f3c4900..d6f7309cafa 100644 --- a/storage/maria/ma_dynrec.c +++ b/storage/maria/ma_dynrec.c @@ -1372,13 +1372,15 @@ int _ma_read_dynamic_record(MARIA_HA *info, byte *buf, { int block_of_record; uint b_type,left_length; - byte *to; MARIA_BLOCK_INFO block_info; File file; DBUG_ENTER("_ma_read_dynamic_record"); if (filepos != HA_OFFSET_ERROR) { + byte *to; + uint left_length; + LINT_INIT(to); LINT_INIT(left_length); file= info->dfile.file; @@ -1390,13 +1392,14 @@ int _ma_read_dynamic_record(MARIA_HA *info, byte *buf, if (filepos == HA_OFFSET_ERROR) goto panic; if (info->opt_flag & WRITE_CACHE_USED && - info->rec_cache.pos_in_file < filepos + MARIA_BLOCK_INFO_HEADER_LENGTH && + (info->rec_cache.pos_in_file < filepos + + MARIA_BLOCK_INFO_HEADER_LENGTH) && flush_io_cache(&info->rec_cache)) goto err; info->rec_cache.seek_not_done=1; - if ((b_type= _ma_get_block_info(&block_info, file, filepos)) - & (BLOCK_DELETED | BLOCK_ERROR | BLOCK_SYNC_ERROR | - BLOCK_FATAL_ERROR)) + if ((b_type= _ma_get_block_info(&block_info, file, filepos)) & + (BLOCK_DELETED | BLOCK_ERROR | BLOCK_SYNC_ERROR | + BLOCK_FATAL_ERROR)) { if (b_type & (BLOCK_SYNC_ERROR | BLOCK_DELETED)) my_errno=HA_ERR_RECORD_DELETED; diff --git a/storage/maria/ma_open.c b/storage/maria/ma_open.c index 3a95d705743..9b7313a469b 100644 --- a/storage/maria/ma_open.c +++ b/storage/maria/ma_open.c @@ -239,7 +239,12 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) my_errno=HA_ERR_UNSUPPORTED; goto err; } - if (share->base.block_size != maria_block_size) + /* + If page cache is not initialized, then assume we will create it + after the table is opened! + */ + if (share->base.block_size != maria_block_size && + share_buff.pagecache->inited != 0) { DBUG_PRINT("error", ("Wrong block size %u; Expected %u", (uint) share->base.block_size, @@ -301,7 +306,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) strmov(share->index_file_name, index_name); strmov(share->data_file_name, data_name); - share->block_size= maria_block_size; + share->block_size= share->base.block_size; { HA_KEYSEG *pos=share->keyparts; for (i=0 ; i < keys ; i++) @@ -553,7 +558,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) goto err; } if (share->data_file_type == BLOCK_RECORD) - info.dfile.file= share->bitmap.file; + info.dfile= share->bitmap.file; else if (_ma_open_datafile(&info, share, old_info->dfile.file)) goto err; errpos= 5; diff --git a/storage/maria/ma_page.c b/storage/maria/ma_page.c index 91a3b42009e..2aaabb1257d 100644 --- a/storage/maria/ma_page.c +++ b/storage/maria/ma_page.c @@ -21,15 +21,15 @@ byte *_ma_fetch_keypage(register MARIA_HA *info, MARIA_KEYDEF *keyinfo, my_off_t page, int level, - byte *buff, int return_buffer) + byte *buff, + int return_buffer __attribute__ ((unused))) { byte *tmp; uint page_size; DBUG_ENTER("_ma_fetch_keypage"); DBUG_PRINT("enter",("page: %ld", (long) page)); - DBUG_ASSERT(info->s->pagecache->block_size == keyinfo->block_length && - info->s->pagecache->block_size == info->s->block_size); + DBUG_ASSERT(info->s->pagecache->block_size == keyinfo->block_length); /* TODO: replace PAGECACHE_PLAIN_PAGE with PAGECACHE_LSN_PAGE when LSN on the pages will be implemented @@ -88,7 +88,6 @@ int _ma_write_keypage(register MARIA_HA *info, register MARIA_KEYDEF *keyinfo, #endif DBUG_ASSERT(info->s->pagecache->block_size == keyinfo->block_length); - DBUG_ASSERT(info->s->pagecache->block_size == info->s->block_size); /* TODO: replace PAGECACHE_PLAIN_PAGE with PAGECACHE_LSN_PAGE when LSN on the pages will be implemented diff --git a/storage/maria/ma_pagecache.c b/storage/maria/ma_pagecache.c index 3d5c3026173..b7f30eae625 100755 --- a/storage/maria/ma_pagecache.c +++ b/storage/maria/ma_pagecache.c @@ -675,8 +675,11 @@ int init_pagecache(PAGECACHE *pagecache, my_size_t use_mem, 2 * sizeof(PAGECACHE_HASH_LINK) + sizeof(PAGECACHE_HASH_LINK*) * 5/4 + block_size)); - /* It doesn't make sense to have too few blocks (less than 8) */ - if (blocks >= 8 && pagecache->disk_blocks < 0) + /* + We need to support page cache with just one block to be able to do + scanning of rows-in-block files + */ + if (blocks >= 1) { for ( ; ; ) { @@ -3768,7 +3771,7 @@ my_bool pagecache_collect_changed_blocks_with_lsn(PAGECACHE *pagecache, LEX_STRING *str, LSN *max_lsn) { - my_bool error; + my_bool error= 0; ulong stored_list_size= 0; uint file_hash; char *ptr; @@ -3836,7 +3839,7 @@ my_bool pagecache_collect_changed_blocks_with_lsn(PAGECACHE *pagecache, ptr= str->str; int8store(ptr, stored_list_size); ptr+= 8; - if (0 == stored_list_size) + if (!stored_list_size) goto end; for (file_hash= 0; file_hash < PAGECACHE_CHANGED_BLOCKS_HASH; file_hash++) { @@ -3858,13 +3861,13 @@ my_bool pagecache_collect_changed_blocks_with_lsn(PAGECACHE *pagecache, set_if_bigger(*max_lsn, block->rec_lsn); } } - error= 0; - goto end; -err: - error= 1; end: pagecache_pthread_mutex_unlock(&pagecache->cache_lock); DBUG_RETURN(error); + +err: + error= 1; + goto end; } diff --git a/storage/maria/ma_test1.c b/storage/maria/ma_test1.c index fc3ffca7f0e..1c69e2c95b4 100644 --- a/storage/maria/ma_test1.c +++ b/storage/maria/ma_test1.c @@ -51,8 +51,8 @@ int main(int argc,char *argv[]) my_init(); maria_init(); get_options(argc,argv); - if (pagecacheing) - init_pagecache(maria_pagecache, IO_SIZE*16, 0, 0, MARIA_KEY_BLOCK_LENGTH); + /* Maria requires that we always have a page cache */ + init_pagecache(maria_pagecache, IO_SIZE*16, 0, 0, maria_block_size); exit(run_test("test1")); } diff --git a/storage/maria/ma_test2.c b/storage/maria/ma_test2.c index c6dde12f5a3..18eaf27073b 100644 --- a/storage/maria/ma_test2.c +++ b/storage/maria/ma_test2.c @@ -50,7 +50,6 @@ static int verbose=0,testflag=0, static int pack_seg=HA_SPACE_PACK,pack_type=HA_PACK_KEY,remove_count=-1; static int create_flag= 0, srand_arg= 0; static ulong pagecache_size=IO_SIZE*16; -static uint pagecache_block_size= MARIA_KEY_BLOCK_LENGTH; static enum data_file_type record_type= DYNAMIC_RECORD; static uint keys=MARIA_KEYS,recant=1000; @@ -219,8 +218,8 @@ int main(int argc, char *argv[]) goto err; if (!silent) printf("- Writing key:s\n"); - if (pagecacheing) - init_pagecache(maria_pagecache, pagecache_size, 0, 0, pagecache_block_size); + /* Maria requires that we always have a page cache */ + init_pagecache(maria_pagecache, pagecache_size, 0, 0, maria_block_size); if (locking) maria_lock_database(file,F_WRLCK); if (write_cacheing) @@ -282,12 +281,11 @@ int main(int argc, char *argv[]) goto end; } } - /* - TODO: uncomment when resize will be implemented +#ifdef REMOVE_WHEN_WE_HAVE_RESIZE if (pagecacheing) - resize_pagecache(maria_pagecache, pagecache_block_size, + resize_pagecache(maria_pagecache, maria_block_size, pagecache_size * 2, 0, 0); - */ +#endif if (!silent) printf("- Delete\n"); if (srand_arg) @@ -862,13 +860,8 @@ end: if (rec_pointer_size) printf("Record pointer size: %d\n",rec_pointer_size); printf("maria_block_size: %lu\n", maria_block_size); - if (pagecacheing) - { - puts("Key cache used"); - printf("pagecache_block_size: %u\n", pagecache_block_size); - if (write_cacheing) - puts("Key cache resized"); - } + if (write_cacheing) + puts("Key cache resized"); if (write_cacheing) puts("Write cacheing used"); if (write_cacheing) @@ -960,6 +953,7 @@ static void get_options(int argc, char **argv) } break; case 'e': /* maria_block_length */ + case 'E': if ((maria_block_size= atoi(++pos)) < MARIA_MIN_KEY_BLOCK_LENGTH || maria_block_size > MARIA_MAX_KEY_BLOCK_LENGTH) { @@ -968,15 +962,6 @@ static void get_options(int argc, char **argv) } maria_block_size= my_round_up_to_next_power(maria_block_size); break; - case 'E': /* maria_block_length */ - if ((pagecache_block_size=atoi(++pos)) < MARIA_MIN_KEY_BLOCK_LENGTH || - pagecache_block_size > MARIA_MAX_KEY_BLOCK_LENGTH) - { - fprintf(stderr,"Wrong pagecache_block_size\n"); - exit(1); - } - pagecache_block_size= my_round_up_to_next_power(pagecache_block_size); - break; case 'f': if ((first_key=atoi(++pos)) < 0 || first_key >= MARIA_KEYS) first_key=0; diff --git a/storage/maria/maria_chk.c b/storage/maria/maria_chk.c index a1921f91092..36101e7d002 100644 --- a/storage/maria/maria_chk.c +++ b/storage/maria/maria_chk.c @@ -39,8 +39,6 @@ static char **default_argv; static const char *load_default_groups[]= { "maria_chk", 0 }; static const char *set_collation_name, *opt_tmpdir; static CHARSET_INFO *set_collation; -static long opt_maria_block_size; -static long opt_pagecache_block_size; static const char *my_progname_short; static int stopwords_inited= 0; static MY_TMPDIR maria_chk_tmpdir; @@ -301,15 +299,6 @@ static struct my_option my_long_options[] = (gptr*) &check_param.use_buffers, (gptr*) &check_param.use_buffers, 0, GET_ULONG, REQUIRED_ARG, (long) USE_BUFFER_INIT, (long) MALLOC_OVERHEAD, (long) ~0L, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0}, - { "pagecache_block_size", OPT_KEY_CACHE_BLOCK_SIZE, "", - (gptr*) &opt_pagecache_block_size, - (gptr*) &opt_pagecache_block_size, 0, - GET_LONG, REQUIRED_ARG, MARIA_KEY_BLOCK_LENGTH, MARIA_MIN_KEY_BLOCK_LENGTH, - MARIA_MAX_KEY_BLOCK_LENGTH, 0, MARIA_MIN_KEY_BLOCK_LENGTH, 0}, - { "maria_block_size", OPT_MARIA_BLOCK_SIZE, "", - (gptr*) &opt_maria_block_size, (gptr*) &opt_maria_block_size, 0, - GET_LONG, REQUIRED_ARG, MARIA_KEY_BLOCK_LENGTH, MARIA_MIN_KEY_BLOCK_LENGTH, - MARIA_MAX_KEY_BLOCK_LENGTH, 0, MARIA_MIN_KEY_BLOCK_LENGTH, 0}, { "read_buffer_size", OPT_READ_BUFFER_SIZE, "", (gptr*) &check_param.read_buffer_length, (gptr*) &check_param.read_buffer_length, 0, GET_ULONG, REQUIRED_ARG, @@ -793,14 +782,12 @@ static void get_options(register int *argc,register char ***argv) exit(1); check_param.tmpdir=&maria_chk_tmpdir; - check_param.pagecache_block_size= opt_pagecache_block_size; if (set_collation_name) if (!(set_collation= get_charset_by_name(set_collation_name, MYF(MY_WME)))) exit(1); - maria_block_size=(uint) 1 << my_bit_log2(opt_maria_block_size); return; } /* get options */ @@ -873,6 +860,7 @@ static int maria_chk(HA_CHECK *param, my_string filename) share->options&= ~HA_OPTION_READ_ONLY_DATA; /* We are modifing it */ share->tot_locks-= share->r_locks; share->r_locks=0; + maria_block_size= share->base.block_size; if (share->data_file_type == BLOCK_RECORD && (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_FAST | T_STATISTICS | @@ -944,8 +932,7 @@ static int maria_chk(HA_CHECK *param, my_string filename) maria_test_if_almost_full(info) || info->s->state.header.file_version[3] != maria_file_magic[3] || (set_collation && - set_collation->number != share->state.header.language) || - maria_block_size != MARIA_KEY_BLOCK_LENGTH)) + set_collation->number != share->state.header.language))) { if (set_collation) param->language= set_collation->number; @@ -975,211 +962,217 @@ static int maria_chk(HA_CHECK *param, my_string filename) param->total_records+=info->state->records; param->total_deleted+=info->state->del; descript(param, info, filename); + maria_close(info); /* Should always succeed */ + return(0); } + + if (!stopwords_inited++) + ft_init_stopwords(); + + if (!(param->testflag & T_READONLY)) + lock_type = F_WRLCK; /* table is changed */ else + lock_type= F_RDLCK; + if (info->lock_type == F_RDLCK) + info->lock_type=F_UNLCK; /* Read only table */ + if (_ma_readinfo(info,lock_type,0)) + { + _ma_check_print_error(param,"Can't lock indexfile of '%s', error: %d", + filename,my_errno); + param->error_printed=0; + error= 1; + goto end2; + } + /* + _ma_readinfo() has locked the table. + We mark the table as locked (without doing file locks) to be able to + use functions that only works on locked tables (like row caching). + */ + maria_lock_database(info, F_EXTRA_LCK); + datafile= info->dfile.file; + if (init_pagecache(maria_pagecache, param->use_buffers, 0, 0, + maria_block_size) == 0) { - if (!stopwords_inited++) - ft_init_stopwords(); + _ma_check_print_error(param, "Can't initialize page cache with %lu memory", + (ulong) param->use_buffers); + error= 1; + goto end2; + } - if (!(param->testflag & T_READONLY)) - lock_type = F_WRLCK; /* table is changed */ - else - lock_type= F_RDLCK; - if (info->lock_type == F_RDLCK) - info->lock_type=F_UNLCK; /* Read only table */ - if (_ma_readinfo(info,lock_type,0)) + if (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX)) + { + if (param->testflag & T_REP_ANY) { - _ma_check_print_error(param,"Can't lock indexfile of '%s', error: %d", - filename,my_errno); - param->error_printed=0; - error= 1; - goto end2; + ulonglong tmp=share->state.key_map; + maria_copy_keys_active(share->state.key_map, share->base.keys, + param->keys_in_use); + if (tmp != share->state.key_map) + info->update|=HA_STATE_CHANGED; } - /* - _ma_readinfo() has locked the table. - We mark the table as locked (without doing file locks) to be able to - use functions that only works on locked tables (like row caching). - */ - maria_lock_database(info, F_EXTRA_LCK); - datafile= info->dfile.file; - - if (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX)) + if (rep_quick && + maria_chk_del(param, info, param->testflag & ~T_VERBOSE)) { - if (param->testflag & T_REP_ANY) - { - ulonglong tmp=share->state.key_map; - maria_copy_keys_active(share->state.key_map, share->base.keys, - param->keys_in_use); - if (tmp != share->state.key_map) - info->update|=HA_STATE_CHANGED; - } - if (rep_quick && - maria_chk_del(param, info, param->testflag & ~T_VERBOSE)) - { - if (param->testflag & T_FORCE_CREATE) - { - rep_quick=0; - _ma_check_print_info(param,"Creating new data file\n"); - } - else - { - error=1; - _ma_check_print_error(param, - "Quick-recover aborted; Run recovery without switch 'q'"); - } - } - if (!error) + if (param->testflag & T_FORCE_CREATE) { - if ((param->testflag & (T_REP_BY_SORT | T_REP_PARALLEL)) && - (maria_is_any_key_active(share->state.key_map) || - (rep_quick && !param->keys_in_use && !recreate)) && - maria_test_if_sort_rep(info, info->state->records, - info->s->state.key_map, - param->force_sort)) - { - if (param->testflag & T_REP_BY_SORT) - error=maria_repair_by_sort(param,info,filename,rep_quick); - else - error=maria_repair_parallel(param,info,filename,rep_quick); - state_updated=1; - } - else if (param->testflag & T_REP_ANY) - error=maria_repair(param, info,filename,rep_quick); + rep_quick=0; + _ma_check_print_info(param,"Creating new data file\n"); } - if (!error && param->testflag & T_SORT_RECORDS) + else { - /* - The data file is nowadays reopened in the repair code so we should - soon remove the following reopen-code - */ -#ifndef TO_BE_REMOVED - if (param->out_flag & O_NEW_DATA) - { /* Change temp file to org file */ - VOID(my_close(info->dfile.file, MYF(MY_WME))); /* Close new file */ - error|=maria_change_to_newfile(filename,MARIA_NAME_DEXT,DATA_TMP_EXT, - MYF(0)); - if (_ma_open_datafile(info,info->s, -1)) - error=1; - param->out_flag&= ~O_NEW_DATA; /* We are using new datafile */ - param->read_cache.file= info->dfile.file; - } -#endif - if (! error) - { - uint key; - /* - We can't update the index in maria_sort_records if we have a - prefix compressed or fulltext index - */ - my_bool update_index=1; - for (key=0 ; key < share->base.keys; key++) - if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY|HA_FULLTEXT)) - update_index=0; - - error=maria_sort_records(param,info,filename,param->opt_sort_key, - /* what is the following parameter for ? */ - (my_bool) !(param->testflag & T_REP), - update_index); - datafile= info->dfile.file; /* This is now locked */ - if (!error && !update_index) - { - if (param->verbose) - puts("Table had a compressed index; We must now recreate the index"); - error=maria_repair_by_sort(param,info,filename,1); - } - } + error=1; + _ma_check_print_error(param, + "Quick-recover aborted; Run recovery without switch 'q'"); } - if (!error && param->testflag & T_SORT_INDEX) - error=maria_sort_index(param,info,filename); - if (!error) - share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED | - STATE_CRASHED_ON_REPAIR); - else - maria_mark_crashed(info); } - else if ((param->testflag & T_CHECK) || !(param->testflag & T_AUTO_INC)) + if (!error) { - if (!(param->testflag & T_SILENT) || param->testflag & T_INFO) - printf("Checking MARIA file: %s\n",filename); - if (!(param->testflag & T_SILENT)) - printf("Data records: %7s Deleted blocks: %7s\n", - llstr(info->state->records,llbuff), - llstr(info->state->del,llbuff2)); - error =maria_chk_status(param,info); - maria_intersect_keys_active(share->state.key_map, param->keys_in_use); - error =maria_chk_size(param,info); - if (!error || !(param->testflag & (T_FAST | T_FORCE_CREATE))) - error|=maria_chk_del(param, info,param->testflag); - if ((!error || (!(param->testflag & (T_FAST | T_FORCE_CREATE)) && - !param->start_check_pos))) + if ((param->testflag & (T_REP_BY_SORT | T_REP_PARALLEL)) && + (maria_is_any_key_active(share->state.key_map) || + (rep_quick && !param->keys_in_use && !recreate)) && + maria_test_if_sort_rep(info, info->state->records, + info->s->state.key_map, + param->force_sort)) { - error|=maria_chk_key(param, info); - if (!error && (param->testflag & (T_STATISTICS | T_AUTO_INC))) - error=maria_update_state_info(param, info, - ((param->testflag & T_STATISTICS) ? - UPDATE_STAT : 0) | - ((param->testflag & T_AUTO_INC) ? - UPDATE_AUTO_INC : 0)); + if (param->testflag & T_REP_BY_SORT) + error=maria_repair_by_sort(param,info,filename,rep_quick); + else + error=maria_repair_parallel(param,info,filename,rep_quick); + state_updated=1; } - if ((!rep_quick && !error) || - !(param->testflag & (T_FAST | T_FORCE_CREATE))) - { - if (param->testflag & (T_EXTEND | T_MEDIUM)) - VOID(init_pagecache(maria_pagecache, param->use_buffers, 0, 0, - opt_pagecache_block_size)); - VOID(init_io_cache(¶m->read_cache,datafile, - (uint) param->read_buffer_length, - READ_CACHE, - (param->start_check_pos ? - param->start_check_pos : - share->pack.header_length), - 1, - MYF(MY_WME))); - maria_lock_memory(param); - if ((info->s->data_file_type != STATIC_RECORD) || - (param->testflag & (T_EXTEND | T_MEDIUM))) - error|=maria_chk_data_link(param, info, param->testflag & T_EXTEND); - error|=_ma_flush_blocks(param, share->pagecache, &share->kfile); - VOID(end_io_cache(¶m->read_cache)); + else if (param->testflag & T_REP_ANY) + error=maria_repair(param, info,filename,rep_quick); + } + if (!error && param->testflag & T_SORT_RECORDS) + { + /* + The data file is nowadays reopened in the repair code so we should + soon remove the following reopen-code + */ +#ifndef TO_BE_REMOVED + if (param->out_flag & O_NEW_DATA) + { /* Change temp file to org file */ + VOID(my_close(info->dfile.file, MYF(MY_WME))); /* Close new file */ + error|=maria_change_to_newfile(filename,MARIA_NAME_DEXT,DATA_TMP_EXT, + MYF(0)); + if (_ma_open_datafile(info,info->s, -1)) + error=1; + param->out_flag&= ~O_NEW_DATA; /* We are using new datafile */ + param->read_cache.file= info->dfile.file; } - if (!error) +#endif + if (! error) { - if ((share->state.changed & STATE_CHANGED) && - (param->testflag & T_UPDATE_STATE)) - info->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; - share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED | - STATE_CRASHED_ON_REPAIR); - } - else if (!maria_is_crashed(info) && - (param->testflag & T_UPDATE_STATE)) - { /* Mark crashed */ - maria_mark_crashed(info); - info->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; + uint key; + /* + We can't update the index in maria_sort_records if we have a + prefix compressed or fulltext index + */ + my_bool update_index=1; + for (key=0 ; key < share->base.keys; key++) + if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY|HA_FULLTEXT)) + update_index=0; + + error=maria_sort_records(param,info,filename,param->opt_sort_key, + /* what is the following parameter for ? */ + (my_bool) !(param->testflag & T_REP), + update_index); + datafile= info->dfile.file; /* This is now locked */ + if (!error && !update_index) + { + if (param->verbose) + puts("Table had a compressed index; We must now recreate the index"); + error=maria_repair_by_sort(param,info,filename,1); + } } } + if (!error && param->testflag & T_SORT_INDEX) + error=maria_sort_index(param,info,filename); + if (!error) + share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED | + STATE_CRASHED_ON_REPAIR); + else + maria_mark_crashed(info); + } + else if ((param->testflag & T_CHECK) || !(param->testflag & T_AUTO_INC)) + { + if (!(param->testflag & T_SILENT) || param->testflag & T_INFO) + printf("Checking MARIA file: %s\n",filename); + if (!(param->testflag & T_SILENT)) + printf("Data records: %7s Deleted blocks: %7s\n", + llstr(info->state->records,llbuff), + llstr(info->state->del,llbuff2)); + error =maria_chk_status(param,info); + maria_intersect_keys_active(share->state.key_map, param->keys_in_use); + error =maria_chk_size(param,info); + if (!error || !(param->testflag & (T_FAST | T_FORCE_CREATE))) + error|=maria_chk_del(param, info,param->testflag); + if ((!error || (!(param->testflag & (T_FAST | T_FORCE_CREATE)) && + !param->start_check_pos))) + { + error|=maria_chk_key(param, info); + if (!error && (param->testflag & (T_STATISTICS | T_AUTO_INC))) + error=maria_update_state_info(param, info, + ((param->testflag & T_STATISTICS) ? + UPDATE_STAT : 0) | + ((param->testflag & T_AUTO_INC) ? + UPDATE_AUTO_INC : 0)); + } + if ((!rep_quick && !error) || + !(param->testflag & (T_FAST | T_FORCE_CREATE))) + { + VOID(init_io_cache(¶m->read_cache,datafile, + (uint) param->read_buffer_length, + READ_CACHE, + (param->start_check_pos ? + param->start_check_pos : + share->pack.header_length), + 1, + MYF(MY_WME))); + maria_lock_memory(param); + if ((info->s->data_file_type != STATIC_RECORD) || + (param->testflag & (T_EXTEND | T_MEDIUM))) + error|=maria_chk_data_link(param, info, param->testflag & T_EXTEND); + error|=_ma_flush_blocks(param, share->pagecache, &share->kfile); + VOID(end_io_cache(¶m->read_cache)); + } + if (!error) + { + if ((share->state.changed & STATE_CHANGED) && + (param->testflag & T_UPDATE_STATE)) + info->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; + share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED | + STATE_CRASHED_ON_REPAIR); + } + else if (!maria_is_crashed(info) && + (param->testflag & T_UPDATE_STATE)) + { /* Mark crashed */ + maria_mark_crashed(info); + info->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; + } } + if ((param->testflag & T_AUTO_INC) || ((param->testflag & T_REP_ANY) && info->s->base.auto_key)) _ma_update_auto_increment_key(param, info, (my_bool) !test(param->testflag & T_AUTO_INC)); - if (!(param->testflag & T_DESCRIPT)) - { - if (info->update & HA_STATE_CHANGED && ! (param->testflag & T_READONLY)) - error|=maria_update_state_info(param, info, - UPDATE_OPEN_COUNT | - (((param->testflag & T_REP_ANY) ? - UPDATE_TIME : 0) | - (state_updated ? UPDATE_STAT : 0) | - ((param->testflag & T_SORT_RECORDS) ? - UPDATE_SORT : 0))); - info->update&= ~HA_STATE_CHANGED; - } + if (info->update & HA_STATE_CHANGED && ! (param->testflag & T_READONLY)) + error|=maria_update_state_info(param, info, + UPDATE_OPEN_COUNT | + (((param->testflag & T_REP_ANY) ? + UPDATE_TIME : 0) | + (state_updated ? UPDATE_STAT : 0) | + ((param->testflag & T_SORT_RECORDS) ? + UPDATE_SORT : 0))); + info->update&= ~HA_STATE_CHANGED; maria_lock_database(info, F_UNLCK); + end2: + end_pagecache(maria_pagecache, 1); if (maria_close(info)) { - _ma_check_print_error(param,"%d when closing MARIA-table '%s'",my_errno,filename); + _ma_check_print_error(param,"%d when closing MARIA-table '%s'", + my_errno,filename); DBUG_RETURN(1); } if (error == 0) @@ -1533,8 +1526,6 @@ static int maria_sort_records(HA_CHECK *param, if (share->state.key_root[sort_key] == HA_OFFSET_ERROR) DBUG_RETURN(0); /* Nothing to do */ - init_pagecache(maria_pagecache, param->use_buffers, - 0, 0, opt_pagecache_block_size); if (init_io_cache(&info->rec_cache,-1,(uint) param->write_buffer_length, WRITE_CACHE,share->pack.header_length,1, MYF(MY_WME | MY_WAIT_IF_FULL))) diff --git a/storage/maria/maria_def.h b/storage/maria/maria_def.h index 4f3024bc427..5e56b0edc5a 100644 --- a/storage/maria/maria_def.h +++ b/storage/maria/maria_def.h @@ -190,9 +190,9 @@ typedef struct st_maria_file_bitmap { uchar *map; ulonglong page; /* Page number for current bitmap */ - PAGECACHE_FILE page_cache; uint used_size; /* Size of bitmap head that is not 0 */ - my_bool changed; /* Set to 1 if page needs to be flushed */ + my_bool changed; /* 1 if page needs to be flushed */ + PAGECACHE_FILE file; /* datafile where bitmap is stored */ #ifdef THREAD pthread_mutex_t bitmap_lock; diff --git a/storage/maria/maria_pack.c b/storage/maria/maria_pack.c index 449b6bf7d59..f1b3903c944 100644 --- a/storage/maria/maria_pack.c +++ b/storage/maria/maria_pack.c @@ -505,13 +505,21 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) trees=fields=0; huff_trees=0; huff_counts=0; + maria_block_size= isam_file->s->block_size; /* Create temporary or join file */ - if (backup) VOID(fn_format(org_name,isam_file->filename,"",MARIA_NAME_DEXT,2)); else VOID(fn_format(org_name,isam_file->filename,"",MARIA_NAME_DEXT,2+4+16)); + + if (init_pagecache(maria_pagecache, MARIA_MIN_PAGE_CACHE_SIZE, 0, 0, + maria_block_size) == 0) + { + fprintf(stderr, "Can't initialize page cache\n"); + goto err; + } + if (!test_only && result_table) { /* Make a new indexfile based on first file in list */ @@ -681,7 +689,7 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) { error|=my_close(isam_file->dfile.file, MYF(MY_WME)); isam_file->dfile.file= -1; /* Tell maria_close file is closed */ - isam_file->s->bitmap.file= -1; + isam_file->s->bitmap.file.file= -1; } } @@ -751,6 +759,7 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) DBUG_RETURN(0); err: + end_pagecache(maria_pagecache, 1); free_counts_and_tree_and_queue(huff_trees,trees,huff_counts,fields); if (new_file >= 0) VOID(my_close(new_file,MYF(0))); |