Commit 04a61d98 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

set_lg_max is ipmlemented, tested, and documented. Fixes #79.

git-svn-id: file:///svn/tokudb@2645 c7de825b-a66e-492c-adef-691d508d4ae1
parent b7bafe0a
MANPAGES = tdb_create tdb_del tdb_put tdb_open
MANPAGES = tdb_create tdb_del tdb_put tdb_open tdb_log_max
MANPAGES_TEXI = $(patsubst %,%.texi,$(MANPAGES))
MANPAGES_POD = $(patsubst %,%.pod,$(MANPAGES))
MANPAGES_3 = $(patsubst %,%.3,$(MANPAGES))
......
@page
@section @code{DB_ENV->set_lg_max}
@setfilename tokudb
@settitle DB_ENV->set_lg_max
@c man title db_del tokudb
@unnumberedsubsec Synopsis
@c man begin SYNOPSIS
@code{#include <db.h>}
@noindent
@code{int DB_ENV->set_lg_max(DB_ENV *}@var{env}@code{, u_int32_t }@var{lg_max}@code{);}
@code{int DB_ENV->get_lg_max(DB_ENV *}@var{env}@code{, u_int32_t*}@var{lg_max_p}@code{);}
@c man end
@unnumberedsubsec Description
@c man begin DESCRIPTION
Set or get the maximum size, in bytes, of any given log file.
When logging is configured, the default maximum log size is 100MiB.
It is possible that a log file will be larger than @var{lg_max}: The
logs comprise log entries, and TokuDB always writes a complete log
entry into a log file. Thus if a log entry is larger than
@var{lg_max}, then the resulting log file could be larger.
You may call @code{DB_ENV->set_log_max} at any time on any environment
that has been created but hasn't yet been closed. Subsequently
written log files will be smaller than the specified size.
@c man end
@unnumberedsubsec Parameters
@c man begin PARAMETERS
@table @var
@item env
The @code{DB_ENV} handle.
@item lg_max
For @code{DB_ENV->set_log_max}, the new maximum logfile size, in bytes.
@item lg_max_p
For @code{DB_ENV->get_log_max}, the return result will be stored in @code{*}@var{lg_max_p}.
@end table
@c man end
@unnumberedsubsec Return Value
@c man begin RETURNVALUE
Returns zero on success.
@c man end
@include everyman.texi
......@@ -41,6 +41,8 @@ Copyright @copyright{} 2007, Tokutek, Inc.
@include tdb_put.texi
@include tdb_log_max.texi
@node Index
@unnumbered Index
......
This diff is collapsed.
......@@ -22,6 +22,7 @@ struct tokulogger {
int n_in_buf;
CACHETABLE ct;
struct list live_txns; // just a linked list. Should be a hashtable.
int lg_max; // The size of the single file in the log. Default is 100MB in TokuDB
};
int toku_logger_find_next_unused_log_file(const char *directory, long long *result);
......
......@@ -69,6 +69,7 @@ int toku_logger_create (TOKULOGGER *resultp) {
if (result==0) return errno;
result->is_open=0;
result->is_panicked=0;
result->lg_max = 100<<20; // 100MB default
list_init(&result->live_txns);
*resultp=result;
return 0;
......@@ -116,14 +117,30 @@ int toku_logger_is_open(TOKULOGGER logger) {
return logger->is_open;
}
static int flush (TOKULOGGER logger) {
int toku_logger_set_lg_max(TOKULOGGER logger, u_int32_t lg_max) {
if (logger==0) return EINVAL; // no logger
if (logger->is_panicked) return EINVAL;
if (logger->is_open) return EINVAL;
if (lg_max>(1<<30)) return EINVAL; // too big
logger->lg_max = lg_max;
return 0;
}
int toku_logger_get_lg_max(TOKULOGGER logger, u_int32_t *lg_maxp) {
if (logger==0) return EINVAL; // no logger
if (logger->is_panicked) return EINVAL;
*lg_maxp = logger->lg_max;
return 0;
}
static int flush (TOKULOGGER logger, int close_p) {
if (logger->n_in_buf>0) {
int r = write(logger->fd, logger->buf, logger->n_in_buf);
if (r==-1) return errno;
logger->n_in_file += logger->n_in_buf;
logger->n_in_buf=0;
}
if (logger->n_in_file > 100<<20) {
if (close_p || logger->n_in_file >= logger->lg_max) {
int r = close(logger->fd);
if (r!=0) return errno;
logger->fd=-1;
......@@ -149,17 +166,18 @@ int toku_logger_log_bytes(TOKULOGGER logger, int nbytes, void *bytes) {
int r = write(logger->fd, "tokulogg", 8); if (r!=8) return errno;
r = write(logger->fd, &version_l, 4); if (r!=4) return errno;
}
if (logger->n_in_buf + nbytes > LOGGER_BUF_SIZE) {
printf("flushing %d %d\n", logger->n_in_buf, logger->n_in_file);
int r=flush(logger);
if (logger->n_in_buf + nbytes > LOGGER_BUF_SIZE
|| logger->n_in_file + logger->n_in_buf + nbytes > logger->lg_max) {
//printf("flushing %d %d\n", logger->n_in_buf, logger->n_in_file);
int r=flush(logger, 1);
if (r!=0) return r;
if (nbytes>LOGGER_BUF_SIZE) {
r = write(logger->fd, bytes, nbytes);
if (r!=0) return errno;
logger->n_in_file = nbytes;
return flush(logger);
return flush(logger, 0);
}
printf("saving %d\n", nbytes);
//printf("saving %d\n", nbytes);
}
memcpy(logger->buf+logger->n_in_buf, bytes, nbytes);
logger->n_in_buf += nbytes;
......@@ -202,9 +220,8 @@ n
int toku_logger_fsync (TOKULOGGER logger) {
//return 0;/// NO TXN
//fprintf(stderr, "%s:%d syncing log\n", __FILE__, __LINE__);
if (logger->is_panicked) return EINVAL;
int r=flush(logger);
int r=flush(logger, 0);
if (r!=0) return r;
if (logger->fd>=0) {
r = fsync(logger->fd);
......
......@@ -20,6 +20,9 @@ int toku_logger_panicked(TOKULOGGER /*logger*/);
int toku_logger_is_open(TOKULOGGER);
LSN toku_logger_last_lsn(TOKULOGGER);
int toku_logger_set_lg_max (TOKULOGGER logger, u_int32_t);
int toku_logger_get_lg_max (TOKULOGGER logger, u_int32_t *);
int toku_logger_log_phys_add_or_delete_in_leaf (DB *db, TOKUTXN txn, DISKOFF diskoff, int is_add, const struct kv_pair *pair);
int toku_logger_commit (TOKUTXN txn, int no_sync);
......
......@@ -462,8 +462,12 @@ static int toku_env_set_lg_dir(DB_ENV * env, const char *dir) {
static int toku_env_set_lg_max(DB_ENV * env, u_int32_t lg_max) {
HANDLE_PANICKED_ENV(env);
lg_max=lg_max;
return toku_ydb_do_error(env, EINVAL, "TokuDB does not (yet) support set_lg_max\n");
return toku_logger_set_lg_max(env->i->logger, lg_max);
}
static int toku_env_get_lg_max(DB_ENV * env, u_int32_t *lg_maxp) {
HANDLE_PANICKED_ENV(env);
return toku_logger_get_lg_max(env->i->logger, lg_maxp);
}
static int toku_env_set_lk_detect(DB_ENV * env, u_int32_t detect) {
......@@ -589,6 +593,10 @@ static int locked_env_set_lg_max(DB_ENV * env, u_int32_t lg_max) {
toku_ydb_lock(); int r = toku_env_set_lg_max(env, lg_max); toku_ydb_unlock(); return r;
}
static int locked_env_get_lg_max(DB_ENV * env, u_int32_t *lg_maxp) {
toku_ydb_lock(); int r = toku_env_get_lg_max(env, lg_maxp); toku_ydb_unlock(); return r;
}
static int locked_env_set_lk_detect(DB_ENV * env, u_int32_t detect) {
toku_ydb_lock(); int r = toku_env_set_lk_detect(env, detect); toku_ydb_unlock(); return r;
}
......@@ -633,6 +641,7 @@ static int toku_env_create(DB_ENV ** envp, u_int32_t flags) {
result->set_lg_bsize = locked_env_set_lg_bsize;
result->set_lg_dir = locked_env_set_lg_dir;
result->set_lg_max = locked_env_set_lg_max;
result->get_lg_max = locked_env_get_lg_max;
result->set_lk_max_locks = locked_env_set_lk_max_locks;
result->get_lk_max_locks = locked_env_get_lk_max_locks;
result->set_cachesize = locked_env_set_cachesize;
......
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