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
storage/maria/unittest/ma_pagecache_consist_64kRD-t-big
storage/maria/unittest/ma_pagecache_consist_64kWR-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
/* Type of the page */
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,
#endif
/* the page does not contain LSN */
PAGECACHE_PLAIN_PAGE,
/* the page contain LSN (maria tablespace page) */
......
......@@ -505,6 +505,9 @@ static my_bool _ma_read_bitmap_page(MARIA_SHARE *share,
bzero(bitmap->map, bitmap->block_size);
memcpy(bitmap->map + share->block_size - 2, maria_bitmap_marker, 2);
bitmap->used_size= 0;
#ifndef DBUG_OFF
memcpy(bitmap->map + bitmap->block_size, bitmap->map, bitmap->block_size);
#endif
DBUG_RETURN(0);
}
bitmap->used_size= bitmap->total_size;
......
......@@ -3640,7 +3640,6 @@ static size_t fill_insert_undo_parts(MARIA_HA *info, const byte *record,
log_parts++;
/* 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->length= share->base.pack_bytes;
row_length+= log_parts->length;
......@@ -3800,7 +3799,7 @@ static size_t fill_update_undo_parts(MARIA_HA *info, const byte *oldrec,
uchar *field_data, *start_field_data;
uchar *old_field_lengths= old_row->field_lengths;
uchar *new_field_lengths= new_row->field_lengths;
size_t row_length;
size_t row_length= 0;
uint field_count= 0;
LEX_STRING *start_log_parts;
my_bool new_column_is_empty;
......
......@@ -1632,7 +1632,7 @@ static int check_block_record(HA_CHECK *param, MARIA_HA *info, int extend,
&info->dfile,
(pos / block_size), 1,
page_buff,
PAGECACHE_PLAIN_PAGE,
info->s->page_type,
PAGECACHE_LOCK_LEFT_UNLOCKED, 0) == 0)
{
_ma_check_print_error(param,
......
......@@ -55,6 +55,8 @@ void maria_end(void)
{
maria_inited= FALSE;
ft_free_stopwords();
translog_destroy();
ma_control_file_end();
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 "ma_blockrec.h"
......@@ -148,6 +163,8 @@ static struct st_translog_descriptor log_descriptor;
/* Marker for end of log */
static byte end_of_log= 0;
static my_bool translog_inited;
/* record classes */
enum record_class
{
......@@ -288,7 +305,7 @@ static LOG_DESC INIT_LOGREC_UNDO_ROW_DELETE=
static LOG_DESC INIT_LOGREC_UNDO_ROW_UPDATE=
{LOGRECTYPE_VARIABLE_LENGTH, 0,
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=
{LOGRECTYPE_PSEUDOFIXEDLENGTH, LSN_STORE_SIZE, LSN_STORE_SIZE,
......@@ -1861,6 +1878,9 @@ static uint16 translog_get_chunk_header_length(byte *page, uint16 offset)
flags flags (TRANSLOG_PAGE_CRC, TRANSLOG_SECTOR_PROTECTION
TRANSLOG_RECORD_CRC)
TODO
Free used resources in case of error.
RETURN
0 OK
1 Error
......@@ -1877,7 +1897,7 @@ my_bool translog_init(const char *directory,
TRANSLOG_ADDRESS sure_page, last_page, last_valid_page;
DBUG_ENTER("translog_init");
loghandler_init();
loghandler_init(); /* Safe to do many times */
if (pthread_mutex_init(&log_descriptor.sent_to_file_lock,
MY_MUTEX_INIT_FAST))
......@@ -2164,6 +2184,7 @@ my_bool translog_init(const char *directory,
log_descriptor.flushed--; /* offset decreased */
log_descriptor.sent_to_file--; /* offset decreased */
translog_inited= 1;
DBUG_RETURN(0);
}
......@@ -2198,8 +2219,6 @@ static void translog_buffer_destroy(struct st_translog_buffer *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));
pthread_mutex_destroy(&buffer->mutex);
DBUG_VOID_RETURN;
......@@ -2217,19 +2236,18 @@ void translog_destroy()
{
uint i;
DBUG_ENTER("translog_destroy");
if (translog_inited)
{
if (log_descriptor.bc.buffer->file != -1)
translog_finish_page(&log_descriptor.horizon, &log_descriptor.bc);
for (i= 0; i < TRANSLOG_BUFFERS_NO; i++)
{
struct st_translog_buffer *buffer= log_descriptor.buffers + i;
/*
Lock the buffer just for safety, there should not be other
threads running.
*/
translog_buffer_lock(buffer);
translog_buffer_destroy(buffer);
}
/* close files */
for (i= 0; i < OPENED_FILES_NUM; i++)
{
......@@ -2238,6 +2256,8 @@ void translog_destroy()
}
pthread_mutex_destroy(&log_descriptor.sent_to_file_lock);
my_close(log_descriptor.directory_fd, MYF(MY_WME));
translog_inited= 0;
}
DBUG_VOID_RETURN;
}
......
......@@ -169,15 +169,19 @@ enum PCBLOCK_TEMPERATURE { PCBLOCK_COLD /*free*/ , PCBLOCK_WARM , PCBLOCK_HOT };
#ifndef DBUG_OFF
static const char *page_cache_page_type_str[]=
{
/* used only for control page type changing during debugging */
"EMPTY",
"PLAIN",
"LSN"
};
static const char *page_cache_page_write_mode_str[]=
{
"DELAY",
"NOW",
"DONE"
};
static const char *page_cache_page_lock_str[]=
{
"free -> free",
......@@ -189,6 +193,7 @@ static const char *page_cache_page_lock_str[]=
"write -> free",
"write -> read"
};
static const char *page_cache_page_pin_str[]=
{
"pinned -> pinned",
......@@ -196,17 +201,19 @@ static const char *page_cache_page_pin_str[]=
"unpinned -> pinned",
"pinned -> unpinned"
};
#endif
#ifndef DBUG_OFF
typedef struct st_pagecache_pin_info
{
struct st_pagecache_pin_info *next, **prev;
struct st_my_thread_var *thread;
} PAGECACHE_PIN_INFO;
/*
st_pagecache_lock_info structure should be kept in next, prev, thread part
compatible with st_pagecache_pin_info to be compatible in functions.
*/
typedef struct st_pagecache_lock_info
{
struct st_pagecache_lock_info *next, **prev;
......@@ -275,7 +282,8 @@ static PAGECACHE_PIN_INFO *info_find(PAGECACHE_PIN_INFO *list,
return i;
return 0;
}
#endif
#endif /* !DBUG_OFF */
/* page cache block */
struct st_pagecache_block_link
......
......@@ -18,6 +18,11 @@
#include "maria.h"
#include <my_getopt.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
......@@ -49,10 +54,23 @@ int main(int argc,char *argv[])
{
MY_INIT(argv[0]);
my_init();
maria_init();
get_options(argc,argv);
maria_data_root= ".";
/* 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"));
}
......
......@@ -28,6 +28,7 @@
#include <m_ctype.h>
#include <my_bit.h>
#define STANDARD_LENGTH 37
#define MARIA_KEYS 6
#define MAX_PARTS 4
......@@ -219,8 +220,22 @@ int main(int argc, char *argv[])
goto err;
if (!silent)
printf("- Writing key:s\n");
maria_data_root= ".";
/* 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)
maria_lock_database(file,F_WRLCK);
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