Commit 3decdc0a authored by Dave Wells's avatar Dave Wells Committed by Yoni Fogel

Fix recover-missing-logfiles test. In the process, define...

Fix recover-missing-logfiles test.  In the process, define DB_CLOSE_DONT_TRIM_LOG flag for db_close.  Also, remove some old, unused code

git-svn-id: file:///svn/toku/tokudb@14631 c7de825b-a66e-492c-adef-691d508d4ae1
parent 8771ff74
...@@ -83,6 +83,7 @@ void print_defines (void) { ...@@ -83,6 +83,7 @@ void print_defines (void) {
dodefine(DB_INIT_LOCK); dodefine(DB_INIT_LOCK);
dodefine(DB_INIT_LOG); dodefine(DB_INIT_LOG);
dodefine(DB_INIT_MPOOL); dodefine(DB_INIT_MPOOL);
printf("#define DB_CLOSE_DONT_TRIM_LOG 1048576\n"); // tokudb
dodefine(DB_INIT_TXN); dodefine(DB_INIT_TXN);
dodefine(DB_USE_ENVIRON); dodefine(DB_USE_ENVIRON);
dodefine(DB_USE_ENVIRON_ROOT); dodefine(DB_USE_ENVIRON_ROOT);
......
...@@ -81,6 +81,7 @@ typedef enum { ...@@ -81,6 +81,7 @@ typedef enum {
#define DB_INIT_LOCK 131072 #define DB_INIT_LOCK 131072
#define DB_INIT_LOG 262144 #define DB_INIT_LOG 262144
#define DB_INIT_MPOOL 524288 #define DB_INIT_MPOOL 524288
#define DB_CLOSE_DONT_TRIM_LOG 1048576
#define DB_INIT_TXN 2097152 #define DB_INIT_TXN 2097152
#define DB_USE_ENVIRON 16384 #define DB_USE_ENVIRON 16384
#define DB_USE_ENVIRON_ROOT 32768 #define DB_USE_ENVIRON_ROOT 32768
......
...@@ -57,6 +57,7 @@ struct tokulogger { ...@@ -57,6 +57,7 @@ struct tokulogger {
int is_open; int is_open;
int is_panicked; int is_panicked;
BOOL write_log_files; BOOL write_log_files;
BOOL trim_log_files; // for test purposes
int panic_errno; int panic_errno;
char *directory; char *directory;
int fd; int fd;
......
...@@ -70,9 +70,9 @@ static int lc_check_lsn(TOKULOGCURSOR lc, int dir) { ...@@ -70,9 +70,9 @@ static int lc_check_lsn(TOKULOGCURSOR lc, int dir) {
LSN lsn = toku_log_entry_get_lsn(&(lc->entry)); LSN lsn = toku_log_entry_get_lsn(&(lc->entry));
if (((dir == LC_FORWARD) && ( lsn.lsn != lc->cur_lsn.lsn + 1 )) || if (((dir == LC_FORWARD) && ( lsn.lsn != lc->cur_lsn.lsn + 1 )) ||
((dir == LC_BACKWARD) && ( lsn.lsn != lc->cur_lsn.lsn - 1 ))) { ((dir == LC_BACKWARD) && ( lsn.lsn != lc->cur_lsn.lsn - 1 ))) {
int index = lc->cur_logfiles_index; // int index = lc->cur_logfiles_index;
fprintf(stderr, "Bad LSN: %d %s direction = %d, lsn.lsn = %"PRIu64", cur_lsn.lsn=%"PRIu64"\n", // fprintf(stderr, "Bad LSN: %d %s direction = %d, lsn.lsn = %"PRIu64", cur_lsn.lsn=%"PRIu64"\n",
index, lc->logfiles[index], dir, lsn.lsn, lc->cur_lsn.lsn); // index, lc->logfiles[index], dir, lsn.lsn, lc->cur_lsn.lsn);
return LC_LSN_ERROR; return LC_LSN_ERROR;
} }
lc->cur_lsn.lsn = lsn.lsn; lc->cur_lsn.lsn = lsn.lsn;
......
...@@ -21,6 +21,7 @@ int toku_logger_create (TOKULOGGER *resultp) { ...@@ -21,6 +21,7 @@ int toku_logger_create (TOKULOGGER *resultp) {
result->is_open=0; result->is_open=0;
result->is_panicked=0; result->is_panicked=0;
result->write_log_files = TRUE; result->write_log_files = TRUE;
result->trim_log_files = TRUE;
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};
...@@ -378,7 +379,7 @@ int toku_logger_maybe_trim_log(TOKULOGGER logger, LSN trim_lsn) { ...@@ -378,7 +379,7 @@ int toku_logger_maybe_trim_log(TOKULOGGER logger, LSN trim_lsn) {
TOKULOGFILEINFO lf_info = NULL; TOKULOGFILEINFO lf_info = NULL;
if ( logger->write_log_files ) { if ( logger->write_log_files && logger->trim_log_files) {
while ( n_logfiles > 1 ) { // don't delete current logfile while ( n_logfiles > 1 ) { // don't delete current logfile
lf_info = toku_logfilemgr_get_oldest_logfile_info(lfm); lf_info = toku_logfilemgr_get_oldest_logfile_info(lfm);
if ( lf_info->maxlsn.lsn > trim_lsn.lsn ) { if ( lf_info->maxlsn.lsn > trim_lsn.lsn ) {
...@@ -412,6 +413,11 @@ void toku_logger_write_log_files (TOKULOGGER logger, BOOL write_log_files) { ...@@ -412,6 +413,11 @@ void toku_logger_write_log_files (TOKULOGGER logger, BOOL write_log_files) {
logger->write_log_files = write_log_files; logger->write_log_files = write_log_files;
} }
void toku_logger_trim_log_files (TOKULOGGER logger, BOOL trim_log_files) {
assert(logger);
logger->trim_log_files = trim_log_files;
}
// Enter holding both locks // Enter holding both locks
// Exit holding only the output_lock // Exit holding only the output_lock
static int do_write (TOKULOGGER logger, int do_fsync) { static int do_write (TOKULOGGER logger, int do_fsync) {
...@@ -488,6 +494,7 @@ int toku_logger_restart(TOKULOGGER logger, LSN lastlsn) { ...@@ -488,6 +494,7 @@ int toku_logger_restart(TOKULOGGER logger, LSN lastlsn) {
// reset the LSN's to the lastlsn when the logger was opened // reset the LSN's to the lastlsn when the logger was opened
logger->lsn = logger->written_lsn = logger->fsynced_lsn = lastlsn; logger->lsn = logger->written_lsn = logger->fsynced_lsn = lastlsn;
logger->write_log_files = TRUE; logger->write_log_files = TRUE;
logger->trim_log_files = TRUE;
// open a new log file // open a new log file
return open_logfile(logger); return open_logfile(logger);
......
...@@ -26,6 +26,7 @@ int toku_logger_lock_init(void); ...@@ -26,6 +26,7 @@ int toku_logger_lock_init(void);
int toku_logger_lock_destroy(void); int toku_logger_lock_destroy(void);
void toku_logger_write_log_files (TOKULOGGER logger, BOOL write_log_files); void toku_logger_write_log_files (TOKULOGGER logger, BOOL write_log_files);
void toku_logger_trim_log_files(TOKULOGGER logger, BOOL trim_log_files);
// Restart the logger. This function is used by recovery to really start // Restart the logger. This function is used by recovery to really start
// logging. // logging.
......
...@@ -773,17 +773,8 @@ static int do_recovery(RECOVER_ENV renv, const char *data_dir, const char *log_d ...@@ -773,17 +773,8 @@ static int do_recovery(RECOVER_ENV renv, const char *data_dir, const char *log_d
assert(r == 0); assert(r == 0);
// checkpoint // checkpoint
#if 1
r = toku_checkpoint(renv->ct, renv->logger, NULL, NULL, NULL, NULL, NULL); r = toku_checkpoint(renv->ct, renv->logger, NULL, NULL, NULL, NULL, NULL);
assert(r == 0); assert(r == 0);
#else
// TODO: checkpoint locks needed here?
r = toku_cachetable_begin_checkpoint(renv->ct, renv->logger);
assert(r == 0);
// TODO: what about the error_string?
r = toku_cachetable_end_checkpoint(renv->ct, renv->logger, NULL, NULL, NULL);
assert(r == 0);
#endif
r = chdir(org_wd); r = chdir(org_wd);
assert(r == 0); assert(r == 0);
......
...@@ -9,6 +9,11 @@ const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG ...@@ -9,6 +9,11 @@ const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG
char *namea="a.db"; char *namea="a.db";
char *nameb="b.db"; char *nameb="b.db";
// needed to get .bdb versions to compile
#ifndef DB_CLOSE_DONT_TRIM_LOG
#define DB_CLOSE_DONT_TRIM_LOG 0
#endif
static void run_test (void) { static void run_test (void) {
int r; int r;
system("rm -rf " ENVDIR); system("rm -rf " ENVDIR);
...@@ -19,12 +24,12 @@ static void run_test (void) { ...@@ -19,12 +24,12 @@ static void run_test (void) {
// create logfile 0 // create logfile 0
r = db_env_create(&env, 0); CKERR(r); r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r); r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = env->close(env, 0); CKERR(r); r = env->close(env, DB_CLOSE_DONT_TRIM_LOG); CKERR(r);
// create logfile 1 // create logfile 1
r = db_env_create(&env, 0); CKERR(r); r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r); r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = env->close(env, 0); CKERR(r); r = env->close(env, DB_CLOSE_DONT_TRIM_LOG); CKERR(r);
// create logfile 2 // create logfile 2
r = db_env_create(&env, 0); CKERR(r); r = db_env_create(&env, 0); CKERR(r);
......
...@@ -469,17 +469,13 @@ static int toku_env_close(DB_ENV * env, u_int32_t flags) { ...@@ -469,17 +469,13 @@ static int toku_env_close(DB_ENV * env, u_int32_t flags) {
toku_ydb_unlock(); // ydb lock must not be held when shutting down minicron toku_ydb_unlock(); // ydb lock must not be held when shutting down minicron
toku_cachetable_minicron_shutdown(env->i->cachetable); toku_cachetable_minicron_shutdown(env->i->cachetable);
if (env->i->logger) { if (env->i->logger) {
#if 1 if ( flags && DB_CLOSE_DONT_TRIM_LOG ) {
toku_logger_trim_log_files(env->i->logger, FALSE);
}
r0 = toku_checkpoint(env->i->cachetable, env->i->logger, NULL, NULL, NULL, NULL, NULL); r0 = toku_checkpoint(env->i->cachetable, env->i->logger, NULL, NULL, NULL, NULL, NULL);
assert(r0 == 0); assert(r0 == 0);
#else r0 = toku_logger_shutdown(env->i->logger);
// TODO locks?
r0 = toku_cachetable_begin_checkpoint(env->i->cachetable, env->i->logger);
if (r0 == 0)
toku_cachetable_end_checkpoint(env->i->cachetable, env->i->logger, NULL, NULL, NULL);
assert(r0 == 0); assert(r0 == 0);
#endif
r0 = toku_logger_shutdown(env->i->logger); assert(r0 == 0);
} }
toku_ydb_lock(); toku_ydb_lock();
r0=toku_cachetable_close(&env->i->cachetable); r0=toku_cachetable_close(&env->i->cachetable);
...@@ -521,7 +517,7 @@ static int toku_env_close(DB_ENV * env, u_int32_t flags) { ...@@ -521,7 +517,7 @@ static int toku_env_close(DB_ENV * env, u_int32_t flags) {
toku_free(env->i); toku_free(env->i);
toku_free(env); toku_free(env);
ydb_unref(); ydb_unref();
if (flags!=0) return EINVAL; if ( (flags!=0) && !(flags==DB_CLOSE_DONT_TRIM_LOG) ) return EINVAL;
if (r0) return r0; if (r0) return r0;
if (r1) return r1; if (r1) return r1;
return is_panicked; return is_panicked;
......
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