From b7ae94d8dfef8e0135af30dcc9711e98a1b14dfc Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 30 Nov 2007 21:28:39 +0200 Subject: [PATCH] Fix bug with skipped syncing. Fix of unit tests. 2 new tests for new features. storage/maria/ma_control_file.c: Getting the definition from the file for unit-test. storage/maria/ma_loghandler.c: Fix bug with skipped syncing. storage/maria/unittest/ma_control_file-t.c: Fix of unit test of control file. 2 new tests for new features of control file. --- storage/maria/ma_control_file.c | 5 + storage/maria/ma_loghandler.c | 4 +- storage/maria/unittest/ma_control_file-t.c | 105 ++++++++++++++++++--- 3 files changed, 97 insertions(+), 17 deletions(-) diff --git a/storage/maria/ma_control_file.c b/storage/maria/ma_control_file.c index 3d3a23cdb8b..4510cc11b20 100644 --- a/storage/maria/ma_control_file.c +++ b/storage/maria/ma_control_file.c @@ -18,7 +18,9 @@ First version written by Guilhem Bichot on 2006-04-27. */ +#ifndef EXTRACT_DEFINITIONS #include "maria_def.h" +#endif /* A control file contains the following objects: @@ -89,6 +91,7 @@ one should increment the control file version number. #define CF_MIN_CHANGEABLE_TOTAL_SIZE \ (CF_FILENO_OFFSET + CF_FILENO_SIZE) +#ifndef EXTRACT_DEFINITIONS /* This module owns these two vars. */ /** @@ -475,3 +478,5 @@ int ma_control_file_end() DBUG_RETURN(close_error); } + +#endif /* EXTRACT_DEFINITIONS */ diff --git a/storage/maria/ma_loghandler.c b/storage/maria/ma_loghandler.c index 2b1d6e4a48d..810efa157d0 100644 --- a/storage/maria/ma_loghandler.c +++ b/storage/maria/ma_loghandler.c @@ -6589,8 +6589,7 @@ my_bool translog_flush(LSN lsn) { DBUG_PRINT("info", ("already flushed: (%lu,0x%lx)", LSN_IN_PARTS(log_descriptor.flushed))); - translog_unlock(); - goto out; + goto sync; } /* send to the file if it is not sent */ sent_to_file= translog_get_sent_to_file(); @@ -6628,6 +6627,7 @@ my_bool translog_flush(LSN lsn) } translog_lock(); } +sync: translog_unlock(); for (i= LSN_FILE_NO(old_flushed); i <= LSN_FILE_NO(lsn); i++) diff --git a/storage/maria/unittest/ma_control_file-t.c b/storage/maria/unittest/ma_control_file-t.c index 50b3407bb15..48db4a59963 100644 --- a/storage/maria/unittest/ma_control_file-t.c +++ b/storage/maria/unittest/ma_control_file-t.c @@ -36,6 +36,10 @@ #include "../../../storage/maria/maria_def.h" #include +#define EXTRACT_DEFINITIONS +#include "../ma_control_file.c" +#undef EXTRACT_DEFINITIONS + char file_name[FN_REFLEN]; /* The values we'll set and expect the control file module to return */ @@ -61,6 +65,8 @@ static int test_2_open_and_2_close(); static int test_bad_magic_string(); static int test_bad_checksum(); static int test_bad_hchecksum(); +static int test_future_size(); +static int test_bad_blocksize(); static int test_bad_size(); /* Utility */ @@ -86,7 +92,7 @@ int main(int argc,char *argv[]) MY_INIT(argv[0]); maria_data_root= "."; - plan(10); + plan(12); diag("Unit tests for control file"); @@ -108,6 +114,8 @@ int main(int argc,char *argv[]) ok(0 == test_bad_magic_string(), "test of bad magic string"); ok(0 == test_bad_checksum(), "test of bad checksum"); ok(0 == test_bad_hchecksum(), "test of bad hchecksum"); + ok(0 == test_future_size(), "test of ability to handlr future versions"); + ok(0 == test_bad_blocksize(), "test of bad blocksize"); ok(0 == test_bad_size(), "test of too small/big file"); return exit_status(); @@ -266,18 +274,18 @@ static int test_binary_content() future change/breakage. */ - char buffer[43]; + char buffer[45]; RET_ERR_UNLESS((fd= my_open(file_name, O_BINARY | O_RDWR, MYF(MY_WME))) >= 0); - RET_ERR_UNLESS(my_read(fd, buffer, 43, MYF(MY_FNABP | MY_WME)) == 0); + RET_ERR_UNLESS(my_read(fd, buffer, 45, MYF(MY_FNABP | MY_WME)) == 0); RET_ERR_UNLESS(my_close(fd, MYF(MY_WME)) == 0); RET_ERR_UNLESS(create_or_open_file() == CONTROL_FILE_OK); - i= uint3korr(buffer + 32 ); + i= uint3korr(buffer + 34 ); RET_ERR_UNLESS(i == LSN_FILE_NO(last_checkpoint_lsn)); - i= uint4korr(buffer + 35); + i= uint4korr(buffer + 37); RET_ERR_UNLESS(i == LSN_OFFSET(last_checkpoint_lsn)); - i= uint4korr(buffer + 39); + i= uint4korr(buffer + 41); RET_ERR_UNLESS(i == last_logno); RET_ERR_UNLESS(close_file() == 0); return 0; @@ -344,21 +352,84 @@ static int test_bad_checksum() RET_ERR_UNLESS((fd= my_open(file_name, O_BINARY | O_RDWR, MYF(MY_WME))) >= 0); - RET_ERR_UNLESS(my_pread(fd, buffer, 1, 28, MYF(MY_FNABP | MY_WME)) == 0); + RET_ERR_UNLESS(my_pread(fd, buffer, 1, 30, MYF(MY_FNABP | MY_WME)) == 0); buffer[0]+= 3; /* mangle checksum */ - RET_ERR_UNLESS(my_pwrite(fd, buffer, 1, 28, MYF(MY_FNABP | MY_WME)) == 0); + RET_ERR_UNLESS(my_pwrite(fd, buffer, 1, 30, MYF(MY_FNABP | MY_WME)) == 0); /* Check that control file module sees the problem */ RET_ERR_UNLESS(ma_control_file_create_or_open(TRUE) == CONTROL_FILE_BAD_CHECKSUM); /* Restore checksum */ buffer[0]-= 3; - RET_ERR_UNLESS(my_pwrite(fd, buffer, 1, 28, MYF(MY_FNABP | MY_WME)) == 0); + RET_ERR_UNLESS(my_pwrite(fd, buffer, 1, 30, MYF(MY_FNABP | MY_WME)) == 0); RET_ERR_UNLESS(my_close(fd, MYF(MY_WME)) == 0); return 0; } +static int test_bad_blocksize() +{ + maria_block_size<<= 1; + /* Check that control file module sees the problem */ + RET_ERR_UNLESS(ma_control_file_create_or_open(TRUE) == + CONTROL_FILE_WRONG_BLOCKSIZE); + /* Restore blocksize */ + maria_block_size>>= 1; + + RET_ERR_UNLESS(create_or_open_file() == CONTROL_FILE_OK); + RET_ERR_UNLESS(close_file() == 0); + return 0; +} + + +static int test_future_size() +{ + /* + Here we check ability to add fields only so we can use + defined constants + */ + uint32 sum; + int fd; + char buffer[CF_CREATE_TIME_TOTAL_SIZE + CF_CHANGEABLE_TOTAL_SIZE + 2]; + RET_ERR_UNLESS((fd= my_open(file_name, + O_BINARY | O_RDWR, + MYF(MY_WME))) >= 0); + RET_ERR_UNLESS(my_read(fd, buffer, + CF_CREATE_TIME_TOTAL_SIZE + CF_CHANGEABLE_TOTAL_SIZE, + MYF(MY_FNABP | MY_WME)) == 0); + RET_ERR_UNLESS(my_close(fd, MYF(MY_WME)) == 0); + /* "add" new field of 1 byte (value 1) to header and variable part */ + memmove(buffer + CF_CREATE_TIME_TOTAL_SIZE + 1, + buffer + CF_CREATE_TIME_TOTAL_SIZE, + CF_CHANGEABLE_TOTAL_SIZE); + buffer[CF_CREATE_TIME_TOTAL_SIZE - CF_CHECKSUM_SIZE]= '\1'; + buffer[CF_CREATE_TIME_TOTAL_SIZE + CF_CHANGEABLE_TOTAL_SIZE + 1]= '\1'; + /* fix lengths */ + int2store(buffer + CF_CREATE_TIME_SIZE_OFFSET, CF_CREATE_TIME_TOTAL_SIZE + 1); + int2store(buffer + CF_CHANGEABLE_SIZE_OFFSET, CF_CHANGEABLE_TOTAL_SIZE + 1); + /* recalculete checksums */ + sum= (uint32) my_checksum(0, buffer, CF_CREATE_TIME_TOTAL_SIZE - + CF_CHECKSUM_SIZE + 1); + int4store(buffer + CF_CREATE_TIME_TOTAL_SIZE - CF_CHECKSUM_SIZE + 1, sum); + sum= (uint32) my_checksum(0, buffer + CF_CREATE_TIME_TOTAL_SIZE + 1 + + CF_CHECKSUM_SIZE, + CF_CHANGEABLE_TOTAL_SIZE - CF_CHECKSUM_SIZE + 1); + int4store(buffer + CF_CREATE_TIME_TOTAL_SIZE + 1, sum); + /* write new file and check it */ + RET_ERR_UNLESS((fd= my_open(file_name, + O_BINARY | O_RDWR, + MYF(MY_WME))) >= 0); + RET_ERR_UNLESS(my_pwrite(fd, buffer, + CF_CREATE_TIME_TOTAL_SIZE + + CF_CHANGEABLE_TOTAL_SIZE + 2, + 0, MYF(MY_FNABP | MY_WME)) == 0); + RET_ERR_UNLESS(my_close(fd, MYF(MY_WME)) == 0); + RET_ERR_UNLESS(create_or_open_file() == CONTROL_FILE_OK); + RET_ERR_UNLESS(close_file() == 0); + + return(0); +} + static int test_bad_hchecksum() { char buffer[4]; @@ -371,15 +442,15 @@ static int test_bad_hchecksum() RET_ERR_UNLESS((fd= my_open(file_name, O_BINARY | O_RDWR, MYF(MY_WME))) >= 0); - RET_ERR_UNLESS(my_pread(fd, buffer, 1, 24, MYF(MY_FNABP | MY_WME)) == 0); + RET_ERR_UNLESS(my_pread(fd, buffer, 1, 26, MYF(MY_FNABP | MY_WME)) == 0); buffer[0]+= 3; /* mangle checksum */ - RET_ERR_UNLESS(my_pwrite(fd, buffer, 1, 24, MYF(MY_FNABP | MY_WME)) == 0); + RET_ERR_UNLESS(my_pwrite(fd, buffer, 1, 26, MYF(MY_FNABP | MY_WME)) == 0); /* Check that control file module sees the problem */ RET_ERR_UNLESS(ma_control_file_create_or_open(TRUE) == CONTROL_FILE_BAD_HEAD_CHECKSUM); /* Restore checksum */ buffer[0]-= 3; - RET_ERR_UNLESS(my_pwrite(fd, buffer, 1, 24, MYF(MY_FNABP | MY_WME)) == 0); + RET_ERR_UNLESS(my_pwrite(fd, buffer, 1, 26, MYF(MY_FNABP | MY_WME)) == 0); RET_ERR_UNLESS(my_close(fd, MYF(MY_WME)) == 0); return 0; @@ -388,8 +459,9 @@ static int test_bad_hchecksum() static int test_bad_size() { - char buffer[]="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; - int fd; + char buffer[]= + "123456789012345678901234567890123456789012345678901234567890123456"; + int fd, i; /* A too short file */ RET_ERR_UNLESS(delete_file(MYF(MY_WME)) == 0); @@ -400,7 +472,10 @@ static int test_bad_size() /* Check that control file module sees the problem */ RET_ERR_UNLESS(ma_control_file_create_or_open(TRUE) == CONTROL_FILE_TOO_SMALL); - RET_ERR_UNLESS(my_write(fd, buffer, 50, MYF(MY_FNABP | MY_WME)) == 0); + for (i= 0; i < 8; i++) + { + RET_ERR_UNLESS(my_write(fd, buffer, 66, MYF(MY_FNABP | MY_WME)) == 0); + } /* Check that control file module sees the problem */ RET_ERR_UNLESS(ma_control_file_create_or_open(TRUE) == CONTROL_FILE_TOO_BIG); RET_ERR_UNLESS(my_close(fd, MYF(MY_WME)) == 0);