Commit 30573786 authored by unknown's avatar unknown

Fix for failures of ma_control_file-t, ma_test_loghandler_purge-t,

ma_test_loghandler_pagecache-t on Windows.


storage/maria/ma_control_file.c:
  stat() is unreliable on Windows (does not reflect process' own writes)
storage/maria/ma_loghandler.c:
  translog_set_lsn_for_files() didn't close its file descriptor; it was
  a real problem as non-closed files could not be purged.
  Same for translog_truncate_log() in case of error.
storage/maria/unittest/ma_test_loghandler_pagecache-t.c:
  stat() is unreliable on Windows (does not reflect process' own writes)
parent e9a89f12
...@@ -212,9 +212,9 @@ CONTROL_FILE_ERROR ma_control_file_create_or_open() ...@@ -212,9 +212,9 @@ CONTROL_FILE_ERROR ma_control_file_create_or_open()
uchar buffer[CF_MAX_SIZE]; uchar buffer[CF_MAX_SIZE];
char name[FN_REFLEN], errmsg_buff[256]; char name[FN_REFLEN], errmsg_buff[256];
const char *errmsg; const char *errmsg;
MY_STAT stat_buff;
uint new_cf_create_time_size, new_cf_changeable_size, new_block_size; uint new_cf_create_time_size, new_cf_changeable_size, new_block_size;
uint retry; uint retry;
my_off_t file_size;
int open_flags= O_BINARY | /*O_DIRECT |*/ O_RDWR; int open_flags= O_BINARY | /*O_DIRECT |*/ O_RDWR;
int error= CONTROL_FILE_UNKNOWN_ERROR; int error= CONTROL_FILE_UNKNOWN_ERROR;
DBUG_ENTER("ma_control_file_create_or_open"); DBUG_ENTER("ma_control_file_create_or_open");
...@@ -252,13 +252,13 @@ CONTROL_FILE_ERROR ma_control_file_create_or_open() ...@@ -252,13 +252,13 @@ CONTROL_FILE_ERROR ma_control_file_create_or_open()
goto err; goto err;
} }
if (my_stat(name, &stat_buff, MYF(0)) == NULL) file_size= my_seek(control_file_fd, 0, SEEK_END, MYF(MY_WME));
if (file_size == MY_FILEPOS_ERROR)
{ {
errmsg= "Can't read status"; errmsg= "Can't read size";
goto err; goto err;
} }
if (file_size < CF_MIN_SIZE)
if ((uint) stat_buff.st_size < CF_MIN_SIZE)
{ {
/* /*
Given that normally we write only a sector and it's atomic, the only Given that normally we write only a sector and it's atomic, the only
...@@ -277,14 +277,14 @@ CONTROL_FILE_ERROR ma_control_file_create_or_open() ...@@ -277,14 +277,14 @@ CONTROL_FILE_ERROR ma_control_file_create_or_open()
} }
/* Check if control file is unexpectedly big */ /* Check if control file is unexpectedly big */
if ((uint)stat_buff.st_size > CF_MAX_SIZE) if (file_size > CF_MAX_SIZE)
{ {
error= CONTROL_FILE_TOO_BIG; error= CONTROL_FILE_TOO_BIG;
errmsg= "File size bigger than expected"; errmsg= "File size bigger than expected";
goto err; goto err;
} }
if (my_read(control_file_fd, buffer, stat_buff.st_size, MYF(MY_FNABP))) if (my_pread(control_file_fd, buffer, (size_t)file_size, 0, MYF(MY_FNABP)))
{ {
errmsg= "Can't read file"; errmsg= "Can't read file";
goto err; goto err;
...@@ -312,8 +312,7 @@ CONTROL_FILE_ERROR ma_control_file_create_or_open() ...@@ -312,8 +312,7 @@ CONTROL_FILE_ERROR ma_control_file_create_or_open()
if (new_cf_create_time_size < CF_MIN_CREATE_TIME_TOTAL_SIZE || if (new_cf_create_time_size < CF_MIN_CREATE_TIME_TOTAL_SIZE ||
new_cf_changeable_size < CF_MIN_CHANGEABLE_TOTAL_SIZE || new_cf_changeable_size < CF_MIN_CHANGEABLE_TOTAL_SIZE ||
new_cf_create_time_size + new_cf_changeable_size != new_cf_create_time_size + new_cf_changeable_size != file_size)
stat_buff.st_size)
{ {
error= CONTROL_FILE_INCONSISTENT_INFORMATION; error= CONTROL_FILE_INCONSISTENT_INFORMATION;
errmsg= "Sizes stored in control file are inconsistent"; errmsg= "Sizes stored in control file are inconsistent";
......
...@@ -1135,10 +1135,11 @@ static my_bool translog_set_lsn_for_files(uint32 from_file, uint32 to_file, ...@@ -1135,10 +1135,11 @@ static my_bool translog_set_lsn_for_files(uint32 from_file, uint32 to_file,
{ {
LOGHANDLER_FILE_INFO info; LOGHANDLER_FILE_INFO info;
File fd= open_logfile_by_number_no_cache(file); File fd= open_logfile_by_number_no_cache(file);
if (fd < 0 || if ((fd < 0) ||
translog_read_file_header(&info, fd) || ((translog_read_file_header(&info, fd) ||
(cmp_translog_addr(lsn, info.max_lsn) > 0 && (cmp_translog_addr(lsn, info.max_lsn) > 0 &&
translog_max_lsn_to_header(fd, lsn))) translog_max_lsn_to_header(fd, lsn))) |
my_close(fd, MYF(MY_WME))))
{ {
translog_stop_writing(); translog_stop_writing();
DBUG_RETURN(1); DBUG_RETURN(1);
...@@ -1316,16 +1317,9 @@ LSN translog_get_file_max_lsn_stored(uint32 file) ...@@ -1316,16 +1317,9 @@ LSN translog_get_file_max_lsn_stored(uint32 file)
{ {
LOGHANDLER_FILE_INFO info; LOGHANDLER_FILE_INFO info;
my_bool error;
File fd= open_logfile_by_number_no_cache(file); File fd= open_logfile_by_number_no_cache(file);
if (fd >= 0) if ((fd < 0) ||
{ (translog_read_file_header(&info, fd) | my_close(fd, MYF(MY_WME))))
error= translog_read_file_header(&info, fd);
my_close(fd, MYF(MY_WME));
}
else
error= TRUE;
if (error)
{ {
DBUG_PRINT("error", ("Can't read file header")); DBUG_PRINT("error", ("Can't read file header"));
DBUG_RETURN(LSN_ERROR); DBUG_RETURN(LSN_ERROR);
...@@ -3129,11 +3123,11 @@ static my_bool translog_truncate_log(TRANSLOG_ADDRESS addr) ...@@ -3129,11 +3123,11 @@ static my_bool translog_truncate_log(TRANSLOG_ADDRESS addr)
page_rest= next_page_offset - LSN_OFFSET(addr); page_rest= next_page_offset - LSN_OFFSET(addr);
memset(page_buff, TRANSLOG_FILLER, page_rest); memset(page_buff, TRANSLOG_FILLER, page_rest);
if ((fd= open_logfile_by_number_no_cache(LSN_FILE_NO(addr))) < 0 || if ((fd= open_logfile_by_number_no_cache(LSN_FILE_NO(addr))) < 0 ||
my_chsize(fd, next_page_offset, TRANSLOG_FILLER, MYF(MY_WME)) || ((my_chsize(fd, next_page_offset, TRANSLOG_FILLER, MYF(MY_WME)) ||
(page_rest && my_pwrite(fd, page_buff, page_rest, LSN_OFFSET(addr), (page_rest && my_pwrite(fd, page_buff, page_rest, LSN_OFFSET(addr),
log_write_flags)) || log_write_flags)) ||
my_sync(fd, MYF(MY_WME)) || my_sync(fd, MYF(MY_WME))) |
my_close(fd, MYF(MY_WME)) || my_close(fd, MYF(MY_WME))) ||
(sync_log_dir >= TRANSLOG_SYNC_DIR_ALWAYS && (sync_log_dir >= TRANSLOG_SYNC_DIR_ALWAYS &&
sync_dir(log_descriptor.directory_fd, MYF(MY_WME | MY_IGNORE_BADFD)))) sync_dir(log_descriptor.directory_fd, MYF(MY_WME | MY_IGNORE_BADFD))))
DBUG_RETURN(1); DBUG_RETURN(1);
......
...@@ -51,7 +51,7 @@ int main(int argc __attribute__((unused)), char *argv[]) ...@@ -51,7 +51,7 @@ int main(int argc __attribute__((unused)), char *argv[])
uchar long_tr_id[6]; uchar long_tr_id[6];
PAGECACHE pagecache; PAGECACHE pagecache;
LSN lsn; LSN lsn;
MY_STAT st, *stat; my_off_t file_size;
LEX_STRING parts[TRANSLOG_INTERNAL_PARTS + 1]; LEX_STRING parts[TRANSLOG_INTERNAL_PARTS + 1];
MY_INIT(argv[0]); MY_INIT(argv[0]);
...@@ -101,18 +101,20 @@ int main(int argc __attribute__((unused)), char *argv[]) ...@@ -101,18 +101,20 @@ int main(int argc __attribute__((unused)), char *argv[])
/* Suppressing of automatic record writing */ /* Suppressing of automatic record writing */
dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID; dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID;
if ((stat= my_stat(first_translog_file, &st, MYF(0))) == 0) if ((file1.file= my_open(first_translog_file, O_RDONLY, MYF(MY_WME))) < 0)
{ {
fprintf(stderr, "There is no %s (%d)\n", first_translog_file, errno); fprintf(stderr, "There is no %s (%d)\n", first_translog_file, errno);
exit(1); exit(1);
} }
if (st.st_size != TRANSLOG_PAGE_SIZE) file_size= my_seek(file1.file, 0, SEEK_END, MYF(MY_WME));
if (file_size != TRANSLOG_PAGE_SIZE)
{ {
fprintf(stderr, fprintf(stderr,
"incorrect initial size of %s: %ld instead of %ld\n", "incorrect initial size of %s: %ld instead of %ld\n",
first_translog_file, (long)st.st_size, (long)TRANSLOG_PAGE_SIZE); first_translog_file, (long)file_size, (long)TRANSLOG_PAGE_SIZE);
exit(1); exit(1);
} }
my_close(file1.file, MYF(MY_WME));
int4store(long_tr_id, 0); int4store(long_tr_id, 0);
parts[TRANSLOG_INTERNAL_PARTS + 0].str= (char*)long_tr_id; parts[TRANSLOG_INTERNAL_PARTS + 0].str= (char*)long_tr_id;
parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6; parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
...@@ -153,20 +155,23 @@ int main(int argc __attribute__((unused)), char *argv[]) ...@@ -153,20 +155,23 @@ int main(int argc __attribute__((unused)), char *argv[])
0, LSN_IMPOSSIBLE); 0, LSN_IMPOSSIBLE);
flush_pagecache_blocks(&pagecache, &file1, FLUSH_FORCE_WRITE); flush_pagecache_blocks(&pagecache, &file1, FLUSH_FORCE_WRITE);
} }
if ((stat= my_stat(first_translog_file, &st, MYF(0))) == 0) my_close(file1.file, MYF(MY_WME));
if ((file1.file= my_open(first_translog_file, O_RDONLY, MYF(MY_WME))) < 0)
{ {
fprintf(stderr, "can't stat %s (%d)\n", first_translog_file, errno); fprintf(stderr, "can't open %s (%d)\n", first_translog_file, errno);
exit(1); exit(1);
} }
if (st.st_size != TRANSLOG_PAGE_SIZE * 2) file_size= my_seek(file1.file, 0, SEEK_END, MYF(MY_WME));
if (file_size != TRANSLOG_PAGE_SIZE * 2)
{ {
fprintf(stderr, fprintf(stderr,
"incorrect initial size of %s: %ld instead of %ld\n", "incorrect initial size of %s: %ld instead of %ld\n",
first_translog_file, first_translog_file,
(long)st.st_size, (long)(TRANSLOG_PAGE_SIZE * 2)); (long)file_size, (long)(TRANSLOG_PAGE_SIZE * 2));
ok(0, "log triggered"); ok(0, "log triggered");
exit(1); exit(1);
} }
my_close(file1.file, MYF(MY_WME));
ok(1, "log triggered"); ok(1, "log triggered");
translog_destroy(); translog_destroy();
......
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