Commit 0909fccc authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

increase the backward log scan rate close[t:2256]

git-svn-id: file:///svn/toku/tokudb@16486 c7de825b-a66e-492c-adef-691d508d4ae1
parent edaa2948
...@@ -13,6 +13,8 @@ struct toku_logcursor { ...@@ -13,6 +13,8 @@ struct toku_logcursor {
int n_logfiles; int n_logfiles;
int cur_logfiles_index; int cur_logfiles_index;
FILE *cur_fp; FILE *cur_fp;
size_t buffer_size;
void *buffer;
BOOL is_open; BOOL is_open;
struct log_entry entry; struct log_entry entry;
BOOL entry_valid; BOOL entry_valid;
...@@ -53,6 +55,9 @@ static int lc_open_logfile(TOKULOGCURSOR lc, int index) { ...@@ -53,6 +55,9 @@ static int lc_open_logfile(TOKULOGCURSOR lc, int index) {
lc->cur_fp = fopen(lc->logfiles[index], "rb"); lc->cur_fp = fopen(lc->logfiles[index], "rb");
if ( lc->cur_fp == NULL ) if ( lc->cur_fp == NULL )
return DB_NOTFOUND; return DB_NOTFOUND;
// debug printf("%s:%d %s %p %u\n", __FUNCTION__, __LINE__, lc->logfiles[index], lc->buffer, (unsigned) lc->buffer_size);
r = setvbuf(lc->cur_fp, lc->buffer, _IOFBF, lc->buffer_size);
assert(r == 0);
// position fp past header // position fp past header
unsigned int version=0; unsigned int version=0;
r = toku_read_logmagic(lc->cur_fp, &version); r = toku_read_logmagic(lc->cur_fp, &version);
...@@ -98,6 +103,8 @@ static int lc_create(TOKULOGCURSOR *lc, const char *log_dir) { ...@@ -98,6 +103,8 @@ static int lc_create(TOKULOGCURSOR *lc, const char *log_dir) {
cursor->is_open = FALSE; cursor->is_open = FALSE;
cursor->cur_logfiles_index = 0; cursor->cur_logfiles_index = 0;
cursor->entry_valid = FALSE; cursor->entry_valid = FALSE;
cursor->buffer_size = 1<<20; // use a 1MB stream buffer (setvbuf)
cursor->buffer = toku_malloc(cursor->buffer_size); // it does not matter if it failes
// cursor->logdir must be an absolute path // cursor->logdir must be an absolute path
if (toku_os_is_absolute_name(log_dir)) { if (toku_os_is_absolute_name(log_dir)) {
cursor->logdir = (char *) toku_malloc(strlen(log_dir)+1); cursor->logdir = (char *) toku_malloc(strlen(log_dir)+1);
...@@ -125,6 +132,7 @@ static int lc_create(TOKULOGCURSOR *lc, const char *log_dir) { ...@@ -125,6 +132,7 @@ static int lc_create(TOKULOGCURSOR *lc, const char *log_dir) {
cursor->n_logfiles = 0; cursor->n_logfiles = 0;
cursor->cur_lsn.lsn=0; cursor->cur_lsn.lsn=0;
cursor->last_direction=LC_FIRST; cursor->last_direction=LC_FIRST;
*lc = cursor; *lc = cursor;
return r; return r;
...@@ -194,6 +202,8 @@ int toku_logcursor_destroy(TOKULOGCURSOR *lc) { ...@@ -194,6 +202,8 @@ int toku_logcursor_destroy(TOKULOGCURSOR *lc) {
} }
toku_free((*lc)->logfiles); toku_free((*lc)->logfiles);
toku_free((*lc)->logdir); toku_free((*lc)->logdir);
if ((*lc)->buffer)
toku_free((*lc)->buffer);
toku_free(*lc); toku_free(*lc);
*lc = NULL; *lc = NULL;
return r; return r;
......
/* -*- 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
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;
r = toku_logcursor_create(&lc, "/tmp");
assert(r == 0 && lc != NULL);
int n = 0;
while (1) {
struct log_entry *le = NULL;
r = toku_logcursor_prev(lc, &le);
if (r != 0)
break;
n++;
}
printf("n=%d\n", n);
r = toku_logcursor_destroy(&lc);
assert(r == 0 && lc == NULL);
return 0;
}
/* -*- 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
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;
r = toku_logcursor_create(&lc, "/tmp");
assert(r == 0 && lc != NULL);
int n = 0;
while (1) {
struct log_entry *le = NULL;
r = toku_logcursor_next(lc, &le);
if (r != 0)
break;
n++;
}
printf("n=%d\n", n);
r = toku_logcursor_destroy(&lc);
assert(r == 0 && lc == NULL);
return 0;
}
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