Commit 76d9f3c6 authored by unknown's avatar unknown

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

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


storage/maria/ma_loghandler.c:
  Auto merged
storage/maria/unittest/ma_test_loghandler_multigroup-t.c:
  Auto merged
parents ed5fe6d3 bc31f005
......@@ -62,7 +62,7 @@ TARGET_LINK_LIBRARIES(maria_read_log maria myisam mysys dbug strings zlib wsock3
ADD_EXECUTABLE(maria_pack maria_pack.c)
TARGET_LINK_LIBRARIES(maria_pack maria myisam mysys dbug strings zlib wsock32)
ADD_EXECUTABLE(maria_dump_log ma_loghandler.c)
ADD_EXECUTABLE(maria_dump_log ma_loghandler.c unittest/ma_loghandler_examples.c)
TARGET_LINK_LIBRARIES(maria_dump_log maria myisam mysys dbug strings zlib wsock32)
SET_TARGET_PROPERTIES(maria_dump_log PROPERTIES COMPILE_FLAGS "-DMARIA_DUMP_LOG")
......
......@@ -63,7 +63,7 @@ maria_dump_log_LDADD= @CLIENT_EXTRA_LDFLAGS@ libmaria.a \
$(top_builddir)/mysys/libmysys.a \
$(top_builddir)/dbug/libdbug.a \
$(top_builddir)/strings/libmystrings.a @ZLIB_LIBS@
maria_dump_log_SOURCES= ma_loghandler.c
maria_dump_log_SOURCES= ma_loghandler.c unittest/ma_loghandler_examples.c
maria_dump_log_CPPFLAGS= -DMARIA_DUMP_LOG
noinst_PROGRAMS = ma_test1 ma_test2 ma_test3 ma_rt_test ma_sp_test
noinst_HEADERS = maria_def.h ma_rt_index.h ma_rt_key.h ma_rt_mbr.h \
......
This diff is collapsed.
......@@ -26,7 +26,7 @@ ADD_EXECUTABLE(lockman2-t lockman2-t.c)
ADD_EXECUTABLE(ma_test_loghandler-t
ma_test_loghandler-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c)
ADD_EXECUTABLE(ma_test_loghandler_multigroup-t
ma_test_loghandler_multigroup-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c)
ma_test_loghandler_multigroup-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c sequence_storage.c)
ADD_EXECUTABLE(ma_test_loghandler_multithread-t
ma_test_loghandler_multithread-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c)
ADD_EXECUTABLE(ma_test_loghandler_pagecache-t
......@@ -44,7 +44,7 @@ ADD_EXECUTABLE(ma_test_loghandler_max_lsn-t
ADD_EXECUTABLE(ma_test_loghandler_purge-t
ma_test_loghandler_purge-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c)
ADD_EXECUTABLE(ma_test_loghandler_readonly-t
ma_test_loghandler_multigroup-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c)
ma_test_loghandler_multigroup-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c sequence_storage.c)
SET_TARGET_PROPERTIES(ma_test_loghandler_readonly-t PROPERTIES COMPILE_FLAGS "-DREADONLY_TEST")
ADD_EXECUTABLE(ma_test_loghandler_nologs-t
ma_test_loghandler_nologs-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c)
......
......@@ -52,7 +52,7 @@ noinst_PROGRAMS = ma_control_file-t trnman-t lockman2-t \
ma_test_loghandler_nologs-t
ma_test_loghandler_t_SOURCES = ma_test_loghandler-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c
ma_test_loghandler_multigroup_t_SOURCES = ma_test_loghandler_multigroup-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c
ma_test_loghandler_multigroup_t_SOURCES = ma_test_loghandler_multigroup-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c sequence_storage.c
ma_test_loghandler_multithread_t_SOURCES = ma_test_loghandler_multithread-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c
ma_test_loghandler_pagecache_t_SOURCES = ma_test_loghandler_pagecache-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c
ma_test_loghandler_long_t_SOURCES = ma_test_loghandler-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c
......@@ -61,7 +61,7 @@ ma_test_loghandler_noflush_t_SOURCES = ma_test_loghandler_noflush-t.c ma_maria_l
ma_test_loghandler_first_lsn_t_SOURCES = ma_test_loghandler_first_lsn-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c
ma_test_loghandler_max_lsn_t_SOURCES = ma_test_loghandler_max_lsn-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c
ma_test_loghandler_purge_t_SOURCES = ma_test_loghandler_purge-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c
ma_test_loghandler_readonly_t_SOURCES = ma_test_loghandler_multigroup-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c
ma_test_loghandler_readonly_t_SOURCES = ma_test_loghandler_multigroup-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c sequence_storage.c
ma_test_loghandler_readonly_t_CPPFLAGS = -DREADONLY_TEST
ma_test_loghandler_nologs_t_SOURCES = ma_test_loghandler_nologs-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c
......
......@@ -18,6 +18,8 @@
#include <errno.h>
#include <tap.h>
#include "../trnman.h"
#include "sequence_storage.h"
#include <my_getopt.h>
extern my_bool maria_log_remove();
extern void translog_example_table_init();
......@@ -126,13 +128,97 @@ static my_bool read_and_check_content(TRANSLOG_HEADER_BUFFER *rec,
DBUG_RETURN(res);
}
static const char *load_default_groups[]= {"ma_unit_loghandler", 0};
#if defined(__WIN__)
static const char *default_dbug_option= "d:t:i:O,\\ma_test_loghandler.trace";
#else
static const char *default_dbug_option= "d:t:i:o,/tmp/ma_test_loghandler.trace";
#endif
static const char *opt_wfile= NULL;
static const char *opt_rfile= NULL;
static struct my_option my_long_options[] =
{
#ifndef DBUG_OFF
{"debug", '#', "Output debug log. Often the argument is 'd:t:o,filename'.",
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
#endif
{"write-seq", 'w', "Path to file in which \"random\" sequence used in the test will be written",
(uchar**) &opt_wfile, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"read-seq", 'r', "Path to file from which \"random\" sequence used in the test will be read",
(uchar**) &opt_rfile, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"help", '?', "Display this help and exit.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
static SEQ_STORAGE seq;
static uint32 get_len()
{
return (uint32)
((ulonglong)rand()*(LONG_BUFFER_SIZE - MIN_REC_LENGTH - 1)/RAND_MAX)+ MIN_REC_LENGTH;
uint32 res;
DBUG_ENTER("get_len");
if (opt_rfile)
res= seq_storage_next(&seq);
else
{
res= (uint32)
((ulonglong) rand() *
(LONG_BUFFER_SIZE - MIN_REC_LENGTH - 1) / RAND_MAX) + MIN_REC_LENGTH;
if (opt_wfile &&
seq_storage_write(opt_wfile, res))
exit(1);
}
DBUG_PRINT("info", ("length value : %lu", (ulong) res));
DBUG_RETURN(res);
}
static void usage(void)
{
puts("Copyright (C) 2008 MySQL AB");
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,");
puts("and you are welcome to modify and redistribute it under the GPL license\n");
puts("Unit test of maria engine");
VOID(printf("\nUsage: %s [OPTIONS]\n", my_progname_short));
my_print_help(my_long_options);
print_defaults("my", load_default_groups);
my_print_variables(my_long_options);
}
static my_bool
get_one_option(int optid __attribute__((unused)),
const struct my_option *opt __attribute__((unused)),
char *argument __attribute__((unused)))
{
switch (optid) {
case '?':
usage();
exit(0);
#ifndef DBUG_OFF
case '#':
DBUG_SET_INITIAL(argument ? argument : default_dbug_option);
break;
#endif
}
return 0;
}
static void get_options(int *argc,char ***argv)
{
int ho_error;
if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error);
if (opt_rfile && opt_wfile)
{
usage();
exit(1);
}
}
int main(int argc __attribute__((unused)), char *argv[])
{
uint32 i;
......@@ -146,6 +232,7 @@ int main(int argc __attribute__((unused)), char *argv[])
0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55
};
uchar *long_buffer= malloc(LONG_BUFFER_SIZE + LSN_STORE_SIZE * 2 + 2);
char **default_argv;
PAGECACHE pagecache;
LSN lsn, lsn_base, first_lsn;
TRANSLOG_HEADER_BUFFER rec;
......@@ -157,6 +244,10 @@ int main(int argc __attribute__((unused)), char *argv[])
bzero(&pagecache, sizeof(pagecache));
maria_data_root= (char *)".";
load_defaults("my", load_default_groups, &argc, &argv);
default_argv= argv;
get_options(&argc, &argv);
if (maria_log_remove())
exit(1);
......@@ -171,18 +262,6 @@ int main(int argc __attribute__((unused)), char *argv[])
}
bzero(long_tr_id, 6);
#ifndef DBUG_OFF
#if defined(__WIN__)
default_dbug_option= "d:t:i:O,\\ma_test_loghandler.trace";
#else
default_dbug_option= "d:t:i:o,/tmp/ma_test_loghandler.trace";
#endif
if (argc > 1)
{
DBUG_SET(default_dbug_option);
DBUG_SET_INITIAL(default_dbug_option);
}
#endif
if (ma_control_file_open(TRUE))
{
......@@ -206,6 +285,9 @@ int main(int argc __attribute__((unused)), char *argv[])
plan(((ITERATIONS - 1) * 4 + 1) * 2);
if (opt_rfile &&
seq_storage_reader_init(&seq, opt_rfile))
exit(1);
srand(122334817L);
long_tr_id[5]= 0xff;
......@@ -366,6 +448,11 @@ int main(int argc __attribute__((unused)), char *argv[])
exit(1);
}
/* If we were writing sequence we need it only once */
opt_wfile= NULL;
if (opt_rfile)
seq_storage_rewind(&seq);
srand(122334817L);
rc= 1;
......@@ -477,6 +564,7 @@ int main(int argc __attribute__((unused)), char *argv[])
(uint) rec.header[22],
LSN_IN_PARTS(rec.lsn));
translog_free_record_header(&rec);
DBUG_ASSERT(0);
goto err;
}
}
......@@ -653,6 +741,8 @@ err:
translog_destroy();
end_pagecache(&pagecache, 1);
ma_control_file_end();
free_defaults(default_argv);
seq_storage_destroy(&seq);
if (maria_log_remove())
exit(1);
......
/* Copyright (C) 2008 MySQL AB
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 "sequence_storage.h"
/**
@brief Initializes the sequence from the sequence file.
@param seq Reference on the sequence storage.
@param file Path to the file where to write the sequence
@retval 0 OK
@retval 1 Error
*/
my_bool seq_storage_reader_init(SEQ_STORAGE *seq, const char *file)
{
FILE *fd;
seq->pos= 0;
if ((fd= my_fopen(file, O_RDONLY, MYF(MY_WME))) == NULL)
return 1;
if (my_init_dynamic_array(&seq->seq, sizeof(ulong), 10, 10))
return 1;
for(;;)
{
ulong num;
char line[22];
if (fgets(line, sizeof(line), fd) == NULL)
break;
num= atol(line);
if (insert_dynamic(&seq->seq, (uchar*) &num))
return 1;
}
fclose(fd);
return 0;
}
/**
@brief Gets next number from the sequence storage
@param seq Reference on the sequence storage.
@return Next number from the sequence.
*/
ulong seq_storage_next(SEQ_STORAGE *seq)
{
DBUG_ASSERT(seq->seq.elements > 0);
DBUG_ASSERT(seq->pos < seq->seq.elements);
return (*(dynamic_element(&seq->seq, seq->pos++, ulong *)));
}
/**
@brief Frees resources allocated for the storage
@param seq Reference on the sequence storage.
*/
void seq_storage_destroy(SEQ_STORAGE *seq)
{
delete_dynamic(&seq->seq);
}
/**
@brief Starts the sequence from begining
@param seq Reference on the sequence storage.
*/
void seq_storage_rewind(SEQ_STORAGE *seq)
{
seq->pos= 0;
}
/**
@brief Writes a number to the sequence file.
@param file Path to the file where to write the sequence
@pagem num Number to be written
@retval 0 OK
@retval 1 Error
*/
my_bool seq_storage_write(const char *file, ulong num)
{
FILE *fd;
return ((fd= my_fopen(file, O_CREAT | O_APPEND | O_WRONLY, MYF(MY_WME))) ==
NULL ||
fprintf(fd, "%lu\n", num) < 0 ||
fclose(fd) != 0);
}
/* Copyright (C) 2008 MySQL AB
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 */
typedef struct st_seq_storage
{
uint pos;
DYNAMIC_ARRAY seq;
} SEQ_STORAGE;
extern my_bool seq_storage_reader_init(SEQ_STORAGE *seq, const char *file);
extern ulong seq_storage_next(SEQ_STORAGE *seq);
extern void seq_storage_destroy(SEQ_STORAGE *seq);
extern void seq_storage_rewind(SEQ_STORAGE *seq);
extern my_bool seq_storage_write(const char *file, ulong num);
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