Commit 09519dda authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Generate many logs the way it is supposed to. 100MB files. Fixes #485.

git-svn-id: file:///svn/tokudb@2620 c7de825b-a66e-492c-adef-691d508d4ae1
parent 6e1b04dc
...@@ -94,6 +94,7 @@ int toku_logger_open (const char *directory, TOKULOGGER logger) { ...@@ -94,6 +94,7 @@ int toku_logger_open (const char *directory, TOKULOGGER logger) {
logger->fd = -1; logger->fd = -1;
logger->next_log_file_number = nexti; logger->next_log_file_number = nexti;
logger->n_in_buf = 0; logger->n_in_buf = 0;
logger->n_in_file = 0;
logger->lsn.lsn = 0; // WRONG!!! This should actually be calculated by looking at the log file. logger->lsn.lsn = 0; // WRONG!!! This should actually be calculated by looking at the log file.
...@@ -115,10 +116,25 @@ int toku_logger_is_open(TOKULOGGER logger) { ...@@ -115,10 +116,25 @@ int toku_logger_is_open(TOKULOGGER logger) {
return logger->is_open; return logger->is_open;
} }
static int flush (TOKULOGGER logger) {
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) {
int r = close(logger->fd);
if (r!=0) return errno;
logger->fd=-1;
logger->n_in_file = 0;
}
return 0;
}
static int log_format_version=0; static int log_format_version=0;
int toku_logger_log_bytes(TOKULOGGER logger, int nbytes, void *bytes) { int toku_logger_log_bytes(TOKULOGGER logger, int nbytes, void *bytes) {
int r;
if (logger->is_panicked) return EINVAL; if (logger->is_panicked) return EINVAL;
//fprintf(stderr, "%s:%d logging %d bytes\n", __FILE__, __LINE__, nbytes); //fprintf(stderr, "%s:%d logging %d bytes\n", __FILE__, __LINE__, nbytes);
if (logger->fd==-1) { if (logger->fd==-1) {
...@@ -130,31 +146,23 @@ int toku_logger_log_bytes(TOKULOGGER logger, int nbytes, void *bytes) { ...@@ -130,31 +146,23 @@ int toku_logger_log_bytes(TOKULOGGER logger, int nbytes, void *bytes) {
if (logger->fd==-1) return errno; 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);
r = write(logger->fd, "tokulogg", 8); if (r!=8) return errno; int r = write(logger->fd, "tokulogg", 8); if (r!=8) return errno;
r = write(logger->fd, &version_l, 4); if (r!=4) return errno; r = write(logger->fd, &version_l, 4); if (r!=4) return errno;
} }
if (logger->n_in_buf + nbytes > LOGGER_BUF_SIZE) { if (logger->n_in_buf + nbytes > LOGGER_BUF_SIZE) {
struct iovec v[2]; printf("flushing %d %d\n", logger->n_in_buf, logger->n_in_file);
v[0].iov_base = logger->buf; int r=flush(logger);
v[0].iov_len = logger->n_in_buf; if (r!=0) return r;
v[1].iov_base = bytes; if (nbytes>LOGGER_BUF_SIZE) {
v[1].iov_len = nbytes; r = write(logger->fd, bytes, nbytes);
//fprintf(stderr, "%s:%d flushing log due to buffer overflow\n", __FILE__, __LINE__);
r=writev(logger->fd, v, 2);
if (r!=logger->n_in_buf + nbytes) return errno;
logger->n_in_file += logger->n_in_buf+nbytes;
logger->n_in_buf=0;
if (logger->n_in_file > 100<<20) {
//fprintf(stderr, "%s:%d closing logfile\n", __FILE__, __LINE__);
r = close(logger->fd);
if (r!=0) return errno; if (r!=0) return errno;
logger->fd=-1; logger->n_in_file = nbytes;
logger->n_in_file = 0; return flush(logger);
}
printf("saving %d\n", nbytes);
} }
} else {
memcpy(logger->buf+logger->n_in_buf, bytes, nbytes); memcpy(logger->buf+logger->n_in_buf, bytes, nbytes);
logger->n_in_buf += nbytes; logger->n_in_buf += nbytes;
}
return 0; return 0;
} }
...@@ -169,7 +177,9 @@ int toku_logger_close(TOKULOGGER *loggerp) { ...@@ -169,7 +177,9 @@ int toku_logger_close(TOKULOGGER *loggerp) {
r = write(logger->fd, logger->buf, logger->n_in_buf); r = write(logger->fd, logger->buf, logger->n_in_buf);
if (r==-1) return errno; if (r==-1) return errno;
} }
r = close(logger->fd); r = fsync(logger->fd);
if (r!=0) close(logger->fd);
else r = close(logger->fd);
} }
toku_free(logger->directory); toku_free(logger->directory);
is_closed: is_closed:
...@@ -194,13 +204,10 @@ int toku_logger_fsync (TOKULOGGER logger) { ...@@ -194,13 +204,10 @@ int toku_logger_fsync (TOKULOGGER logger) {
//return 0;/// NO TXN //return 0;/// NO TXN
//fprintf(stderr, "%s:%d syncing log\n", __FILE__, __LINE__); //fprintf(stderr, "%s:%d syncing log\n", __FILE__, __LINE__);
if (logger->is_panicked) return EINVAL; if (logger->is_panicked) return EINVAL;
if (logger->n_in_buf>0) { int r=flush(logger);
int r = write(logger->fd, logger->buf, logger->n_in_buf); if (r!=0) return r;
if (r==-1) return errno; if (logger->fd>=0) {
logger->n_in_buf=0; r = fsync(logger->fd);
}
{
int r = fsync(logger->fd);
if (r!=0) return errno; if (r!=0) return errno;
} }
return 0; 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