Commit 847c69b1 authored by unknown's avatar unknown

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.
parent ff15476b
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
First version written by Guilhem Bichot on 2006-04-27. First version written by Guilhem Bichot on 2006-04-27.
*/ */
#ifndef EXTRACT_DEFINITIONS
#include "maria_def.h" #include "maria_def.h"
#endif
/* /*
A control file contains the following objects: A control file contains the following objects:
...@@ -89,6 +91,7 @@ one should increment the control file version number. ...@@ -89,6 +91,7 @@ one should increment the control file version number.
#define CF_MIN_CHANGEABLE_TOTAL_SIZE \ #define CF_MIN_CHANGEABLE_TOTAL_SIZE \
(CF_FILENO_OFFSET + CF_FILENO_SIZE) (CF_FILENO_OFFSET + CF_FILENO_SIZE)
#ifndef EXTRACT_DEFINITIONS
/* This module owns these two vars. */ /* This module owns these two vars. */
/** /**
...@@ -475,3 +478,5 @@ int ma_control_file_end() ...@@ -475,3 +478,5 @@ int ma_control_file_end()
DBUG_RETURN(close_error); DBUG_RETURN(close_error);
} }
#endif /* EXTRACT_DEFINITIONS */
...@@ -6589,8 +6589,7 @@ my_bool translog_flush(LSN lsn) ...@@ -6589,8 +6589,7 @@ my_bool translog_flush(LSN lsn)
{ {
DBUG_PRINT("info", ("already flushed: (%lu,0x%lx)", DBUG_PRINT("info", ("already flushed: (%lu,0x%lx)",
LSN_IN_PARTS(log_descriptor.flushed))); LSN_IN_PARTS(log_descriptor.flushed)));
translog_unlock(); goto sync;
goto out;
} }
/* send to the file if it is not sent */ /* send to the file if it is not sent */
sent_to_file= translog_get_sent_to_file(); sent_to_file= translog_get_sent_to_file();
...@@ -6628,6 +6627,7 @@ my_bool translog_flush(LSN lsn) ...@@ -6628,6 +6627,7 @@ my_bool translog_flush(LSN lsn)
} }
translog_lock(); translog_lock();
} }
sync:
translog_unlock(); translog_unlock();
for (i= LSN_FILE_NO(old_flushed); i <= LSN_FILE_NO(lsn); i++) for (i= LSN_FILE_NO(old_flushed); i <= LSN_FILE_NO(lsn); i++)
......
...@@ -36,6 +36,10 @@ ...@@ -36,6 +36,10 @@
#include "../../../storage/maria/maria_def.h" #include "../../../storage/maria/maria_def.h"
#include <my_getopt.h> #include <my_getopt.h>
#define EXTRACT_DEFINITIONS
#include "../ma_control_file.c"
#undef EXTRACT_DEFINITIONS
char file_name[FN_REFLEN]; char file_name[FN_REFLEN];
/* The values we'll set and expect the control file module to return */ /* 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(); ...@@ -61,6 +65,8 @@ static int test_2_open_and_2_close();
static int test_bad_magic_string(); static int test_bad_magic_string();
static int test_bad_checksum(); static int test_bad_checksum();
static int test_bad_hchecksum(); static int test_bad_hchecksum();
static int test_future_size();
static int test_bad_blocksize();
static int test_bad_size(); static int test_bad_size();
/* Utility */ /* Utility */
...@@ -86,7 +92,7 @@ int main(int argc,char *argv[]) ...@@ -86,7 +92,7 @@ int main(int argc,char *argv[])
MY_INIT(argv[0]); MY_INIT(argv[0]);
maria_data_root= "."; maria_data_root= ".";
plan(10); plan(12);
diag("Unit tests for control file"); diag("Unit tests for control file");
...@@ -108,6 +114,8 @@ int main(int argc,char *argv[]) ...@@ -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_magic_string(), "test of bad magic string");
ok(0 == test_bad_checksum(), "test of bad checksum"); ok(0 == test_bad_checksum(), "test of bad checksum");
ok(0 == test_bad_hchecksum(), "test of bad hchecksum"); 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"); ok(0 == test_bad_size(), "test of too small/big file");
return exit_status(); return exit_status();
...@@ -266,18 +274,18 @@ static int test_binary_content() ...@@ -266,18 +274,18 @@ static int test_binary_content()
future change/breakage. future change/breakage.
*/ */
char buffer[43]; char buffer[45];
RET_ERR_UNLESS((fd= my_open(file_name, RET_ERR_UNLESS((fd= my_open(file_name,
O_BINARY | O_RDWR, O_BINARY | O_RDWR,
MYF(MY_WME))) >= 0); 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(my_close(fd, MYF(MY_WME)) == 0);
RET_ERR_UNLESS(create_or_open_file() == CONTROL_FILE_OK); 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)); 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)); 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(i == last_logno);
RET_ERR_UNLESS(close_file() == 0); RET_ERR_UNLESS(close_file() == 0);
return 0; return 0;
...@@ -344,21 +352,84 @@ static int test_bad_checksum() ...@@ -344,21 +352,84 @@ static int test_bad_checksum()
RET_ERR_UNLESS((fd= my_open(file_name, RET_ERR_UNLESS((fd= my_open(file_name,
O_BINARY | O_RDWR, O_BINARY | O_RDWR,
MYF(MY_WME))) >= 0); 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 */ 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 */ /* Check that control file module sees the problem */
RET_ERR_UNLESS(ma_control_file_create_or_open(TRUE) == RET_ERR_UNLESS(ma_control_file_create_or_open(TRUE) ==
CONTROL_FILE_BAD_CHECKSUM); CONTROL_FILE_BAD_CHECKSUM);
/* Restore checksum */ /* Restore checksum */
buffer[0]-= 3; 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); RET_ERR_UNLESS(my_close(fd, MYF(MY_WME)) == 0);
return 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() static int test_bad_hchecksum()
{ {
char buffer[4]; char buffer[4];
...@@ -371,15 +442,15 @@ static int test_bad_hchecksum() ...@@ -371,15 +442,15 @@ static int test_bad_hchecksum()
RET_ERR_UNLESS((fd= my_open(file_name, RET_ERR_UNLESS((fd= my_open(file_name,
O_BINARY | O_RDWR, O_BINARY | O_RDWR,
MYF(MY_WME))) >= 0); 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 */ 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 */ /* Check that control file module sees the problem */
RET_ERR_UNLESS(ma_control_file_create_or_open(TRUE) == RET_ERR_UNLESS(ma_control_file_create_or_open(TRUE) ==
CONTROL_FILE_BAD_HEAD_CHECKSUM); CONTROL_FILE_BAD_HEAD_CHECKSUM);
/* Restore checksum */ /* Restore checksum */
buffer[0]-= 3; 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); RET_ERR_UNLESS(my_close(fd, MYF(MY_WME)) == 0);
return 0; return 0;
...@@ -388,8 +459,9 @@ static int test_bad_hchecksum() ...@@ -388,8 +459,9 @@ static int test_bad_hchecksum()
static int test_bad_size() static int test_bad_size()
{ {
char buffer[]="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; char buffer[]=
int fd; "123456789012345678901234567890123456789012345678901234567890123456";
int fd, i;
/* A too short file */ /* A too short file */
RET_ERR_UNLESS(delete_file(MYF(MY_WME)) == 0); RET_ERR_UNLESS(delete_file(MYF(MY_WME)) == 0);
...@@ -400,7 +472,10 @@ static int test_bad_size() ...@@ -400,7 +472,10 @@ static int test_bad_size()
/* Check that control file module sees the problem */ /* Check that control file module sees the problem */
RET_ERR_UNLESS(ma_control_file_create_or_open(TRUE) == RET_ERR_UNLESS(ma_control_file_create_or_open(TRUE) ==
CONTROL_FILE_TOO_SMALL); 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 */ /* 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(ma_control_file_create_or_open(TRUE) == CONTROL_FILE_TOO_BIG);
RET_ERR_UNLESS(my_close(fd, MYF(MY_WME)) == 0); RET_ERR_UNLESS(my_close(fd, MYF(MY_WME)) == 0);
......
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