Commit 10065404 authored by Michael Widenius's avatar Michael Widenius

Fixes lp:805930 Sysbench breaks on multiple table test with MariaDB 5.2.7 + Aria

The bug happens when one uses MAX_ROWS=# with Aria & row_format=page and one insert more than # rows.


mysql-test/mysql-test-run.pl:
  Ignore table is full error messages
mysql-test/suite/maria/r/max_length.result:
  Test case for 'Table is full'
mysql-test/suite/maria/t/max_length.test:
  Test case for 'Table is full'
storage/maria/ma_bitmap.c:
  Ensure that we don't allocate bits outside of max_data_file_size.
  Adjust max_data_file_size based on bitmap alignments.
  Backport fix to adjust wrong first_bitmap_with_space.
storage/maria/ma_blockrec.c:
  Calculate value of max_data_file_length
storage/maria/ma_blockrec.h:
  Updated prototype for _ma_bitmap_init()
storage/maria/ma_check.c:
  Give warnings if file sizes are above max file sizes.
  Give more warnings in case of errors.
  Have maria_chk write if table is recreated.
storage/maria/ma_create.c:
  Better calculation of max_data_file_length and thus data pointer length.
  Fixes some wrong pointer lengths when using MAX_ROWS=#
storage/maria/ma_open.c:
  Removed duplicate assigment.
  Use block size from file instead of global variable.
storage/maria/maria_chk.c:
  Remove -1 from printed file length
storage/maria/maria_def.h:
  Update struct st_maria_file_bitmap
