Commit 9d057ea8 authored by Rich Prohaska's avatar Rich Prohaska

enable/disable writing tokulogs. addresses#807

git-svn-id: file:///svn/tokudb@4017 c7de825b-a66e-492c-adef-691d508d4ae1
parent 7d676f90
...@@ -48,6 +48,7 @@ struct tokulogger { ...@@ -48,6 +48,7 @@ struct tokulogger {
struct mylock input_lock, output_lock; // acquired in that order struct mylock input_lock, output_lock; // acquired in that order
int is_open; int is_open;
int is_panicked; int is_panicked;
int write_log_files;
int panic_errno; int panic_errno;
char *directory; char *directory;
int fd; int fd;
......
...@@ -57,12 +57,12 @@ int toku_logger_find_logfiles (const char *directory, char ***resultp) { ...@@ -57,12 +57,12 @@ int toku_logger_find_logfiles (const char *directory, char ***resultp) {
char **MALLOC_N(result_limit, result); char **MALLOC_N(result_limit, result);
struct dirent *de; struct dirent *de;
DIR *d=opendir(directory); DIR *d=opendir(directory);
if (d==0 && strcmp(directory, dev_null) != 0) { if (d==0) {
free(result); free(result);
return errno; return errno;
} }
int dirnamelen = strlen(directory); int dirnamelen = strlen(directory);
while (d && (de=readdir(d))) { while ((de=readdir(d))) {
if (de==0) return errno; if (de==0) return errno;
long long thisl; long long thisl;
int r = sscanf(de->d_name, "log%llu.tokulog", &thisl); int r = sscanf(de->d_name, "log%llu.tokulog", &thisl);
...@@ -89,6 +89,7 @@ int toku_logger_create (TOKULOGGER *resultp) { ...@@ -89,6 +89,7 @@ int toku_logger_create (TOKULOGGER *resultp) {
if (result==0) return errno; if (result==0) return errno;
result->is_open=0; result->is_open=0;
result->is_panicked=0; result->is_panicked=0;
result->write_log_files = 1;
result->lg_max = 100<<20; // 100MB default result->lg_max = 100<<20; // 100MB default
result->head = result->tail = 0; result->head = result->tail = 0;
result->lsn = result->written_lsn = result->fsynced_lsn = (LSN){0}; result->lsn = result->written_lsn = result->fsynced_lsn = (LSN){0};
...@@ -113,6 +114,10 @@ void toku_logger_set_cachetable (TOKULOGGER tl, CACHETABLE ct) { ...@@ -113,6 +114,10 @@ void toku_logger_set_cachetable (TOKULOGGER tl, CACHETABLE ct) {
tl->ct = ct; tl->ct = ct;
} }
void toku_logger_write_log_files (TOKULOGGER tl, int write_log_files) {
tl->write_log_files = write_log_files;
}
static int (*toku_os_fsync_function)(int)=fsync; static int (*toku_os_fsync_function)(int)=fsync;
static const int log_format_version=0; static const int log_format_version=0;
...@@ -137,10 +142,10 @@ static int open_logfile (TOKULOGGER logger) { ...@@ -137,10 +142,10 @@ static int open_logfile (TOKULOGGER logger) {
int fnamelen = strlen(logger->directory)+50; int fnamelen = strlen(logger->directory)+50;
char fname[fnamelen]; char fname[fnamelen];
snprintf(fname, fnamelen, "%s/log%012llu.tokulog", logger->directory, logger->next_log_file_number); snprintf(fname, fnamelen, "%s/log%012llu.tokulog", logger->directory, logger->next_log_file_number);
if (strcmp(logger->directory, dev_null) == 0) { if (logger->write_log_files) {
logger->fd = open(dev_null, O_RDWR); if (logger->fd==-1) return errno;
} else {
logger->fd = creat(fname, O_EXCL | 0700); if (logger->fd==-1) return errno; logger->fd = creat(fname, O_EXCL | 0700); if (logger->fd==-1) return errno;
} else {
logger->fd = open(dev_null, O_RDWR); if (logger->fd==-1) return errno;
} }
logger->next_log_file_number++; logger->next_log_file_number++;
int version_l = htonl(log_format_version); int version_l = htonl(log_format_version);
...@@ -164,7 +169,7 @@ int toku_logger_open (const char *directory, TOKULOGGER logger) { ...@@ -164,7 +169,7 @@ int toku_logger_open (const char *directory, TOKULOGGER logger) {
int r; int r;
long long nexti; long long nexti;
r = toku_logger_find_next_unused_log_file(directory, &nexti); r = toku_logger_find_next_unused_log_file(directory, &nexti);
if (r!=0 && strcmp(directory, dev_null) != 0) return r; if (r!=0) return r;
logger->directory = toku_strdup(directory); logger->directory = toku_strdup(directory);
if (logger->directory==0) return errno; if (logger->directory==0) return errno;
logger->next_log_file_number = nexti; logger->next_log_file_number = nexti;
...@@ -175,7 +180,7 @@ int toku_logger_open (const char *directory, TOKULOGGER logger) { ...@@ -175,7 +180,7 @@ int toku_logger_open (const char *directory, TOKULOGGER logger) {
logger->fsynced_lsn.lsn = 0; logger->fsynced_lsn.lsn = 0;
logger->is_open = 1; logger->is_open = 1;
if (strcmp(directory, dev_null) == 0) if (!logger->write_log_files)
toku_set_func_fsync(toku_logger_fsync_null); toku_set_func_fsync(toku_logger_fsync_null);
return 0; return 0;
...@@ -845,7 +850,10 @@ int toku_set_func_fsync (int (*fsync_function)(int)) { ...@@ -845,7 +850,10 @@ int toku_set_func_fsync (int (*fsync_function)(int)) {
static int peek_at_log (TOKULOGGER logger, char* filename, LSN *first_lsn) { static int peek_at_log (TOKULOGGER logger, char* filename, LSN *first_lsn) {
logger=logger; logger=logger;
int fd = open(filename, O_RDONLY); int fd = open(filename, O_RDONLY);
if (fd<0) { printf("couldn't open: %s\n", strerror(errno)); return errno; } if (fd<0) {
if (logger->write_log_files) printf("couldn't open: %s\n", strerror(errno));
return errno;
}
enum { SKIP = 12+1+4 }; // read the 12 byte header, the first cmd, and the first len enum { SKIP = 12+1+4 }; // read the 12 byte header, the first cmd, and the first len
unsigned char header[SKIP+8]; unsigned char header[SKIP+8];
int r = read(fd, header, SKIP+8); int r = read(fd, header, SKIP+8);
......
...@@ -21,6 +21,7 @@ struct logbytes { ...@@ -21,6 +21,7 @@ struct logbytes {
int toku_logger_create(TOKULOGGER */*resultp*/); int toku_logger_create(TOKULOGGER */*resultp*/);
void toku_logger_set_cachetable (TOKULOGGER, CACHETABLE); void toku_logger_set_cachetable (TOKULOGGER, CACHETABLE);
void toku_logger_write_log_files (TOKULOGGER, int do_write_log_files);
int toku_logger_open(const char */*directory*/, TOKULOGGER); int toku_logger_open(const char */*directory*/, TOKULOGGER);
int toku_logger_log_bytes(TOKULOGGER logger, struct logbytes *bytes, int do_fsync); int toku_logger_log_bytes(TOKULOGGER logger, struct logbytes *bytes, int do_fsync);
int toku_logger_close(TOKULOGGER *logger); int toku_logger_close(TOKULOGGER *logger);
......
...@@ -333,6 +333,7 @@ static int toku_env_open(DB_ENV * env, const char *home, u_int32_t flags, int mo ...@@ -333,6 +333,7 @@ static int toku_env_open(DB_ENV * env, const char *home, u_int32_t flags, int mo
char* full_dir = NULL; char* full_dir = NULL;
if (env->i->lg_dir) full_dir = construct_full_name(env->i->dir, env->i->lg_dir); if (env->i->lg_dir) full_dir = construct_full_name(env->i->dir, env->i->lg_dir);
assert(env->i->logger); assert(env->i->logger);
toku_logger_write_log_files(env->i->logger, (flags & DB_INIT_LOG) != 0);
r = toku_logger_open(full_dir ? full_dir : env->i->dir, env->i->logger); r = toku_logger_open(full_dir ? full_dir : env->i->dir, env->i->logger);
if (full_dir) toku_free(full_dir); if (full_dir) toku_free(full_dir);
if (r!=0) { if (r!=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