Commit 212c7dfe authored by unknown's avatar unknown

Merge desktop.sanja.is.com.ua:/home/bell/mysql/bk/mysql-maria

into  desktop.sanja.is.com.ua:/home/bell/mysql/bk/work-maria-filler

parents ea388ba2 b47628f1
...@@ -1176,6 +1176,7 @@ static my_bool find_blob(MARIA_HA *info, ulong length) ...@@ -1176,6 +1176,7 @@ static my_bool find_blob(MARIA_HA *info, ulong length)
MARIA_BITMAP_BLOCK *first_block= 0; MARIA_BITMAP_BLOCK *first_block= 0;
DBUG_ENTER("find_blob"); DBUG_ENTER("find_blob");
DBUG_PRINT("enter", ("length: %lu", length)); DBUG_PRINT("enter", ("length: %lu", length));
LINT_INIT(first_block_pos);
pages= length / full_page_size; pages= length / full_page_size;
rest_length= (uint) (length - pages * full_page_size); rest_length= (uint) (length - pages * full_page_size);
...@@ -2007,6 +2008,9 @@ my_bool _ma_check_bitmap_data(MARIA_HA *info, ...@@ -2007,6 +2008,9 @@ my_bool _ma_check_bitmap_data(MARIA_HA *info,
case BLOB_PAGE: case BLOB_PAGE:
bits= FULL_TAIL_PAGE; bits= FULL_TAIL_PAGE;
break; break;
default:
bits= 0; /* to satisfy compiler */
DBUG_ASSERT(0);
} }
return (*bitmap_pattern= get_page_bits(info, &info->s->bitmap, page)) != return (*bitmap_pattern= get_page_bits(info, &info->s->bitmap, page)) !=
bits; bits;
......
...@@ -5514,6 +5514,7 @@ my_bool _ma_apply_undo_row_update(MARIA_HA *info, LSN undo_lsn, ...@@ -5514,6 +5514,7 @@ my_bool _ma_apply_undo_row_update(MARIA_HA *info, LSN undo_lsn,
MARIA_RECORD_POS record_pos; MARIA_RECORD_POS record_pos;
ha_checksum checksum_delta; ha_checksum checksum_delta;
DBUG_ENTER("_ma_apply_undo_row_update"); DBUG_ENTER("_ma_apply_undo_row_update");
LINT_INIT(checksum_delta);
page= page_korr(header); page= page_korr(header);
header+= PAGE_STORE_SIZE; header+= PAGE_STORE_SIZE;
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
translog_assert_owner() could be added. translog_assert_owner() could be added.
*/ */
#define TRANSLOG_FILLER 0xFF
/* number of opened log files in the pagecache (should be at least 2) */ /* number of opened log files in the pagecache (should be at least 2) */
#define OPENED_FILES_NUM 3 #define OPENED_FILES_NUM 3
...@@ -62,6 +64,31 @@ ...@@ -62,6 +64,31 @@
#define COMPRESSED_LSN_MAX_STORE_SIZE (2 + LSN_STORE_SIZE) #define COMPRESSED_LSN_MAX_STORE_SIZE (2 + LSN_STORE_SIZE)
#define MAX_NUMBER_OF_LSNS_PER_RECORD 2 #define MAX_NUMBER_OF_LSNS_PER_RECORD 2
#ifndef DBUG_OFF
static int translog_mutex_lock(pthread_mutex_t *M)
{
int rc;
DBUG_PRINT("info", ("Going lock mutex 0x%lx...", (ulong)(M)));
rc= pthread_mutex_lock(M);
DBUG_PRINT("info", ("Mutex locked 0x%lx rc: %d", (ulong)(M), rc));
return (rc);
}
static int translog_mutex_unlock(pthread_mutex_t *M)
{
int rc;
DBUG_PRINT("info", ("Going unlock mutex 0x%lx...", (ulong)(M)));
rc= pthread_mutex_unlock(M);
DBUG_PRINT("info", ("Mutex unlocked 0x%lx rc: %d", (ulong)(M), rc));
return(rc);
}
#else
#define translog_mutex_lock(M) pthread_mutex_lock(M)
#define translog_mutex_unlock(M) pthread_mutex_unlock(M)
#endif
/* log write buffer descriptor */ /* log write buffer descriptor */
struct st_translog_buffer struct st_translog_buffer
{ {
...@@ -187,6 +214,7 @@ static struct st_translog_descriptor log_descriptor; ...@@ -187,6 +214,7 @@ static struct st_translog_descriptor log_descriptor;
/* Marker for end of log */ /* Marker for end of log */
static uchar end_of_log= 0; static uchar end_of_log= 0;
#define END_OF_LOG &end_of_log
my_bool translog_inited= 0; my_bool translog_inited= 0;
...@@ -726,13 +754,9 @@ static my_bool translog_write_file_header() ...@@ -726,13 +754,9 @@ static my_bool translog_write_file_header()
/* file number */ /* file number */
int3store(page, LSN_FILE_NO(log_descriptor.horizon)); int3store(page, LSN_FILE_NO(log_descriptor.horizon));
page+= 3; page+= 3;
/* lsn_store(page, LSN_IMPOSSIBLE);
Here should be max lsn storing for current file (which is LSN_IPOSSIBLE):
lsn_store(page, LSN_IPOSSIBLE);
page+= LSN_STORE_SIZE; page+= LSN_STORE_SIZE;
But it is zeros so we can rely on bzero() in this case memset(page, TRANSLOG_FILLER, sizeof(page_buff) - (page- page_buff));
*/
bzero(page, sizeof(page_buff) - (page- page_buff));
DBUG_RETURN(my_pwrite(log_descriptor.log_file_num[0], page_buff, DBUG_RETURN(my_pwrite(log_descriptor.log_file_num[0], page_buff,
sizeof(page_buff), 0, log_write_flags) != 0); sizeof(page_buff), 0, log_write_flags) != 0);
...@@ -868,7 +892,7 @@ static my_bool translog_set_lsn_for_files(uint32 from_file, uint32 to_file, ...@@ -868,7 +892,7 @@ static my_bool translog_set_lsn_for_files(uint32 from_file, uint32 to_file,
translog_unlock(); translog_unlock();
/* Checks finished files if they are */ /* Checks finished files if they are */
pthread_mutex_lock(&log_descriptor.file_header_lock); translog_mutex_lock(&log_descriptor.file_header_lock);
for (file= from_file; file <= to_file; file++) for (file= from_file; file <= to_file; file++)
{ {
LOGHANDLER_FILE_INFO info; LOGHANDLER_FILE_INFO info;
...@@ -879,7 +903,7 @@ static my_bool translog_set_lsn_for_files(uint32 from_file, uint32 to_file, ...@@ -879,7 +903,7 @@ static my_bool translog_set_lsn_for_files(uint32 from_file, uint32 to_file,
translog_max_lsn_to_header(fd, lsn))) translog_max_lsn_to_header(fd, lsn)))
DBUG_RETURN(1); DBUG_RETURN(1);
} }
pthread_mutex_unlock(&log_descriptor.file_header_lock); translog_mutex_unlock(&log_descriptor.file_header_lock);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -908,7 +932,7 @@ static void translog_mark_file_unfinished(uint32 file) ...@@ -908,7 +932,7 @@ static void translog_mark_file_unfinished(uint32 file)
DBUG_ENTER("translog_mark_file_unfinished"); DBUG_ENTER("translog_mark_file_unfinished");
DBUG_PRINT("enter", ("file: %lu", (ulong) file)); DBUG_PRINT("enter", ("file: %lu", (ulong) file));
pthread_mutex_lock(&log_descriptor.unfinished_files_lock); translog_mutex_lock(&log_descriptor.unfinished_files_lock);
if (log_descriptor.unfinished_files.elements == 0) if (log_descriptor.unfinished_files.elements == 0)
{ {
...@@ -959,7 +983,7 @@ static void translog_mark_file_unfinished(uint32 file) ...@@ -959,7 +983,7 @@ static void translog_mark_file_unfinished(uint32 file)
place + 1, struct st_file_counter *), place + 1, struct st_file_counter *),
&fc, sizeof(struct st_file_counter)); &fc, sizeof(struct st_file_counter));
end: end:
pthread_mutex_unlock(&log_descriptor.unfinished_files_lock); translog_mutex_unlock(&log_descriptor.unfinished_files_lock);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -980,7 +1004,7 @@ static void translog_mark_file_finished(uint32 file) ...@@ -980,7 +1004,7 @@ static void translog_mark_file_finished(uint32 file)
LINT_INIT(fc_ptr); LINT_INIT(fc_ptr);
pthread_mutex_lock(&log_descriptor.unfinished_files_lock); translog_mutex_lock(&log_descriptor.unfinished_files_lock);
DBUG_ASSERT(log_descriptor.unfinished_files.elements > 0); DBUG_ASSERT(log_descriptor.unfinished_files.elements > 0);
for (i= 0; for (i= 0;
...@@ -998,7 +1022,7 @@ static void translog_mark_file_finished(uint32 file) ...@@ -998,7 +1022,7 @@ static void translog_mark_file_finished(uint32 file)
if (! --fc_ptr->counter) if (! --fc_ptr->counter)
delete_dynamic_element(&log_descriptor.unfinished_files, i); delete_dynamic_element(&log_descriptor.unfinished_files, i);
pthread_mutex_unlock(&log_descriptor.unfinished_files_lock); translog_mutex_unlock(&log_descriptor.unfinished_files_lock);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -1021,7 +1045,7 @@ LSN translog_get_file_max_lsn_stored(uint32 file) ...@@ -1021,7 +1045,7 @@ LSN translog_get_file_max_lsn_stored(uint32 file)
DBUG_PRINT("enter", ("file: %lu", (ulong)file)); DBUG_PRINT("enter", ("file: %lu", (ulong)file));
DBUG_ASSERT(translog_inited == 1); DBUG_ASSERT(translog_inited == 1);
pthread_mutex_lock(&log_descriptor.unfinished_files_lock); translog_mutex_lock(&log_descriptor.unfinished_files_lock);
/* find file with minimum file number "in progress" */ /* find file with minimum file number "in progress" */
if (log_descriptor.unfinished_files.elements > 0) if (log_descriptor.unfinished_files.elements > 0)
...@@ -1031,7 +1055,7 @@ LSN translog_get_file_max_lsn_stored(uint32 file) ...@@ -1031,7 +1055,7 @@ LSN translog_get_file_max_lsn_stored(uint32 file)
0, struct st_file_counter *); 0, struct st_file_counter *);
limit= fc_ptr->file; /* minimal file number "in progress" */ limit= fc_ptr->file; /* minimal file number "in progress" */
} }
pthread_mutex_unlock(&log_descriptor.unfinished_files_lock); translog_mutex_unlock(&log_descriptor.unfinished_files_lock);
/* /*
if there is no "in progress file" then unfinished file is in progress if there is no "in progress file" then unfinished file is in progress
...@@ -1084,7 +1108,7 @@ static my_bool translog_buffer_init(struct st_translog_buffer *buffer) ...@@ -1084,7 +1108,7 @@ static my_bool translog_buffer_init(struct st_translog_buffer *buffer)
buffer->file= -1; buffer->file= -1;
buffer->overlay= 0; buffer->overlay= 0;
/* IO cache for current log */ /* IO cache for current log */
bzero(buffer->buffer, TRANSLOG_WRITE_BUFFER); memset(buffer->buffer, TRANSLOG_FILLER, TRANSLOG_WRITE_BUFFER);
/* Buffer size */ /* Buffer size */
buffer->size= 0; buffer->size= 0;
/* cond of thread which is waiting for buffer filling */ /* cond of thread which is waiting for buffer filling */
...@@ -1194,7 +1218,7 @@ static my_bool translog_buffer_lock(struct st_translog_buffer *buffer) ...@@ -1194,7 +1218,7 @@ static my_bool translog_buffer_lock(struct st_translog_buffer *buffer)
("Lock buffer #%u: (0x%lx) mutex: 0x%lx", ("Lock buffer #%u: (0x%lx) mutex: 0x%lx",
(uint) buffer->buffer_no, (ulong) buffer, (uint) buffer->buffer_no, (ulong) buffer,
(ulong) &buffer->mutex)); (ulong) &buffer->mutex));
res= (pthread_mutex_lock(&buffer->mutex) != 0); res= (translog_mutex_lock(&buffer->mutex) != 0);
DBUG_RETURN(res); DBUG_RETURN(res);
} }
#else #else
...@@ -1225,7 +1249,7 @@ static my_bool translog_buffer_unlock(struct st_translog_buffer *buffer) ...@@ -1225,7 +1249,7 @@ static my_bool translog_buffer_unlock(struct st_translog_buffer *buffer)
(uint) buffer->buffer_no, (ulong) buffer, (uint) buffer->buffer_no, (ulong) buffer,
(ulong) &buffer->mutex)); (ulong) &buffer->mutex));
res= (pthread_mutex_unlock(&buffer->mutex) != 0); res= (translog_mutex_unlock(&buffer->mutex) != 0);
DBUG_PRINT("enter", ("Unlocked buffer... #%u: 0x%lx mutex: 0x%lx", DBUG_PRINT("enter", ("Unlocked buffer... #%u: 0x%lx mutex: 0x%lx",
(uint) buffer->buffer_no, (ulong) buffer, (uint) buffer->buffer_no, (ulong) buffer,
(ulong) &buffer->mutex)); (ulong) &buffer->mutex));
...@@ -1266,7 +1290,9 @@ static void translog_new_page_header(TRANSLOG_ADDRESS *horizon, ...@@ -1266,7 +1290,9 @@ static void translog_new_page_header(TRANSLOG_ADDRESS *horizon,
/* File number */ /* File number */
int3store(ptr, LSN_FILE_NO(*horizon)); int3store(ptr, LSN_FILE_NO(*horizon));
ptr+= 3; ptr+= 3;
*(ptr++)= (uchar) log_descriptor.flags; DBUG_ASSERT(TRANSLOG_PAGE_FLAGS == (ptr - cursor->ptr));
cursor->ptr[TRANSLOG_PAGE_FLAGS]= (uchar) log_descriptor.flags;
ptr++;
if (log_descriptor.flags & TRANSLOG_PAGE_CRC) if (log_descriptor.flags & TRANSLOG_PAGE_CRC)
{ {
#ifndef DBUG_OFF #ifndef DBUG_OFF
...@@ -1397,7 +1423,7 @@ static void translog_finish_page(TRANSLOG_ADDRESS *horizon, ...@@ -1397,7 +1423,7 @@ static void translog_finish_page(TRANSLOG_ADDRESS *horizon,
struct st_buffer_cursor *cursor) struct st_buffer_cursor *cursor)
{ {
uint16 left= TRANSLOG_PAGE_SIZE - cursor->current_page_fill; uint16 left= TRANSLOG_PAGE_SIZE - cursor->current_page_fill;
uchar *page= cursor->ptr -cursor->current_page_fill; uchar *page= cursor->ptr - cursor->current_page_fill;
DBUG_ENTER("translog_finish_page"); DBUG_ENTER("translog_finish_page");
DBUG_PRINT("enter", ("Buffer: #%u 0x%lx " DBUG_PRINT("enter", ("Buffer: #%u 0x%lx "
"Buffer addr: (%lu,0x%lx) " "Buffer addr: (%lu,0x%lx) "
...@@ -1424,7 +1450,7 @@ static void translog_finish_page(TRANSLOG_ADDRESS *horizon, ...@@ -1424,7 +1450,7 @@ static void translog_finish_page(TRANSLOG_ADDRESS *horizon,
if (left != 0) if (left != 0)
{ {
DBUG_PRINT("info", ("left: %u", (uint) left)); DBUG_PRINT("info", ("left: %u", (uint) left));
bzero(cursor->ptr, left); memset(cursor->ptr, TRANSLOG_FILLER, left);
cursor->ptr +=left; cursor->ptr +=left;
(*horizon)+= left; /* offset increasing */ (*horizon)+= left; /* offset increasing */
if (!cursor->chaser) if (!cursor->chaser)
...@@ -1438,14 +1464,19 @@ static void translog_finish_page(TRANSLOG_ADDRESS *horizon, ...@@ -1438,14 +1464,19 @@ static void translog_finish_page(TRANSLOG_ADDRESS *horizon,
(ulong) (cursor->ptr - cursor->buffer->buffer))); (ulong) (cursor->ptr - cursor->buffer->buffer)));
DBUG_EXECUTE("info", translog_check_cursor(cursor);); DBUG_EXECUTE("info", translog_check_cursor(cursor););
} }
if (page[TRANSLOG_PAGE_FLAGS] & TRANSLOG_SECTOR_PROTECTION) /*
When we are finishing the page other thread might not finish the page
header yet so we have to read log_descriptor.flags but not the flags
from the page
*/
if (log_descriptor.flags & TRANSLOG_SECTOR_PROTECTION)
{ {
translog_put_sector_protection(page, cursor); translog_put_sector_protection(page, cursor);
DBUG_PRINT("info", ("drop write_counter")); DBUG_PRINT("info", ("drop write_counter"));
cursor->write_counter= 0; cursor->write_counter= 0;
cursor->previous_offset= 0; cursor->previous_offset= 0;
} }
if (page[TRANSLOG_PAGE_FLAGS] & TRANSLOG_PAGE_CRC) if (log_descriptor.flags & TRANSLOG_PAGE_CRC)
{ {
uint32 crc= translog_crc(page + log_descriptor.page_overhead, uint32 crc= translog_crc(page + log_descriptor.page_overhead,
TRANSLOG_PAGE_SIZE - TRANSLOG_PAGE_SIZE -
...@@ -1688,7 +1719,7 @@ static my_bool translog_buffer_next(TRANSLOG_ADDRESS *horizon, ...@@ -1688,7 +1719,7 @@ static my_bool translog_buffer_next(TRANSLOG_ADDRESS *horizon,
static void translog_set_sent_to_file(LSN lsn, TRANSLOG_ADDRESS in_buffers) static void translog_set_sent_to_file(LSN lsn, TRANSLOG_ADDRESS in_buffers)
{ {
DBUG_ENTER("translog_set_sent_to_file"); DBUG_ENTER("translog_set_sent_to_file");
pthread_mutex_lock(&log_descriptor.sent_to_file_lock); translog_mutex_lock(&log_descriptor.sent_to_file_lock);
DBUG_PRINT("enter", ("lsn: (%lu,0x%lx) in_buffers: (%lu,0x%lx) " DBUG_PRINT("enter", ("lsn: (%lu,0x%lx) in_buffers: (%lu,0x%lx) "
"in_buffers_only: (%lu,0x%lx)", "in_buffers_only: (%lu,0x%lx)",
LSN_IN_PARTS(lsn), LSN_IN_PARTS(lsn),
...@@ -1702,7 +1733,7 @@ static void translog_set_sent_to_file(LSN lsn, TRANSLOG_ADDRESS in_buffers) ...@@ -1702,7 +1733,7 @@ static void translog_set_sent_to_file(LSN lsn, TRANSLOG_ADDRESS in_buffers)
log_descriptor.in_buffers_only= in_buffers; log_descriptor.in_buffers_only= in_buffers;
DBUG_PRINT("info", ("set new in_buffers_only")); DBUG_PRINT("info", ("set new in_buffers_only"));
} }
pthread_mutex_unlock(&log_descriptor.sent_to_file_lock); translog_mutex_unlock(&log_descriptor.sent_to_file_lock);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -1719,7 +1750,7 @@ static void translog_set_sent_to_file(LSN lsn, TRANSLOG_ADDRESS in_buffers) ...@@ -1719,7 +1750,7 @@ static void translog_set_sent_to_file(LSN lsn, TRANSLOG_ADDRESS in_buffers)
static void translog_set_only_in_buffers(TRANSLOG_ADDRESS in_buffers) static void translog_set_only_in_buffers(TRANSLOG_ADDRESS in_buffers)
{ {
DBUG_ENTER("translog_set_only_in_buffers"); DBUG_ENTER("translog_set_only_in_buffers");
pthread_mutex_lock(&log_descriptor.sent_to_file_lock); translog_mutex_lock(&log_descriptor.sent_to_file_lock);
DBUG_PRINT("enter", ("in_buffers: (%lu,0x%lx) " DBUG_PRINT("enter", ("in_buffers: (%lu,0x%lx) "
"in_buffers_only: (%lu,0x%lx)", "in_buffers_only: (%lu,0x%lx)",
LSN_IN_PARTS(in_buffers), LSN_IN_PARTS(in_buffers),
...@@ -1730,7 +1761,7 @@ static void translog_set_only_in_buffers(TRANSLOG_ADDRESS in_buffers) ...@@ -1730,7 +1761,7 @@ static void translog_set_only_in_buffers(TRANSLOG_ADDRESS in_buffers)
log_descriptor.in_buffers_only= in_buffers; log_descriptor.in_buffers_only= in_buffers;
DBUG_PRINT("info", ("set new in_buffers_only")); DBUG_PRINT("info", ("set new in_buffers_only"));
} }
pthread_mutex_unlock(&log_descriptor.sent_to_file_lock); translog_mutex_unlock(&log_descriptor.sent_to_file_lock);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -1749,9 +1780,9 @@ static TRANSLOG_ADDRESS translog_only_in_buffers() ...@@ -1749,9 +1780,9 @@ static TRANSLOG_ADDRESS translog_only_in_buffers()
{ {
register TRANSLOG_ADDRESS addr; register TRANSLOG_ADDRESS addr;
DBUG_ENTER("translog_only_in_buffers"); DBUG_ENTER("translog_only_in_buffers");
pthread_mutex_lock(&log_descriptor.sent_to_file_lock); translog_mutex_lock(&log_descriptor.sent_to_file_lock);
addr= log_descriptor.in_buffers_only; addr= log_descriptor.in_buffers_only;
pthread_mutex_unlock(&log_descriptor.sent_to_file_lock); translog_mutex_unlock(&log_descriptor.sent_to_file_lock);
DBUG_RETURN(addr); DBUG_RETURN(addr);
} }
...@@ -1770,9 +1801,9 @@ static LSN translog_get_sent_to_file() ...@@ -1770,9 +1801,9 @@ static LSN translog_get_sent_to_file()
{ {
register LSN lsn; register LSN lsn;
DBUG_ENTER("translog_get_sent_to_file"); DBUG_ENTER("translog_get_sent_to_file");
pthread_mutex_lock(&log_descriptor.sent_to_file_lock); translog_mutex_lock(&log_descriptor.sent_to_file_lock);
lsn= log_descriptor.sent_to_file; lsn= log_descriptor.sent_to_file;
pthread_mutex_unlock(&log_descriptor.sent_to_file_lock); translog_mutex_unlock(&log_descriptor.sent_to_file_lock);
DBUG_RETURN(lsn); DBUG_RETURN(lsn);
} }
...@@ -2080,7 +2111,7 @@ static my_bool translog_recover_page_up_to_sector(uchar *page, uint16 offset) ...@@ -2080,7 +2111,7 @@ static my_bool translog_recover_page_up_to_sector(uchar *page, uint16 offset)
DBUG_PRINT("enter", ("offset: %u first chunk: %u", DBUG_PRINT("enter", ("offset: %u first chunk: %u",
(uint) offset, (uint) chunk_offset)); (uint) offset, (uint) chunk_offset));
while (page[chunk_offset] != '\0' && chunk_offset < offset) while (page[chunk_offset] != TRANSLOG_FILLER && chunk_offset < offset)
{ {
uint16 chunk_length; uint16 chunk_length;
if ((chunk_length= if ((chunk_length=
...@@ -2103,7 +2134,7 @@ static my_bool translog_recover_page_up_to_sector(uchar *page, uint16 offset) ...@@ -2103,7 +2134,7 @@ static my_bool translog_recover_page_up_to_sector(uchar *page, uint16 offset)
valid_chunk_end= chunk_offset; valid_chunk_end= chunk_offset;
/* end of trusted area - sector parsing */ /* end of trusted area - sector parsing */
while (page[chunk_offset] != '\0') while (page[chunk_offset] != TRANSLOG_FILLER)
{ {
uint16 chunk_length; uint16 chunk_length;
if ((chunk_length= if ((chunk_length=
...@@ -2121,7 +2152,8 @@ static my_bool translog_recover_page_up_to_sector(uchar *page, uint16 offset) ...@@ -2121,7 +2152,8 @@ static my_bool translog_recover_page_up_to_sector(uchar *page, uint16 offset)
} }
DBUG_PRINT("info", ("valid chunk end offset: %u", (uint) valid_chunk_end)); DBUG_PRINT("info", ("valid chunk end offset: %u", (uint) valid_chunk_end));
bzero(page + valid_chunk_end, TRANSLOG_PAGE_SIZE - valid_chunk_end); memset(page + valid_chunk_end, TRANSLOG_FILLER,
TRANSLOG_PAGE_SIZE - valid_chunk_end);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -2879,10 +2911,11 @@ my_bool translog_init(const char *directory, ...@@ -2879,10 +2911,11 @@ my_bool translog_init(const char *directory,
log_descriptor.horizon= last_valid_page; log_descriptor.horizon= last_valid_page;
translog_start_buffer(log_descriptor.buffers, &log_descriptor.bc, 0); translog_start_buffer(log_descriptor.buffers, &log_descriptor.bc, 0);
/* /*
Free space if filled with 0 and first uchar of Free space if filled with TRANSLOG_FILLER and first uchar of
real chunk can't be 0 real chunk can't be TRANSLOG_FILLER
*/ */
while (chunk_offset < TRANSLOG_PAGE_SIZE && page[chunk_offset] != '\0') while (chunk_offset < TRANSLOG_PAGE_SIZE &&
page[chunk_offset] != TRANSLOG_FILLER)
{ {
uint16 chunk_length; uint16 chunk_length;
if ((chunk_length= if ((chunk_length=
...@@ -5340,7 +5373,7 @@ static my_bool translog_scanner_eop(TRANSLOG_SCANNER_DATA *scanner) ...@@ -5340,7 +5373,7 @@ static my_bool translog_scanner_eop(TRANSLOG_SCANNER_DATA *scanner)
{ {
DBUG_ENTER("translog_scanner_eop"); DBUG_ENTER("translog_scanner_eop");
DBUG_RETURN(scanner->page_offset >= TRANSLOG_PAGE_SIZE || DBUG_RETURN(scanner->page_offset >= TRANSLOG_PAGE_SIZE ||
scanner->page[scanner->page_offset] == 0); scanner->page[scanner->page_offset] == TRANSLOG_FILLER);
} }
...@@ -5401,7 +5434,7 @@ translog_get_next_chunk(TRANSLOG_SCANNER_DATA *scanner) ...@@ -5401,7 +5434,7 @@ translog_get_next_chunk(TRANSLOG_SCANNER_DATA *scanner)
if (translog_scanner_eol(scanner)) if (translog_scanner_eol(scanner))
{ {
scanner->page= &end_of_log; scanner->page= END_OF_LOG;
scanner->page_offset= 0; scanner->page_offset= 0;
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -5434,11 +5467,11 @@ translog_get_next_chunk(TRANSLOG_SCANNER_DATA *scanner) ...@@ -5434,11 +5467,11 @@ translog_get_next_chunk(TRANSLOG_SCANNER_DATA *scanner)
scanner->page_offset= translog_get_first_chunk_offset(scanner->page); scanner->page_offset= translog_get_first_chunk_offset(scanner->page);
if (translog_scanner_eol(scanner)) if (translog_scanner_eol(scanner))
{ {
scanner->page= &end_of_log; scanner->page= END_OF_LOG;
scanner->page_offset= 0; scanner->page_offset= 0;
DBUG_RETURN(0); DBUG_RETURN(0);
} }
DBUG_ASSERT(scanner->page[scanner->page_offset]); DBUG_ASSERT(scanner->page[scanner->page_offset] != TRANSLOG_FILLER);
} }
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -5456,6 +5489,7 @@ translog_get_next_chunk(TRANSLOG_SCANNER_DATA *scanner) ...@@ -5456,6 +5489,7 @@ translog_get_next_chunk(TRANSLOG_SCANNER_DATA *scanner)
@return Length of header or operation status @return Length of header or operation status
@retval RECHEADER_READ_ERROR error @retval RECHEADER_READ_ERROR error
@retval RECHEADER_READ_EOF End of the log reached during the read
@retval # number of bytes in @retval # number of bytes in
TRANSLOG_HEADER_BUFFER::header where TRANSLOG_HEADER_BUFFER::header where
stored decoded part of the header stored decoded part of the header
...@@ -5562,7 +5596,17 @@ translog_variable_length_header(uchar *page, translog_size_t page_offset, ...@@ -5562,7 +5596,17 @@ translog_variable_length_header(uchar *page, translog_size_t page_offset,
DBUG_RETURN(RECHEADER_READ_ERROR); DBUG_RETURN(RECHEADER_READ_ERROR);
} }
if (translog_get_next_chunk(scanner)) if (translog_get_next_chunk(scanner))
{
if (scanner == &internal_scanner)
translog_destroy_scanner(scanner);
DBUG_RETURN(RECHEADER_READ_ERROR); DBUG_RETURN(RECHEADER_READ_ERROR);
}
if (scanner->page == END_OF_LOG)
{
if (scanner == &internal_scanner)
translog_destroy_scanner(scanner);
DBUG_RETURN(RECHEADER_READ_EOF);
}
page= scanner->page; page= scanner->page;
page_offset= scanner->page_offset; page_offset= scanner->page_offset;
src= page + page_offset + header_to_skip; src= page + page_offset + header_to_skip;
...@@ -5804,14 +5848,26 @@ int translog_read_next_record_header(TRANSLOG_SCANNER_DATA *scanner, ...@@ -5804,14 +5848,26 @@ int translog_read_next_record_header(TRANSLOG_SCANNER_DATA *scanner,
{ {
if (translog_get_next_chunk(scanner)) if (translog_get_next_chunk(scanner))
DBUG_RETURN(RECHEADER_READ_ERROR); DBUG_RETURN(RECHEADER_READ_ERROR);
if (scanner->page == END_OF_LOG)
{
DBUG_PRINT("info", ("End of file from the scanner"));
/* Last record was read */
buff->lsn= LSN_IMPOSSIBLE;
DBUG_RETURN(RECHEADER_READ_EOF);
}
chunk_type= scanner->page[scanner->page_offset] & TRANSLOG_CHUNK_TYPE; chunk_type= scanner->page[scanner->page_offset] & TRANSLOG_CHUNK_TYPE;
DBUG_PRINT("info", ("type: %x byte: %x", (uint) chunk_type, DBUG_PRINT("info", ("Page: (%lu,0x%lx) offset: %lu type: %x byte: %x",
LSN_IN_PARTS(scanner->page_addr),
(ulong) scanner->page_offset,
(uint) chunk_type,
(uint) scanner->page[scanner->page_offset])); (uint) scanner->page[scanner->page_offset]));
} while (chunk_type != TRANSLOG_CHUNK_LSN && chunk_type != } while (chunk_type != TRANSLOG_CHUNK_LSN &&
TRANSLOG_CHUNK_FIXED && scanner->page[scanner->page_offset] != 0); chunk_type != TRANSLOG_CHUNK_FIXED &&
scanner->page[scanner->page_offset] != TRANSLOG_FILLER);
if (scanner->page[scanner->page_offset] == 0) if (scanner->page[scanner->page_offset] == TRANSLOG_FILLER)
{ {
DBUG_PRINT("info", ("End of file"));
/* Last record was read */ /* Last record was read */
buff->lsn= LSN_IMPOSSIBLE; buff->lsn= LSN_IMPOSSIBLE;
/* Return 'end of log' marker */ /* Return 'end of log' marker */
...@@ -5867,6 +5923,14 @@ static my_bool translog_record_read_next_chunk(struct st_translog_reader_data ...@@ -5867,6 +5923,14 @@ static my_bool translog_record_read_next_chunk(struct st_translog_reader_data
data->current_chunk++; data->current_chunk++;
if (translog_get_next_chunk(&data->scanner)) if (translog_get_next_chunk(&data->scanner))
DBUG_RETURN(1); DBUG_RETURN(1);
if (data->scanner.page == END_OF_LOG)
{
/*
Actually it should not happened, but we wont quite nice in case of
cut log
*/
DBUG_RETURN(1);
}
} }
type= data->scanner.page[data->scanner.page_offset] & TRANSLOG_CHUNK_TYPE; type= data->scanner.page[data->scanner.page_offset] & TRANSLOG_CHUNK_TYPE;
...@@ -6128,7 +6192,7 @@ static void translog_force_current_buffer_to_finish() ...@@ -6128,7 +6192,7 @@ static void translog_force_current_buffer_to_finish()
new_buff_beginning-= log_descriptor.bc.current_page_fill; new_buff_beginning-= log_descriptor.bc.current_page_fill;
current_page_fill= log_descriptor.bc.current_page_fill; current_page_fill= log_descriptor.bc.current_page_fill;
bzero(log_descriptor.bc.ptr, left); memset(log_descriptor.bc.ptr, TRANSLOG_FILLER, left);
log_descriptor.bc.buffer->size+= left; log_descriptor.bc.buffer->size+= left;
DBUG_PRINT("info", ("Finish Page buffer #%u: 0x%lx " DBUG_PRINT("info", ("Finish Page buffer #%u: 0x%lx "
"Size: %lu", "Size: %lu",
...@@ -6177,8 +6241,7 @@ static void translog_force_current_buffer_to_finish() ...@@ -6177,8 +6241,7 @@ static void translog_force_current_buffer_to_finish()
*/ */
translog_wait_for_writers(old_buffer); translog_wait_for_writers(old_buffer);
if (log_descriptor.flags & TRANSLOG_SECTOR_PROTECTION)
if (data[TRANSLOG_PAGE_FLAGS] & TRANSLOG_SECTOR_PROTECTION)
{ {
translog_put_sector_protection(data, &log_descriptor.bc); translog_put_sector_protection(data, &log_descriptor.bc);
if (left) if (left)
...@@ -6194,7 +6257,7 @@ static void translog_force_current_buffer_to_finish() ...@@ -6194,7 +6257,7 @@ static void translog_force_current_buffer_to_finish()
} }
} }
if (data[TRANSLOG_PAGE_FLAGS] & TRANSLOG_PAGE_CRC) if (log_descriptor.flags & TRANSLOG_PAGE_CRC)
{ {
uint32 crc= translog_crc(data + log_descriptor.page_overhead, uint32 crc= translog_crc(data + log_descriptor.page_overhead,
TRANSLOG_PAGE_SIZE - TRANSLOG_PAGE_SIZE -
...@@ -6260,7 +6323,7 @@ my_bool translog_flush(LSN lsn) ...@@ -6260,7 +6323,7 @@ my_bool translog_flush(LSN lsn)
DBUG_PRINT("enter", ("Flush up to LSN: (%lu,0x%lx)", LSN_IN_PARTS(lsn))); DBUG_PRINT("enter", ("Flush up to LSN: (%lu,0x%lx)", LSN_IN_PARTS(lsn)));
DBUG_ASSERT(translog_inited == 1); DBUG_ASSERT(translog_inited == 1);
pthread_mutex_lock(&log_descriptor.log_flush_lock); translog_mutex_lock(&log_descriptor.log_flush_lock);
translog_lock(); translog_lock();
old_flushed= log_descriptor.flushed; old_flushed= log_descriptor.flushed;
for (;;) for (;;)
...@@ -6343,7 +6406,7 @@ my_bool translog_flush(LSN lsn) ...@@ -6343,7 +6406,7 @@ my_bool translog_flush(LSN lsn)
/** @todo LOG decide if syncing of directory is needed */ /** @todo LOG decide if syncing of directory is needed */
rc|= my_sync(log_descriptor.directory_fd, MYF(MY_WME | MY_IGNORE_BADFD)); rc|= my_sync(log_descriptor.directory_fd, MYF(MY_WME | MY_IGNORE_BADFD));
out: out:
pthread_mutex_unlock(&log_descriptor.log_flush_lock); translog_mutex_unlock(&log_descriptor.log_flush_lock);
DBUG_RETURN(rc); DBUG_RETURN(rc);
} }
...@@ -6374,7 +6437,7 @@ int translog_assign_id_to_share(MARIA_HA *tbl_info, TRN *trn) ...@@ -6374,7 +6437,7 @@ int translog_assign_id_to_share(MARIA_HA *tbl_info, TRN *trn)
*/ */
DBUG_ASSERT(share->data_file_type == BLOCK_RECORD); DBUG_ASSERT(share->data_file_type == BLOCK_RECORD);
/* re-check under mutex to avoid having 2 ids for the same share */ /* re-check under mutex to avoid having 2 ids for the same share */
pthread_mutex_lock(&share->intern_lock); translog_mutex_lock(&share->intern_lock);
if (likely(share->id == 0)) if (likely(share->id == 0))
{ {
/* Inspired by set_short_trid() of trnman.c */ /* Inspired by set_short_trid() of trnman.c */
...@@ -6421,7 +6484,7 @@ int translog_assign_id_to_share(MARIA_HA *tbl_info, TRN *trn) ...@@ -6421,7 +6484,7 @@ int translog_assign_id_to_share(MARIA_HA *tbl_info, TRN *trn)
log_array, log_data, NULL))) log_array, log_data, NULL)))
return 1; return 1;
} }
pthread_mutex_unlock(&share->intern_lock); translog_mutex_unlock(&share->intern_lock);
return 0; return 0;
} }
...@@ -6498,14 +6561,14 @@ static uint32 translog_first_file(TRANSLOG_ADDRESS horizon, int is_protected) ...@@ -6498,14 +6561,14 @@ static uint32 translog_first_file(TRANSLOG_ADDRESS horizon, int is_protected)
uint min_file= 1, max_file; uint min_file= 1, max_file;
DBUG_ENTER("translog_first_file"); DBUG_ENTER("translog_first_file");
if (!is_protected) if (!is_protected)
pthread_mutex_lock(&log_descriptor.purger_lock); translog_mutex_lock(&log_descriptor.purger_lock);
if (log_descriptor.min_file_number && if (log_descriptor.min_file_number &&
translog_is_file(log_descriptor.min_file_number)) translog_is_file(log_descriptor.min_file_number))
{ {
DBUG_PRINT("info", ("cached %lu", DBUG_PRINT("info", ("cached %lu",
(ulong) log_descriptor.min_file_number)); (ulong) log_descriptor.min_file_number));
if (!is_protected) if (!is_protected)
pthread_mutex_unlock(&log_descriptor.purger_lock); translog_mutex_unlock(&log_descriptor.purger_lock);
DBUG_RETURN(log_descriptor.min_file_number); DBUG_RETURN(log_descriptor.min_file_number);
} }
...@@ -6532,7 +6595,7 @@ static uint32 translog_first_file(TRANSLOG_ADDRESS horizon, int is_protected) ...@@ -6532,7 +6595,7 @@ static uint32 translog_first_file(TRANSLOG_ADDRESS horizon, int is_protected)
} }
log_descriptor.min_file_number= max_file; log_descriptor.min_file_number= max_file;
if (!is_protected) if (!is_protected)
pthread_mutex_unlock(&log_descriptor.purger_lock); translog_mutex_unlock(&log_descriptor.purger_lock);
DBUG_RETURN(max_file); DBUG_RETURN(max_file);
} }
...@@ -6568,19 +6631,28 @@ LSN translog_next_LSN(TRANSLOG_ADDRESS addr, TRANSLOG_ADDRESS horizon) ...@@ -6568,19 +6631,28 @@ LSN translog_next_LSN(TRANSLOG_ADDRESS addr, TRANSLOG_ADDRESS horizon)
(uint) scanner.page[scanner.page_offset])); (uint) scanner.page[scanner.page_offset]));
while (chunk_type != TRANSLOG_CHUNK_LSN && while (chunk_type != TRANSLOG_CHUNK_LSN &&
chunk_type != TRANSLOG_CHUNK_FIXED && chunk_type != TRANSLOG_CHUNK_FIXED &&
scanner.page[scanner.page_offset] != 0) scanner.page[scanner.page_offset] != TRANSLOG_FILLER)
{ {
if (translog_get_next_chunk(&scanner)) if (translog_get_next_chunk(&scanner))
DBUG_RETURN(LSN_ERROR); {
result= LSN_ERROR;
goto out;
}
if (scanner.page == END_OF_LOG)
{
result= LSN_IMPOSSIBLE;
goto out;
}
chunk_type= scanner.page[scanner.page_offset] & TRANSLOG_CHUNK_TYPE; chunk_type= scanner.page[scanner.page_offset] & TRANSLOG_CHUNK_TYPE;
DBUG_PRINT("info", ("type: %x byte: %x", (uint) chunk_type, DBUG_PRINT("info", ("type: %x byte: %x", (uint) chunk_type,
(uint) scanner.page[scanner.page_offset])); (uint) scanner.page[scanner.page_offset]));
} }
if (scanner.page[scanner.page_offset] == 0) if (scanner.page[scanner.page_offset] == TRANSLOG_FILLER)
result= LSN_IMPOSSIBLE; /* reached page filler */ result= LSN_IMPOSSIBLE; /* reached page filler */
else else
result= scanner.page_addr + scanner.page_offset; result= scanner.page_addr + scanner.page_offset;
out:
translog_destroy_scanner(&scanner); translog_destroy_scanner(&scanner);
DBUG_RETURN(result); DBUG_RETURN(result);
} }
...@@ -6678,7 +6750,7 @@ my_bool translog_purge(TRANSLOG_ADDRESS low) ...@@ -6678,7 +6750,7 @@ my_bool translog_purge(TRANSLOG_ADDRESS low)
DBUG_PRINT("enter", ("low: (%lu,0x%lx)", LSN_IN_PARTS(low))); DBUG_PRINT("enter", ("low: (%lu,0x%lx)", LSN_IN_PARTS(low)));
DBUG_ASSERT(translog_inited == 1); DBUG_ASSERT(translog_inited == 1);
pthread_mutex_lock(&log_descriptor.purger_lock); translog_mutex_lock(&log_descriptor.purger_lock);
if (LSN_FILE_NO(log_descriptor.last_lsn_checked) < last_need_file) if (LSN_FILE_NO(log_descriptor.last_lsn_checked) < last_need_file)
{ {
uint32 i; uint32 i;
...@@ -6706,6 +6778,6 @@ my_bool translog_purge(TRANSLOG_ADDRESS low) ...@@ -6706,6 +6778,6 @@ my_bool translog_purge(TRANSLOG_ADDRESS low)
} }
} }
pthread_mutex_unlock(&log_descriptor.purger_lock); translog_mutex_unlock(&log_descriptor.purger_lock);
DBUG_RETURN(rc); DBUG_RETURN(rc);
} }
...@@ -83,7 +83,7 @@ typedef LSN LSN_WITH_FLAGS; ...@@ -83,7 +83,7 @@ typedef LSN LSN_WITH_FLAGS;
#define FILENO_IMPOSSIBLE 0 /**< log file's numbering starts at 1 */ #define FILENO_IMPOSSIBLE 0 /**< log file's numbering starts at 1 */
#define LOG_OFFSET_IMPOSSIBLE 0 /**< log always has a header */ #define LOG_OFFSET_IMPOSSIBLE 0 /**< log always has a header */
#define LSN_IMPOSSIBLE 0 #define LSN_IMPOSSIBLE 0L
/* following LSN also is impossible */ /* following LSN also is impossible */
#define LSN_ERROR 1 #define LSN_ERROR 1
......
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