Commit b2ca3d93 authored by unknown's avatar unknown

Fixed that ma_test_all works with -T (simple transaction/logging support)

Some fixes from Sanja


BitKeeper/etc/ignore:
  added storage/maria/maria_log.*
include/pagecache.h:
  Always have enum PAGECACHE_EMPTY_PAGE available
  (Simpler code)
storage/maria/ma_bitmap.c:
  Reset 'debugging' bitmap when creating new one (fixes valgrind warning)
storage/maria/ma_blockrec.c:
  Removed duplicate (wrong) initialization
  Reset not initialized variable
storage/maria/ma_check.c:
  Use right page type
  (Patch from Sanja)
storage/maria/ma_init.c:
  Reset logging in maria_end()
  (Fixes memory leak)
storage/maria/ma_loghandler.c:
  Add missing copyright header
  Added checking of duplicate calls or calls without init to translog_destroy()
  Don't lock mutex before destroying them (not needed as you can't use a destroyed mutex anyway)
storage/maria/ma_pagecache.c:
  Added extra page type text
  Trivial indentation fixes
storage/maria/ma_test1.c:
  Added transaction setup
  (Patch from Sanja)
storage/maria/ma_test2.c:
  Added transaction setup
  (Patch from Sanja)
parent de6183fd
...@@ -2998,3 +2998,5 @@ storage/maria/unittest/ma_pagecache_consist_64kHC-t-big ...@@ -2998,3 +2998,5 @@ storage/maria/unittest/ma_pagecache_consist_64kHC-t-big
storage/maria/unittest/ma_pagecache_consist_64kRD-t-big storage/maria/unittest/ma_pagecache_consist_64kRD-t-big
storage/maria/unittest/ma_pagecache_consist_64kWR-t-big storage/maria/unittest/ma_pagecache_consist_64kWR-t-big
storage/maria/unittest/ma_pagecache_single_64k-t-big storage/maria/unittest/ma_pagecache_single_64k-t-big
storage/maria/maria_control
storage/maria/maria_log.*
...@@ -26,10 +26,11 @@ C_MODE_START ...@@ -26,10 +26,11 @@ C_MODE_START
/* Type of the page */ /* Type of the page */
enum pagecache_page_type enum pagecache_page_type
{ {
#ifndef DBUG_OFF /*
/* used only for control page type changing during debugging */ Used only for control page type changing during debugging. This define
should only be using when using DBUG.
*/
PAGECACHE_EMPTY_PAGE, PAGECACHE_EMPTY_PAGE,
#endif
/* the page does not contain LSN */ /* the page does not contain LSN */
PAGECACHE_PLAIN_PAGE, PAGECACHE_PLAIN_PAGE,
/* the page contain LSN (maria tablespace page) */ /* the page contain LSN (maria tablespace page) */
......
...@@ -505,6 +505,9 @@ static my_bool _ma_read_bitmap_page(MARIA_SHARE *share, ...@@ -505,6 +505,9 @@ static my_bool _ma_read_bitmap_page(MARIA_SHARE *share,
bzero(bitmap->map, bitmap->block_size); bzero(bitmap->map, bitmap->block_size);
memcpy(bitmap->map + share->block_size - 2, maria_bitmap_marker, 2); memcpy(bitmap->map + share->block_size - 2, maria_bitmap_marker, 2);
bitmap->used_size= 0; bitmap->used_size= 0;
#ifndef DBUG_OFF
memcpy(bitmap->map + bitmap->block_size, bitmap->map, bitmap->block_size);
#endif
DBUG_RETURN(0); DBUG_RETURN(0);
} }
bitmap->used_size= bitmap->total_size; bitmap->used_size= bitmap->total_size;
......
...@@ -3640,7 +3640,6 @@ static size_t fill_insert_undo_parts(MARIA_HA *info, const byte *record, ...@@ -3640,7 +3640,6 @@ static size_t fill_insert_undo_parts(MARIA_HA *info, const byte *record,
log_parts++; log_parts++;
/* Stored bitmap over packed (zero length or all-zero fields) */ /* Stored bitmap over packed (zero length or all-zero fields) */
start_log_parts= log_parts;
log_parts->str= info->cur_row.empty_bits; log_parts->str= info->cur_row.empty_bits;
log_parts->length= share->base.pack_bytes; log_parts->length= share->base.pack_bytes;
row_length+= log_parts->length; row_length+= log_parts->length;
...@@ -3800,7 +3799,7 @@ static size_t fill_update_undo_parts(MARIA_HA *info, const byte *oldrec, ...@@ -3800,7 +3799,7 @@ static size_t fill_update_undo_parts(MARIA_HA *info, const byte *oldrec,
uchar *field_data, *start_field_data; uchar *field_data, *start_field_data;
uchar *old_field_lengths= old_row->field_lengths; uchar *old_field_lengths= old_row->field_lengths;
uchar *new_field_lengths= new_row->field_lengths; uchar *new_field_lengths= new_row->field_lengths;
size_t row_length; size_t row_length= 0;
uint field_count= 0; uint field_count= 0;
LEX_STRING *start_log_parts; LEX_STRING *start_log_parts;
my_bool new_column_is_empty; my_bool new_column_is_empty;
......
...@@ -1632,7 +1632,7 @@ static int check_block_record(HA_CHECK *param, MARIA_HA *info, int extend, ...@@ -1632,7 +1632,7 @@ static int check_block_record(HA_CHECK *param, MARIA_HA *info, int extend,
&info->dfile, &info->dfile,
(pos / block_size), 1, (pos / block_size), 1,
page_buff, page_buff,
PAGECACHE_PLAIN_PAGE, info->s->page_type,
PAGECACHE_LOCK_LEFT_UNLOCKED, 0) == 0) PAGECACHE_LOCK_LEFT_UNLOCKED, 0) == 0)
{ {
_ma_check_print_error(param, _ma_check_print_error(param,
......
...@@ -55,6 +55,8 @@ void maria_end(void) ...@@ -55,6 +55,8 @@ void maria_end(void)
{ {
maria_inited= FALSE; maria_inited= FALSE;
ft_free_stopwords(); ft_free_stopwords();
translog_destroy();
ma_control_file_end();
pthread_mutex_destroy(&THR_LOCK_maria); pthread_mutex_destroy(&THR_LOCK_maria);
} }
} }
/* Copyright (C) 2007 MySQL AB & Sanja Belkin
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "maria_def.h" #include "maria_def.h"
#include "ma_blockrec.h" #include "ma_blockrec.h"
...@@ -148,6 +163,8 @@ static struct st_translog_descriptor log_descriptor; ...@@ -148,6 +163,8 @@ static struct st_translog_descriptor log_descriptor;
/* Marker for end of log */ /* Marker for end of log */
static byte end_of_log= 0; static byte end_of_log= 0;
static my_bool translog_inited;
/* record classes */ /* record classes */
enum record_class enum record_class
{ {
...@@ -288,7 +305,7 @@ static LOG_DESC INIT_LOGREC_UNDO_ROW_DELETE= ...@@ -288,7 +305,7 @@ static LOG_DESC INIT_LOGREC_UNDO_ROW_DELETE=
static LOG_DESC INIT_LOGREC_UNDO_ROW_UPDATE= static LOG_DESC INIT_LOGREC_UNDO_ROW_UPDATE=
{LOGRECTYPE_VARIABLE_LENGTH, 0, {LOGRECTYPE_VARIABLE_LENGTH, 0,
LSN_STORE_SIZE + FILEID_STORE_SIZE + PAGE_STORE_SIZE + DIRPOS_STORE_SIZE, LSN_STORE_SIZE + FILEID_STORE_SIZE + PAGE_STORE_SIZE + DIRPOS_STORE_SIZE,
NULL, NULL, NULL, 2}; NULL, NULL, NULL, 1};
static LOG_DESC INIT_LOGREC_UNDO_ROW_PURGE= static LOG_DESC INIT_LOGREC_UNDO_ROW_PURGE=
{LOGRECTYPE_PSEUDOFIXEDLENGTH, LSN_STORE_SIZE, LSN_STORE_SIZE, {LOGRECTYPE_PSEUDOFIXEDLENGTH, LSN_STORE_SIZE, LSN_STORE_SIZE,
...@@ -1861,6 +1878,9 @@ static uint16 translog_get_chunk_header_length(byte *page, uint16 offset) ...@@ -1861,6 +1878,9 @@ static uint16 translog_get_chunk_header_length(byte *page, uint16 offset)
flags flags (TRANSLOG_PAGE_CRC, TRANSLOG_SECTOR_PROTECTION flags flags (TRANSLOG_PAGE_CRC, TRANSLOG_SECTOR_PROTECTION
TRANSLOG_RECORD_CRC) TRANSLOG_RECORD_CRC)
TODO
Free used resources in case of error.
RETURN RETURN
0 OK 0 OK
1 Error 1 Error
...@@ -1877,7 +1897,7 @@ my_bool translog_init(const char *directory, ...@@ -1877,7 +1897,7 @@ my_bool translog_init(const char *directory,
TRANSLOG_ADDRESS sure_page, last_page, last_valid_page; TRANSLOG_ADDRESS sure_page, last_page, last_valid_page;
DBUG_ENTER("translog_init"); DBUG_ENTER("translog_init");
loghandler_init(); loghandler_init(); /* Safe to do many times */
if (pthread_mutex_init(&log_descriptor.sent_to_file_lock, if (pthread_mutex_init(&log_descriptor.sent_to_file_lock,
MY_MUTEX_INIT_FAST)) MY_MUTEX_INIT_FAST))
...@@ -2164,6 +2184,7 @@ my_bool translog_init(const char *directory, ...@@ -2164,6 +2184,7 @@ my_bool translog_init(const char *directory,
log_descriptor.flushed--; /* offset decreased */ log_descriptor.flushed--; /* offset decreased */
log_descriptor.sent_to_file--; /* offset decreased */ log_descriptor.sent_to_file--; /* offset decreased */
translog_inited= 1;
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -2198,8 +2219,6 @@ static void translog_buffer_destroy(struct st_translog_buffer *buffer) ...@@ -2198,8 +2219,6 @@ static void translog_buffer_destroy(struct st_translog_buffer *buffer)
*/ */
translog_buffer_flush(buffer); translog_buffer_flush(buffer);
} }
DBUG_PRINT("info", ("Unlock mutex: 0x%lx", (ulong) &buffer->mutex));
pthread_mutex_unlock(&buffer->mutex);
DBUG_PRINT("info", ("Destroy mutex: 0x%lx", (ulong) &buffer->mutex)); DBUG_PRINT("info", ("Destroy mutex: 0x%lx", (ulong) &buffer->mutex));
pthread_mutex_destroy(&buffer->mutex); pthread_mutex_destroy(&buffer->mutex);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
...@@ -2217,27 +2236,28 @@ void translog_destroy() ...@@ -2217,27 +2236,28 @@ void translog_destroy()
{ {
uint i; uint i;
DBUG_ENTER("translog_destroy"); DBUG_ENTER("translog_destroy");
if (log_descriptor.bc.buffer->file != -1)
translog_finish_page(&log_descriptor.horizon, &log_descriptor.bc); if (translog_inited)
for (i= 0; i < TRANSLOG_BUFFERS_NO; i++)
{ {
struct st_translog_buffer *buffer= log_descriptor.buffers + i; if (log_descriptor.bc.buffer->file != -1)
/* translog_finish_page(&log_descriptor.horizon, &log_descriptor.bc);
Lock the buffer just for safety, there should not be other
threads running. for (i= 0; i < TRANSLOG_BUFFERS_NO; i++)
*/ {
translog_buffer_lock(buffer); struct st_translog_buffer *buffer= log_descriptor.buffers + i;
translog_buffer_destroy(buffer); translog_buffer_destroy(buffer);
} }
/* close files */
for (i= 0; i < OPENED_FILES_NUM; i++) /* close files */
{ for (i= 0; i < OPENED_FILES_NUM; i++)
if (log_descriptor.log_file_num[i] != -1) {
translog_close_log_file(log_descriptor.log_file_num[i]); if (log_descriptor.log_file_num[i] != -1)
translog_close_log_file(log_descriptor.log_file_num[i]);
}
pthread_mutex_destroy(&log_descriptor.sent_to_file_lock);
my_close(log_descriptor.directory_fd, MYF(MY_WME));
translog_inited= 0;
} }
pthread_mutex_destroy(&log_descriptor.sent_to_file_lock);
my_close(log_descriptor.directory_fd, MYF(MY_WME));
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
...@@ -169,15 +169,19 @@ enum PCBLOCK_TEMPERATURE { PCBLOCK_COLD /*free*/ , PCBLOCK_WARM , PCBLOCK_HOT }; ...@@ -169,15 +169,19 @@ enum PCBLOCK_TEMPERATURE { PCBLOCK_COLD /*free*/ , PCBLOCK_WARM , PCBLOCK_HOT };
#ifndef DBUG_OFF #ifndef DBUG_OFF
static const char *page_cache_page_type_str[]= static const char *page_cache_page_type_str[]=
{ {
/* used only for control page type changing during debugging */
"EMPTY",
"PLAIN", "PLAIN",
"LSN" "LSN"
}; };
static const char *page_cache_page_write_mode_str[]= static const char *page_cache_page_write_mode_str[]=
{ {
"DELAY", "DELAY",
"NOW", "NOW",
"DONE" "DONE"
}; };
static const char *page_cache_page_lock_str[]= static const char *page_cache_page_lock_str[]=
{ {
"free -> free", "free -> free",
...@@ -189,6 +193,7 @@ static const char *page_cache_page_lock_str[]= ...@@ -189,6 +193,7 @@ static const char *page_cache_page_lock_str[]=
"write -> free", "write -> free",
"write -> read" "write -> read"
}; };
static const char *page_cache_page_pin_str[]= static const char *page_cache_page_pin_str[]=
{ {
"pinned -> pinned", "pinned -> pinned",
...@@ -196,17 +201,19 @@ static const char *page_cache_page_pin_str[]= ...@@ -196,17 +201,19 @@ static const char *page_cache_page_pin_str[]=
"unpinned -> pinned", "unpinned -> pinned",
"pinned -> unpinned" "pinned -> unpinned"
}; };
#endif
#ifndef DBUG_OFF
typedef struct st_pagecache_pin_info typedef struct st_pagecache_pin_info
{ {
struct st_pagecache_pin_info *next, **prev; struct st_pagecache_pin_info *next, **prev;
struct st_my_thread_var *thread; struct st_my_thread_var *thread;
} PAGECACHE_PIN_INFO; } PAGECACHE_PIN_INFO;
/* /*
st_pagecache_lock_info structure should be kept in next, prev, thread part st_pagecache_lock_info structure should be kept in next, prev, thread part
compatible with st_pagecache_pin_info to be compatible in functions. compatible with st_pagecache_pin_info to be compatible in functions.
*/ */
typedef struct st_pagecache_lock_info typedef struct st_pagecache_lock_info
{ {
struct st_pagecache_lock_info *next, **prev; struct st_pagecache_lock_info *next, **prev;
...@@ -275,7 +282,8 @@ static PAGECACHE_PIN_INFO *info_find(PAGECACHE_PIN_INFO *list, ...@@ -275,7 +282,8 @@ static PAGECACHE_PIN_INFO *info_find(PAGECACHE_PIN_INFO *list,
return i; return i;
return 0; return 0;
} }
#endif
#endif /* !DBUG_OFF */
/* page cache block */ /* page cache block */
struct st_pagecache_block_link struct st_pagecache_block_link
......
...@@ -18,6 +18,11 @@ ...@@ -18,6 +18,11 @@
#include "maria.h" #include "maria.h"
#include <my_getopt.h> #include <my_getopt.h>
#include <m_string.h> #include <m_string.h>
#include "ma_control_file.h"
#include "ma_loghandler.h"
extern PAGECACHE *maria_log_pagecache;
extern const char *maria_data_root;
#define MAX_REC_LENGTH 1024 #define MAX_REC_LENGTH 1024
...@@ -49,10 +54,23 @@ int main(int argc,char *argv[]) ...@@ -49,10 +54,23 @@ int main(int argc,char *argv[])
{ {
MY_INIT(argv[0]); MY_INIT(argv[0]);
my_init(); my_init();
maria_init();
get_options(argc,argv); get_options(argc,argv);
maria_data_root= ".";
/* Maria requires that we always have a page cache */ /* Maria requires that we always have a page cache */
init_pagecache(maria_pagecache, IO_SIZE*16, 0, 0, maria_block_size); if (maria_init() ||
(init_pagecache(maria_pagecache, IO_SIZE*16, 0, 0,
maria_block_size) == 0) ||
ma_control_file_create_or_open() ||
(init_pagecache(maria_log_pagecache,
TRANSLOG_PAGECACHE_SIZE, 0, 0,
TRANSLOG_PAGE_SIZE) == 0) ||
translog_init(maria_data_root, TRANSLOG_FILE_SIZE,
0, 0, maria_log_pagecache,
TRANSLOG_DEFAULT_FLAGS))
{
fprintf(stderr, "Error in initialization");
exit(1);
}
exit(run_test("test1")); exit(run_test("test1"));
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <m_ctype.h> #include <m_ctype.h>
#include <my_bit.h> #include <my_bit.h>
#define STANDARD_LENGTH 37 #define STANDARD_LENGTH 37
#define MARIA_KEYS 6 #define MARIA_KEYS 6
#define MAX_PARTS 4 #define MAX_PARTS 4
...@@ -219,8 +220,22 @@ int main(int argc, char *argv[]) ...@@ -219,8 +220,22 @@ int main(int argc, char *argv[])
goto err; goto err;
if (!silent) if (!silent)
printf("- Writing key:s\n"); printf("- Writing key:s\n");
maria_data_root= ".";
/* Maria requires that we always have a page cache */ /* Maria requires that we always have a page cache */
init_pagecache(maria_pagecache, pagecache_size, 0, 0, maria_block_size); if ((init_pagecache(maria_pagecache, pagecache_size, 0, 0,
maria_block_size) == 0) ||
ma_control_file_create_or_open() ||
(init_pagecache(maria_log_pagecache,
TRANSLOG_PAGECACHE_SIZE, 0, 0,
TRANSLOG_PAGE_SIZE) == 0) ||
translog_init(maria_data_root, TRANSLOG_FILE_SIZE,
0, 0, maria_log_pagecache,
TRANSLOG_DEFAULT_FLAGS))
{
fprintf(stderr, "Error in initialization");
exit(1);
}
if (locking) if (locking)
maria_lock_database(file,F_WRLCK); maria_lock_database(file,F_WRLCK);
if (write_cacheing) if (write_cacheing)
......
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