parent 3c97c9c9
...@@ -4435,6 +4435,7 @@ sub extract_warning_lines ($) { ...@@ -4435,6 +4435,7 @@ sub extract_warning_lines ($) {
qr|Table \./test/bug53592 has a primary key in InnoDB data dictionary, but not in MySQL|, qr|Table \./test/bug53592 has a primary key in InnoDB data dictionary, but not in MySQL|,
qr|mysqld: Table '\./mtr/test_suppressions' is marked as crashed and should be repaired|, qr|mysqld: Table '\./mtr/test_suppressions' is marked as crashed and should be repaired|,
qr|InnoDB: Error: table 'test/bug39438'|, qr|InnoDB: Error: table 'test/bug39438'|,
qr|table.*is full|,
); );
my $matched_lines= []; my $matched_lines= [];
......
drop table if exists t1,t2;
Warnings:
Note 1051 Unknown table 't1'
Note 1051 Unknown table 't2'
create table t1 (id int(10) unsigned not null auto_increment primary key, v varchar(1000), b blob) row_format=page max_rows=2 engine=aria;
create table t2 (id int(10) unsigned not null auto_increment primary key, v varchar(1000), b blob) row_format=page max_rows=20000000 engine=aria;
lock tables t1 write,t2 write;
show table status like "t_";
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
t1 MARIA 10 Page 0 0 8192 268320768 8192 0 1 # # # latin1_swedish_ci NULL max_rows=2 row_format=PAGE
t2 MARIA 10 Page 0 0 8192 17592186011648 8192 0 1 # # # latin1_swedish_ci NULL max_rows=20000000 row_format=PAGE
insert into t1 values(null, repeat("ab",100),repeat("def",1000));
insert into t1 values(null, repeat("de",200),repeat("ghi",2000));
insert into t1 values(null, repeat("fe",300),repeat("ghi",3000));
insert into t1 values(null, repeat("gh",400),repeat("jkl",10000));
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
unlock tables;
insert into t1 (v,b) select v,b from t2;
ERROR HY000: The table 't1' is full
check table t1;
Table Op Msg_type Msg_text
test.t1 check warning Datafile is almost full, 268230656 of 268320768 used
test.t1 check status OK
insert into t1 values(null, repeat("gh",400),repeat("jkl",10000));
ERROR HY000: The table 't1' is full
check table t1;
Table Op Msg_type Msg_text
test.t1 check warning Datafile is almost full, 268230656 of 268320768 used
test.t1 check status OK
truncate table t1;
insert into t1 (v,b) select v,b from t2;
ERROR HY000: The table 't1' is full
check table t1;
Table Op Msg_type Msg_text
test.t1 check warning Datafile is almost full, 268230656 of 268320768 used
test.t1 check status OK
drop table t1,t2;
# Test max data length
# This test will use around 1.3G of disk space!
--source include/have_maria.inc
--source include/big_test.inc
drop table if exists t1,t2;
create table t1 (id int(10) unsigned not null auto_increment primary key, v varchar(1000), b blob) row_format=page max_rows=2 engine=aria;
create table t2 (id int(10) unsigned not null auto_increment primary key, v varchar(1000), b blob) row_format=page max_rows=20000000 engine=aria;
lock tables t1 write,t2 write;
--replace_column 12 # 13 # 14 #
show table status like "t_";
insert into t1 values(null, repeat("ab",100),repeat("def",1000));
insert into t1 values(null, repeat("de",200),repeat("ghi",2000));
insert into t1 values(null, repeat("fe",300),repeat("ghi",3000));
insert into t1 values(null, repeat("gh",400),repeat("jkl",10000));
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
insert into t1 (v,b) select v,b from t2;
insert into t2 (v,b) select v,b from t1;
unlock tables;
--error ER_RECORD_FILE_FULL
insert into t1 (v,b) select v,b from t2;
check table t1;
--error ER_RECORD_FILE_FULL
insert into t1 values(null, repeat("gh",400),repeat("jkl",10000));
check table t1;
# Test also with inserting into empty table (different code)
truncate table t1;
--error ER_RECORD_FILE_FULL
insert into t1 (v,b) select v,b from t2;
check table t1;
drop table t1,t2;
...@@ -209,7 +209,10 @@ static inline my_bool write_changed_bitmap(MARIA_SHARE *share, ...@@ -209,7 +209,10 @@ static inline my_bool write_changed_bitmap(MARIA_SHARE *share,
SYNOPSIS SYNOPSIS
_ma_bitmap_init() _ma_bitmap_init()
share Share handler share Share handler
file data file handler file Data file handler
last_page Pointer to last page (max_file_size) that needs to be
mapped by the bitmap. This is adjusted to bitmap
alignment.
NOTES NOTES
This is called the first time a file is opened. This is called the first time a file is opened.
...@@ -219,12 +222,14 @@ static inline my_bool write_changed_bitmap(MARIA_SHARE *share, ...@@ -219,12 +222,14 @@ static inline my_bool write_changed_bitmap(MARIA_SHARE *share,
1 error 1 error
*/ */
my_bool _ma_bitmap_init(MARIA_SHARE *share, File file) my_bool _ma_bitmap_init(MARIA_SHARE *share, File file,
pgcache_page_no_t *last_page)
{ {
uint aligned_bit_blocks; uint aligned_bit_blocks;
uint max_page_size; uint max_page_size;
MARIA_FILE_BITMAP *bitmap= &share->bitmap; MARIA_FILE_BITMAP *bitmap= &share->bitmap;
uint size= share->block_size; uint size= share->block_size;
pgcache_page_no_t first_bitmap_with_space;
#ifndef DBUG_OFF #ifndef DBUG_OFF
/* We want to have a copy of the bitmap to be able to print differences */ /* We want to have a copy of the bitmap to be able to print differences */
size*= 2; size*= 2;
...@@ -241,7 +246,7 @@ my_bool _ma_bitmap_init(MARIA_SHARE *share, File file) ...@@ -241,7 +246,7 @@ my_bool _ma_bitmap_init(MARIA_SHARE *share, File file)
/* Size needs to be aligned on 6 */ /* Size needs to be aligned on 6 */
aligned_bit_blocks= (share->block_size - PAGE_SUFFIX_SIZE) / 6; aligned_bit_blocks= (share->block_size - PAGE_SUFFIX_SIZE) / 6;
bitmap->total_size= aligned_bit_blocks * 6; bitmap->max_total_size= bitmap->total_size= aligned_bit_blocks * 6;
/* /*
In each 6 bytes, we have 6*8/3 = 16 pages covered In each 6 bytes, we have 6*8/3 = 16 pages covered
The +1 is to add the bitmap page, as this doesn't have to be covered The +1 is to add the bitmap page, as this doesn't have to be covered
...@@ -266,13 +271,34 @@ my_bool _ma_bitmap_init(MARIA_SHARE *share, File file) ...@@ -266,13 +271,34 @@ my_bool _ma_bitmap_init(MARIA_SHARE *share, File file)
pthread_mutex_init(&share->bitmap.bitmap_lock, MY_MUTEX_INIT_SLOW); pthread_mutex_init(&share->bitmap.bitmap_lock, MY_MUTEX_INIT_SLOW);
pthread_cond_init(&share->bitmap.bitmap_cond, 0); pthread_cond_init(&share->bitmap.bitmap_cond, 0);
first_bitmap_with_space= share->state.first_bitmap_with_space;
_ma_bitmap_reset_cache(share); _ma_bitmap_reset_cache(share);
if (share->state.first_bitmap_with_space == ~(pgcache_page_no_t) 0) /*
The bitmap used to map the file are aligned on 6 bytes. We now
calculate the max file size that can be used by the bitmap. This
is needed to get ma_info() give a true file size so that the user can
estimate if there is still space free for records in the file.
*/
{ {
/* Start scanning for free space from start of file */ pgcache_page_no_t last_bitmap_page;
share->state.first_bitmap_with_space = 0; ulong blocks, bytes;
last_bitmap_page= *last_page - *last_page % bitmap->pages_covered;
blocks= *last_page - last_bitmap_page;
bytes= (blocks * 3) / 8; /* 3 bit per page / 8 bits per byte */
/* Size needs to be aligned on 6 */
bytes/= 6;
bytes*= 6;
bitmap->last_bitmap_page= last_bitmap_page;
bitmap->last_total_size= bytes;
*last_page= ((last_bitmap_page + bytes*8/3));
} }
/* Restore first_bitmap_with_space if it's resonable */
if (first_bitmap_with_space <= (share->state.state.data_file_length /
share->block_size))
share->state.first_bitmap_with_space= first_bitmap_with_space;
return 0; return 0;
} }
...@@ -616,7 +642,7 @@ void _ma_bitmap_delete_all(MARIA_SHARE *share) ...@@ -616,7 +642,7 @@ void _ma_bitmap_delete_all(MARIA_SHARE *share)
bzero(bitmap->map, bitmap->block_size); bzero(bitmap->map, bitmap->block_size);
bitmap->changed= 1; bitmap->changed= 1;
bitmap->page= 0; bitmap->page= 0;
bitmap->used_size= bitmap->total_size; bitmap->used_size= bitmap->total_size= bitmap->max_total_size;
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -646,13 +672,20 @@ void _ma_bitmap_reset_cache(MARIA_SHARE *share) ...@@ -646,13 +672,20 @@ void _ma_bitmap_reset_cache(MARIA_SHARE *share)
We can't read a page yet, as in some case we don't have an active We can't read a page yet, as in some case we don't have an active
page cache yet. page cache yet.
Pretend we have a dummy, full and not changed bitmap page in memory. Pretend we have a dummy, full and not changed bitmap page in memory.
We set bitmap->page to a value so that if we use it in
move_to_next_bitmap() it will point to page 0.
(This can only happen if writing to a bitmap page fails)
*/ */
bitmap->page= ~(ulonglong) 0; bitmap->page= ((pgcache_page_no_t) 0) - bitmap->pages_covered;
bitmap->used_size= bitmap->total_size; bitmap->used_size= bitmap->total_size= bitmap->max_total_size;
bfill(bitmap->map, share->block_size, 255); bfill(bitmap->map, share->block_size, 255);
#ifndef DBUG_OFF #ifndef DBUG_OFF
memcpy(bitmap->map + bitmap->block_size, bitmap->map, bitmap->block_size); memcpy(bitmap->map + bitmap->block_size, bitmap->map, bitmap->block_size);
#endif #endif
/* Start scanning for free space from start of file */
share->state.first_bitmap_with_space = 0;
} }
} }
...@@ -920,6 +953,20 @@ void _ma_get_bitmap_description(MARIA_FILE_BITMAP *bitmap, ...@@ -920,6 +953,20 @@ void _ma_get_bitmap_description(MARIA_FILE_BITMAP *bitmap,
} }
/*
Adjust bitmap->total_size to not go over max_data_file_size
*/
static void adjust_total_size(MARIA_HA *info, pgcache_page_no_t page)
{
MARIA_FILE_BITMAP *bitmap= &info->s->bitmap;
if (page < bitmap->last_bitmap_page)
bitmap->total_size= bitmap->max_total_size; /* Use all bits in bitmap */
else
bitmap->total_size= bitmap->last_total_size;
}
/*************************************************************************** /***************************************************************************
Reading & writing bitmap pages Reading & writing bitmap pages
***************************************************************************/ ***************************************************************************/
...@@ -956,12 +1003,16 @@ static my_bool _ma_read_bitmap_page(MARIA_HA *info, ...@@ -956,12 +1003,16 @@ static my_bool _ma_read_bitmap_page(MARIA_HA *info,
DBUG_ASSERT(!bitmap->changed); DBUG_ASSERT(!bitmap->changed);
bitmap->page= page; bitmap->page= page;
if (((page + 1) * bitmap->block_size) > share->state.state.data_file_length) if ((page + 1) * bitmap->block_size > share->state.state.data_file_length)
{ {
/* Inexistent or half-created page */ /* Inexistent or half-created page */
res= _ma_bitmap_create_missing(info, bitmap, page); res= _ma_bitmap_create_missing(info, bitmap, page);
if (!res)
adjust_total_size(info, page);
DBUG_RETURN(res); DBUG_RETURN(res);
} }
adjust_total_size(info, page);
bitmap->used_size= bitmap->total_size; bitmap->used_size= bitmap->total_size;
DBUG_ASSERT(share->pagecache->block_size == bitmap->block_size); DBUG_ASSERT(share->pagecache->block_size == bitmap->block_size);
res= pagecache_read(share->pagecache, res= pagecache_read(share->pagecache,
...@@ -1045,14 +1096,18 @@ static my_bool move_to_next_bitmap(MARIA_HA *info, MARIA_FILE_BITMAP *bitmap) ...@@ -1045,14 +1096,18 @@ static my_bool move_to_next_bitmap(MARIA_HA *info, MARIA_FILE_BITMAP *bitmap)
MARIA_STATE_INFO *state= &info->s->state; MARIA_STATE_INFO *state= &info->s->state;
DBUG_ENTER("move_to_next_bitmap"); 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) state->first_bitmap_with_space != page)
{ {
page= state->first_bitmap_with_space; 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 else
{
page+= bitmap->pages_covered; page+= bitmap->pages_covered;
DBUG_ASSERT(page % bitmap->pages_covered == 0);
}
DBUG_RETURN(_ma_change_bitmap_page(info, bitmap, page)); DBUG_RETURN(_ma_change_bitmap_page(info, bitmap, page));
} }
...@@ -2933,6 +2988,11 @@ static my_bool _ma_bitmap_create_missing(MARIA_HA *info, ...@@ -2933,6 +2988,11 @@ static my_bool _ma_bitmap_create_missing(MARIA_HA *info,
/* First (in offset order) bitmap page to create */ /* First (in offset order) bitmap page to create */
if (data_file_length < block_size) if (data_file_length < block_size)
goto err; /* corrupted, should have first bitmap page */ goto err; /* corrupted, should have first bitmap page */
if (page * block_size >= share->base.max_data_file_length)
{
my_errno= HA_ERR_RECORD_FILE_FULL;
goto err;
}
from= (data_file_length / block_size - 1) / bitmap->pages_covered + 1; from= (data_file_length / block_size - 1) / bitmap->pages_covered + 1;
from*= bitmap->pages_covered; from*= bitmap->pages_covered;
......
...@@ -414,14 +414,29 @@ void _ma_init_block_record_data(void) ...@@ -414,14 +414,29 @@ void _ma_init_block_record_data(void)
my_bool _ma_once_init_block_record(MARIA_SHARE *share, File data_file) my_bool _ma_once_init_block_record(MARIA_SHARE *share, File data_file)
{ {
my_bool res;
pgcache_page_no_t last_page;
/*
First calculate the max file length with can have with a pointer of size
rec_reflength.
share->base.max_data_file_length= The 'rec_reflength - 1' is because one byte is used for row
(((ulonglong) 1 << ((share->base.rec_reflength-1)*8))-1) * position withing the page.
share->block_size; The /2 comes from _ma_transaction_recpos_to_keypos() where we use
the lowest bit to mark if there is a transid following the rownr.
*/
last_page= ((ulonglong) 1 << ((share->base.rec_reflength-1)*8))/2;
if (!last_page) /* Overflow; set max size */
last_page= ~(pgcache_page_no_t) 0;
res= _ma_bitmap_init(share, data_file, &last_page);
share->base.max_data_file_length= _ma_safe_mul(last_page + 1,
share->block_size);
#if SIZEOF_OFF_T == 4 #if SIZEOF_OFF_T == 4
set_if_smaller(share->base.max_data_file_length, INT_MAX32); set_if_smaller(share->base.max_data_file_length, INT_MAX32);
#endif #endif
return _ma_bitmap_init(share, data_file); return res;
} }
...@@ -5170,7 +5185,7 @@ my_bool _ma_scan_init_block_record(MARIA_HA *info) ...@@ -5170,7 +5185,7 @@ my_bool _ma_scan_init_block_record(MARIA_HA *info)
(uchar *) my_malloc(share->block_size * 2, MYF(MY_WME)))))) (uchar *) my_malloc(share->block_size * 2, MYF(MY_WME))))))
DBUG_RETURN(1); DBUG_RETURN(1);
info->scan.page_buff= info->scan.bitmap_buff + share->block_size; info->scan.page_buff= info->scan.bitmap_buff + share->block_size;
info->scan.bitmap_end= info->scan.bitmap_buff + share->bitmap.total_size; info->scan.bitmap_end= info->scan.bitmap_buff + share->bitmap.max_total_size;
/* Set scan variables to get _ma_scan_block() to start with reading bitmap */ /* Set scan variables to get _ma_scan_block() to start with reading bitmap */
info->scan.number_of_rows= 0; info->scan.number_of_rows= 0;
......
...@@ -187,7 +187,8 @@ maria_page_get_lsn(uchar *page, pgcache_page_no_t page_no, uchar* data_ptr); ...@@ -187,7 +187,8 @@ maria_page_get_lsn(uchar *page, pgcache_page_no_t page_no, uchar* data_ptr);
/* ma_bitmap.c */ /* ma_bitmap.c */
extern const char *bits_to_txt[]; extern const char *bits_to_txt[];
my_bool _ma_bitmap_init(MARIA_SHARE *share, File file); my_bool _ma_bitmap_init(MARIA_SHARE *share, File file,
pgcache_page_no_t *last_page);
my_bool _ma_bitmap_end(MARIA_SHARE *share); my_bool _ma_bitmap_end(MARIA_SHARE *share);
my_bool _ma_bitmap_flush(MARIA_SHARE *share); my_bool _ma_bitmap_flush(MARIA_SHARE *share);
my_bool _ma_bitmap_flush_all(MARIA_SHARE *share); my_bool _ma_bitmap_flush_all(MARIA_SHARE *share);
......
...@@ -405,26 +405,34 @@ int maria_chk_size(HA_CHECK *param, register MARIA_HA *info) ...@@ -405,26 +405,34 @@ int maria_chk_size(HA_CHECK *param, register MARIA_HA *info)
size= my_seek(share->kfile.file, 0L, MY_SEEK_END, MYF(MY_THREADSAFE)); size= my_seek(share->kfile.file, 0L, MY_SEEK_END, MYF(MY_THREADSAFE));
if ((skr=(my_off_t) share->state.state.key_file_length) != size) if ((skr=(my_off_t) share->state.state.key_file_length) != size)
{ {
/* Don't give error if file generated by mariapack */ /* Don't give error if file generated by maria_pack */
if (skr > size && maria_is_any_key_active(share->state.key_map)) if (skr > size && maria_is_any_key_active(share->state.key_map))
{ {
error=1; error=1;
_ma_check_print_error(param, _ma_check_print_error(param,
"Size of indexfile is: %-8s Should be: %s", "Size of indexfile is: %-8s Should be: %s",
llstr(size,buff), llstr(skr,buff2)); llstr(size,buff), llstr(skr,buff2));
share->state.state.key_file_length= size;
} }
else if (!(param->testflag & T_VERY_SILENT)) else if (!(param->testflag & T_VERY_SILENT))
_ma_check_print_warning(param, _ma_check_print_warning(param,
"Size of indexfile is: %-8s Should be: %s", "Size of indexfile is: %-8s Should be: %s",
llstr(size,buff), llstr(skr,buff2)); llstr(size,buff), llstr(skr,buff2));
} }
if (!(param->testflag & T_VERY_SILENT) && if (size > share->base.max_key_file_length)
{
_ma_check_print_warning(param,
"Size of indexfile is: %-8s which is bigger than max indexfile size: %s",
ullstr(size,buff),
ullstr(share->base.max_key_file_length, buff2));
}
else if (!(param->testflag & T_VERY_SILENT) &&
! (share->options & HA_OPTION_COMPRESS_RECORD) && ! (share->options & HA_OPTION_COMPRESS_RECORD) &&
ulonglong2double(share->state.state.key_file_length) > ulonglong2double(share->state.state.key_file_length) >
ulonglong2double(share->base.margin_key_file_length)*0.9) ulonglong2double(share->base.margin_key_file_length)*0.9)
_ma_check_print_warning(param,"Keyfile is almost full, %10s of %10s used", _ma_check_print_warning(param,"Keyfile is almost full, %10s of %10s used",
llstr(share->state.state.key_file_length,buff), llstr(share->state.state.key_file_length,buff),
llstr(share->base.max_key_file_length-1,buff)); llstr(share->base.max_key_file_length,buff));
size= my_seek(info->dfile.file, 0L, MY_SEEK_END, MYF(0)); size= my_seek(info->dfile.file, 0L, MY_SEEK_END, MYF(0));
skr=(my_off_t) share->state.state.data_file_length; skr=(my_off_t) share->state.state.data_file_length;
...@@ -437,9 +445,9 @@ int maria_chk_size(HA_CHECK *param, register MARIA_HA *info) ...@@ -437,9 +445,9 @@ int maria_chk_size(HA_CHECK *param, register MARIA_HA *info)
#endif #endif
if (skr != size) if (skr != size)
{ {
share->state.state.data_file_length=size; /* Skip other errors */
if (skr > size && skr != size + MEMMAP_EXTRA_MARGIN) if (skr > size && skr != size + MEMMAP_EXTRA_MARGIN)
{ {
share->state.state.data_file_length=size; /* Skip other errors */
error=1; error=1;
_ma_check_print_error(param,"Size of datafile is: %-9s Should be: %s", _ma_check_print_error(param,"Size of datafile is: %-9s Should be: %s",
llstr(size,buff), llstr(skr,buff2)); llstr(size,buff), llstr(skr,buff2));
...@@ -452,13 +460,19 @@ int maria_chk_size(HA_CHECK *param, register MARIA_HA *info) ...@@ -452,13 +460,19 @@ int maria_chk_size(HA_CHECK *param, register MARIA_HA *info)
llstr(size,buff), llstr(skr,buff2)); llstr(size,buff), llstr(skr,buff2));
} }
} }
if (!(param->testflag & T_VERY_SILENT) && if (size > share->base.max_data_file_length)
{
_ma_check_print_warning(param,
"Size of datafile is: %-8s which is bigger than max datafile size: %s",
ullstr(size,buff),
ullstr(share->base.max_data_file_length, buff2));
} else if (!(param->testflag & T_VERY_SILENT) &&
!(share->options & HA_OPTION_COMPRESS_RECORD) && !(share->options & HA_OPTION_COMPRESS_RECORD) &&
ulonglong2double(share->state.state.data_file_length) > ulonglong2double(share->state.state.data_file_length) >
(ulonglong2double(share->base.max_data_file_length)*0.9)) (ulonglong2double(share->base.max_data_file_length)*0.9))
_ma_check_print_warning(param, "Datafile is almost full, %10s of %10s used", _ma_check_print_warning(param, "Datafile is almost full, %10s of %10s used",
llstr(share->state.state.data_file_length,buff), llstr(share->state.state.data_file_length,buff),
llstr(share->base.max_data_file_length-1,buff2)); llstr(share->base.max_data_file_length,buff2));
DBUG_RETURN(error); DBUG_RETURN(error);
} /* maria_chk_size */ } /* maria_chk_size */
...@@ -1967,8 +1981,8 @@ static int check_block_record(HA_CHECK *param, MARIA_HA *info, int extend, ...@@ -1967,8 +1981,8 @@ static int check_block_record(HA_CHECK *param, MARIA_HA *info, int extend,
data= bitmap_buff + offset_page / 8; data= bitmap_buff + offset_page / 8;
bitmap_pattern= uint2korr(data); bitmap_pattern= uint2korr(data);
if (((bitmap_pattern >> offset)) || if (((bitmap_pattern >> offset)) ||
(data + 2 < bitmap_buff + share->bitmap.total_size && (data + 2 < bitmap_buff + share->bitmap.max_total_size &&
_ma_check_if_zero(data+2, bitmap_buff + share->bitmap.total_size - _ma_check_if_zero(data+2, bitmap_buff + share->bitmap.max_total_size -
data - 2))) data - 2)))
{ {
ulonglong bitmap_page; ulonglong bitmap_page;
...@@ -2074,14 +2088,14 @@ int maria_chk_data_link(HA_CHECK *param, MARIA_HA *info, my_bool extend) ...@@ -2074,14 +2088,14 @@ int maria_chk_data_link(HA_CHECK *param, MARIA_HA *info, my_bool extend)
llstr(share->state.state.records,llbuff2)); llstr(share->state.state.records,llbuff2));
error=1; error=1;
} }
else if (param->record_checksum && if (param->record_checksum &&
param->record_checksum != param->tmp_record_checksum) param->record_checksum != param->tmp_record_checksum)
{ {
_ma_check_print_error(param, _ma_check_print_error(param,
"Key pointers and record positions doesn't match"); "Key pointers and record positions doesn't match");
error=1; error=1;
} }
else if (param->glob_crc != share->state.state.checksum && if (param->glob_crc != share->state.state.checksum &&
(share->options & (share->options &
(HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD))) (HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD)))
{ {
...@@ -2090,7 +2104,7 @@ int maria_chk_data_link(HA_CHECK *param, MARIA_HA *info, my_bool extend) ...@@ -2090,7 +2104,7 @@ int maria_chk_data_link(HA_CHECK *param, MARIA_HA *info, my_bool extend)
"stored in the index file"); "stored in the index file");
error=1; error=1;
} }
else if (!extend) if (!extend)
{ {
uint key; uint key;
for (key=0 ; key < share->base.keys; key++) for (key=0 ; key < share->base.keys; key++)
...@@ -5256,7 +5270,10 @@ int _ma_sort_write_record(MARIA_SORT_PARAM *sort_param) ...@@ -5256,7 +5270,10 @@ int _ma_sort_write_record(MARIA_SORT_PARAM *sort_param)
if ((sort_param->current_filepos= if ((sort_param->current_filepos=
(*share->write_record_init)(info, sort_param->record)) == (*share->write_record_init)(info, sort_param->record)) ==
HA_OFFSET_ERROR) HA_OFFSET_ERROR)
{
_ma_check_print_error(param, "%d when writing to datafile", my_errno);
DBUG_RETURN(1); DBUG_RETURN(1);
}
/* Pointer to end of file */ /* Pointer to end of file */
sort_param->filepos= share->state.state.data_file_length; sort_param->filepos= share->state.state.data_file_length;
break; break;
...@@ -5876,6 +5893,9 @@ int maria_recreate_table(HA_CHECK *param, MARIA_HA **org_info, char *filename) ...@@ -5876,6 +5893,9 @@ int maria_recreate_table(HA_CHECK *param, MARIA_HA **org_info, char *filename)
MARIA_CREATE_INFO create_info; MARIA_CREATE_INFO create_info;
DBUG_ENTER("maria_recreate_table"); DBUG_ENTER("maria_recreate_table");
if ((!(param->testflag & T_SILENT)))
printf("Recreating table '%s'\n", param->isam_file_name);
error=1; /* Default error */ error=1; /* Default error */
info= **org_info; info= **org_info;
status_info= (*org_info)->state[0]; status_info= (*org_info)->state[0];
......
...@@ -319,7 +319,15 @@ int maria_create(const char *name, enum data_file_type datafile_type, ...@@ -319,7 +319,15 @@ int maria_create(const char *name, enum data_file_type datafile_type,
(~(ulonglong) 0)/ci->max_rows < (ulonglong) pack_reclength) (~(ulonglong) 0)/ci->max_rows < (ulonglong) pack_reclength)
ci->data_file_length= ~(ulonglong) 0; ci->data_file_length= ~(ulonglong) 0;
else else
ci->data_file_length=(ulonglong) ci->max_rows*pack_reclength; {
ci->data_file_length= _ma_safe_mul(ci->max_rows, pack_reclength);
if (datafile_type == BLOCK_RECORD)
{
/* Assume that blocks are only half full (very pessimistic!) */
ci->data_file_length= _ma_safe_mul(ci->data_file_length, 2);
set_if_bigger(ci->data_file_length, maria_block_size*2);
}
}
} }
else if (!ci->max_rows) else if (!ci->max_rows)
{ {
...@@ -331,7 +339,7 @@ int maria_create(const char *name, enum data_file_type datafile_type, ...@@ -331,7 +339,7 @@ int maria_create(const char *name, enum data_file_type datafile_type,
ulonglong data_file_length= ci->data_file_length; ulonglong data_file_length= ci->data_file_length;
if (!data_file_length) if (!data_file_length)
data_file_length= ((((ulonglong) 1 << ((BLOCK_RECORD_POINTER_SIZE-1) * data_file_length= ((((ulonglong) 1 << ((BLOCK_RECORD_POINTER_SIZE-1) *
8)) -1) * maria_block_size); 8))/2 -1) * maria_block_size);
if (rows_per_page > 0) if (rows_per_page > 0)
{ {
set_if_smaller(rows_per_page, MAX_ROWS_PER_PAGE); set_if_smaller(rows_per_page, MAX_ROWS_PER_PAGE);
...@@ -353,11 +361,11 @@ int maria_create(const char *name, enum data_file_type datafile_type, ...@@ -353,11 +361,11 @@ int maria_create(const char *name, enum data_file_type datafile_type,
{ {
/* /*
The + 1 is for record position withing page The + 1 is for record position withing page
The / 2 is because we need one bit for knowing if there is transid's The * 2 is because we need one bit for knowing if there is transid's
after the row pointer after the row pointer
*/ */
pointer= maria_get_pointer_length((ci->data_file_length / pointer= maria_get_pointer_length((ci->data_file_length /
(maria_block_size * 2)), 3) + 1; maria_block_size) * 2, 3) + 1;
set_if_smaller(pointer, BLOCK_RECORD_POINTER_SIZE); set_if_smaller(pointer, BLOCK_RECORD_POINTER_SIZE);
if (!max_rows) if (!max_rows)
......
...@@ -502,7 +502,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) ...@@ -502,7 +502,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags)
(ulonglong) 1 << (share->base.rec_reflength*8))-1); (ulonglong) 1 << (share->base.rec_reflength*8))-1);
max_key_file_length= max_key_file_length=
_ma_safe_mul(maria_block_size, _ma_safe_mul(share->base.block_size,
((ulonglong) 1 << (share->base.key_reflength*8))-1); ((ulonglong) 1 << (share->base.key_reflength*8))-1);
#if SIZEOF_OFF_T == 4 #if SIZEOF_OFF_T == 4
set_if_smaller(max_data_file_length, INT_MAX32); set_if_smaller(max_data_file_length, INT_MAX32);
...@@ -815,7 +815,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) ...@@ -815,7 +815,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags)
share->base.margin_key_file_length=(share->base.max_key_file_length - share->base.margin_key_file_length=(share->base.max_key_file_length -
(keys ? MARIA_INDEX_BLOCK_MARGIN * (keys ? MARIA_INDEX_BLOCK_MARGIN *
share->block_size * keys : 0)); share->block_size * keys : 0));
share->block_size= share->base.block_size;
my_free(disk_cache, MYF(0)); my_free(disk_cache, MYF(0));
_ma_setup_functions(share); _ma_setup_functions(share);
if ((*share->once_init)(share, info.dfile.file)) if ((*share->once_init)(share, info.dfile.file))
......
...@@ -1553,8 +1553,8 @@ static void descript(HA_CHECK *param, register MARIA_HA *info, char *name) ...@@ -1553,8 +1553,8 @@ static void descript(HA_CHECK *param, register MARIA_HA *info, char *name)
if (share->base.max_data_file_length != HA_OFFSET_ERROR || if (share->base.max_data_file_length != HA_OFFSET_ERROR ||
share->base.max_key_file_length != HA_OFFSET_ERROR) share->base.max_key_file_length != HA_OFFSET_ERROR)
printf("Max datafile length: %16s Max keyfile length: %18s\n", printf("Max datafile length: %16s Max keyfile length: %18s\n",
llstr(share->base.max_data_file_length-1,llbuff), ullstr(share->base.max_data_file_length,llbuff),
llstr(share->base.max_key_file_length-1,llbuff2)); ullstr(share->base.max_key_file_length,llbuff2));
} }
} }
printf("Block_size: %16d\n",(int) share->block_size); printf("Block_size: %16d\n",(int) share->block_size);
......
...@@ -245,9 +245,10 @@ typedef struct st_maria_file_bitmap ...@@ -245,9 +245,10 @@ typedef struct st_maria_file_bitmap
{ {
uchar *map; uchar *map;
pgcache_page_no_t page; /* Page number for current bitmap */ pgcache_page_no_t page; /* Page number for current bitmap */
uint used_size; /* Size of bitmap head that is not 0 */ pgcache_page_no_t last_bitmap_page; /* Last possible bitmap page */
my_bool changed; /* 1 if page needs to be written */ my_bool changed; /* 1 if page needs to be written */
my_bool changed_not_flushed; /* 1 if some bitmap is not flushed */ my_bool changed_not_flushed; /* 1 if some bitmap is not flushed */
uint used_size; /* Size of bitmap head that is not 0 */
uint flush_all_requested; /**< If _ma_bitmap_flush_all waiting */ uint flush_all_requested; /**< If _ma_bitmap_flush_all waiting */
uint waiting_for_flush_all_requested; /* If someone is waiting for above */ uint waiting_for_flush_all_requested; /* If someone is waiting for above */
uint non_flushable; /**< 0 if bitmap and log are in sync */ uint non_flushable; /**< 0 if bitmap and log are in sync */
...@@ -261,6 +262,8 @@ typedef struct st_maria_file_bitmap ...@@ -261,6 +262,8 @@ typedef struct st_maria_file_bitmap
/* Constants, allocated when initiating bitmaps */ /* Constants, allocated when initiating bitmaps */
uint sizes[8]; /* Size per bit combination */ uint sizes[8]; /* Size per bit combination */
uint total_size; /* Total usable size of bitmap page */ uint total_size; /* Total usable size of bitmap page */
uint max_total_size; /* Max value for total_size */
uint last_total_size; /* Size of bitmap on last_bitmap_page */
uint block_size; /* Block size of file */ uint block_size; /* Block size of file */
ulong pages_covered; /* Pages covered by bitmap + 1 */ ulong pages_covered; /* Pages covered by bitmap + 1 */
DYNAMIC_ARRAY pinned_pages; /**< not-yet-flushable bitmap pages */ DYNAMIC_ARRAY pinned_pages; /**< not-yet-flushable bitmap pages */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment