Commit a601d8fb authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

memory leak when logcursors fail refs[t:2446]

git-svn-id: file:///svn/toku/tokudb@18346 c7de825b-a66e-492c-adef-691d508d4ae1
parent 9cf0c76e
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
#include "test.h"
#include "includes.h"
#define dname __FILE__ ".dir"
#define rmrf "rm -rf " dname "/"
// log a couple of timestamp entries and verify the log by walking
// a cursor through the log entries
static void corrupt_the_checksum(void) {
// change the LSN in the first log entry of log 0. this will cause an checksum error.
int r;
FILE *f = fopen(dname "/" "log000000000000.tokulog", "r+b"); assert(f);
r = fseek(f, 025, SEEK_SET); assert(r == 0);
char c = 100;
size_t n = fwrite(&c, sizeof c, 1, f); assert(n == sizeof c);
r = fclose(f); assert(r == 0);
}
int
test_main (int argc, const char *argv[]) {
default_parse_args(argc, argv);
int r;
system(rmrf);
r = toku_os_mkdir(dname, S_IRWXU); assert(r==0);
TOKULOGGER logger;
LSN lsn = ZERO_LSN;
// log a couple of timestamp log entries
r = toku_logger_create(&logger);
assert(r == 0);
r = toku_logger_open(dname, logger);
assert(r == 0);
BYTESTRING bs0 = { .data = "hello", .len = 5 };
r = toku_log_comment(logger, &lsn, 0, 0, bs0);
assert(r == 0);
r = toku_logger_close(&logger);
assert(r == 0);
// change the LSN and corrupt the checksum
corrupt_the_checksum();
// walk forwards
TOKULOGCURSOR lc = NULL;
struct log_entry *le;
r = toku_logcursor_create(&lc, dname);
assert(r == 0 && lc != NULL);
r = toku_logcursor_next(lc, &le);
assert(r != 0);
r = toku_logcursor_destroy(&lc);
assert(r == 0 && lc == NULL);
// walk backwards
r = toku_logcursor_create(&lc, dname);
assert(r == 0 && lc != NULL);
r = toku_logcursor_prev(lc, &le);
assert(r != 0);
r = toku_logcursor_destroy(&lc);
assert(r == 0 && lc == NULL);
return 0;
}
......@@ -5,19 +5,13 @@
#include "includes.h"
#define dname __FILE__ ".dir"
#define rmrf "rm -rf " dname "/"
// log a couple of timestamp entries and verify the log by walking
// a cursor through the log entries
// walk forward through the log files found in the current directory
int
test_main (int argc, const char *argv[]) {
default_parse_args(argc, argv);
int r;
system(rmrf);
r = toku_os_mkdir(dname, S_IRWXU); assert(r==0);
// verify the log backwards
TOKULOGCURSOR lc = NULL;
......
......@@ -5,19 +5,13 @@
#include "includes.h"
#define dname __FILE__ ".dir"
#define rmrf "rm -rf " dname "/"
// log a couple of timestamp entries and verify the log by walking
// a cursor through the log entries
// walk forward through the log files found in the current directory
int
test_main (int argc, const char *argv[]) {
default_parse_args(argc, argv);
int r;
system(rmrf);
r = toku_os_mkdir(dname, S_IRWXU); assert(r==0);
// verify the log backwards
TOKULOGCURSOR lc = NULL;
......
// force a bad LSN during the forward scan. recovery should fail.
#include "test.h"
#include "includes.h"
#define TESTDIR "dir." __FILE__
static void recover_callback_at_turnaround(void *UU(arg)) {
// change the LSN in the first log entry of log 2. this will cause an LSN error during the forward scan.
int r;
FILE *f = fopen("log000000000002.tokulog", "r+b"); assert(f);
r = fseek(f, 025, SEEK_SET); assert(r == 0);
char c = 100;
size_t n = fwrite(&c, sizeof c, 1, f); assert(n == sizeof c);
r = fclose(f); assert(r == 0);
}
static int
run_test(void) {
int r;
// setup the test dir
system("rm -rf " TESTDIR);
r = toku_os_mkdir(TESTDIR, S_IRWXU); assert(r == 0);
// log 1 has the checkpoint
TOKULOGGER logger;
r = toku_logger_create(&logger); assert(r == 0);
r = toku_logger_open(TESTDIR, logger); assert(r == 0);
LSN beginlsn;
r = toku_log_begin_checkpoint(logger, &beginlsn, TRUE, 0); assert(r == 0);
r = toku_log_end_checkpoint(logger, NULL, TRUE, beginlsn.lsn, 0); assert(r == 0);
r = toku_logger_close(&logger); assert(r == 0);
// log 2 has hello
r = toku_logger_create(&logger); assert(r == 0);
r = toku_logger_open(TESTDIR, logger); assert(r == 0);
BYTESTRING hello = { strlen("hello"), "hello" };
r = toku_log_comment(logger, NULL, TRUE, 0, hello); assert(r == 0);
r = toku_logger_close(&logger); assert(r == 0);
// log 3 has there
r = toku_logger_create(&logger); assert(r == 0);
r = toku_logger_open(TESTDIR, logger); assert(r == 0);
BYTESTRING there = { strlen("there"), "there" };
r = toku_log_comment(logger, NULL, TRUE, 0, there); assert(r == 0);
r = toku_logger_close(&logger); assert(r == 0);
// redirect stderr
int devnul = open(DEV_NULL_FILE, O_WRONLY);
assert(devnul>=0);
r = toku_dup2(devnul, fileno(stderr)); assert(r==fileno(stderr));
r = close(devnul); assert(r==0);
// delete log 2 at the turnaround to force
toku_recover_set_callback(recover_callback_at_turnaround, NULL);
// run recovery
r = tokudb_recover(TESTDIR, TESTDIR, 0, 0, NULL, NULL, 0);
assert(r != 0);
return 0;
}
int
test_main(int UU(argc), const char *UU(argv[])) {
int r;
r = run_test();
return r;
}
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