Skip to content

Commit

Permalink
Don't run full recovery for snapshot
Browse files Browse the repository at this point in the history
Signed-off-by: mdouglas47 <[email protected]>
  • Loading branch information
morgando committed Feb 26, 2025
1 parent 5b72028 commit 20cde44
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 31 deletions.
2 changes: 2 additions & 0 deletions bdb/bdbglue.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
struct bdb_state_tag;
extern struct bdb_state_tag *gbl_bdb_state;

int bdb_recovery_timestamp_fulfills_log_age_requirement(int32_t timestamp);

/* Acquire the write lock. If the current thread already holds the bdb read
* lock then it is upgraded to a write lock. If it already holds the write
* lock then we just increase our reference count. */
Expand Down
57 changes: 29 additions & 28 deletions bdb/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,15 @@ int bdb_checkpoint_list_push(DB_LSN lsn, DB_LSN ckp_lsn, int32_t timestamp, int
return 0;
}

static int bdb_checkpoint_list_ok_to_delete_log(int min_keep_logs_age,
int filenum)
int bdb_recovery_timestamp_fulfills_log_age_requirement(int32_t recovery_timestamp)
{
const bdb_state_type *bdb_state = thedb->bdb_env;

return (time(NULL) - recovery_timestamp) >= bdb_state->attr->min_keep_logs_age;
}

static int bdb_need_log_to_fulfill_log_age_requirement(int min_keep_logs_age,
int filenum)
{
struct checkpoint_list *ckp = NULL;
if (!ckp_lst_ready)
Expand All @@ -226,17 +233,13 @@ static int bdb_checkpoint_list_ok_to_delete_log(int min_keep_logs_age,
LISTC_FOR_EACH(&ckp_lst, ckp, lnk)
{
/* find the first checkpoint which references a file that's larger than
* the deleted logfile */
* the logfile that we're considering deleting */
if (ckp->ckp_lsn.file > filenum) {
/* the furthest point we can recover to is less than what we
* guaranteed the users*/
if (time(NULL) - ckp->timestamp < min_keep_logs_age) {
Pthread_mutex_unlock(&ckp_lst_mtx);
return 0;
} else {
Pthread_mutex_unlock(&ckp_lst_mtx);
return 1;
}
const int ckp_in_newer_logfile_can_be_oldest_ckp = bdb_recovery_timestamp_fulfills_log_age_requirement(ckp->timestamp);
const int need_logfile = !ckp_in_newer_logfile_can_be_oldest_ckp;

Pthread_mutex_unlock(&ckp_lst_mtx);
return need_logfile;
}
}
Pthread_mutex_unlock(&ckp_lst_mtx);
Expand Down Expand Up @@ -324,7 +327,8 @@ void bdb_checkpoint_list_get_ckplsn_before_lsn(DB_LSN lsn, DB_LSN *lsnout)
}
Pthread_mutex_unlock(&ckp_lst_mtx);

/* huh?? not found? BUG BUG */
logmsg(LOGMSG_ERROR, "%s: Failed to find checkpoint LSN before %"PRIu32":%"PRIu32".\n",
__func__, lsn.file, lsn.offset);
abort();
}

Expand Down Expand Up @@ -3884,22 +3888,19 @@ static void delete_log_files_int(bdb_state_type *bdb_state)
}
}

if (gbl_new_snapisol_asof || gbl_modsnap_asof) {
/* check if we still can maintain snapshot that begin as of
* min_keep_logs_age seconds ago */
if (!bdb_checkpoint_list_ok_to_delete_log(
if ((gbl_new_snapisol_asof || gbl_modsnap_asof)
&& bdb_need_log_to_fulfill_log_age_requirement(
bdb_state->attr->min_keep_logs_age, filenum)) {
Pthread_mutex_unlock(&bdb_gbl_recoverable_lsn_mutex);
if (bdb_state->attr->debug_log_deletion)
logmsg(LOGMSG_USER, "not ok to delete log, log file needed "
"to recover to at least %ds ago\n",
bdb_state->attr->min_keep_logs_age);
if (ctrace_info)
ctrace("not ok to delete log, log file needed to "
"recover to at least %ds ago\n",
bdb_state->attr->min_keep_logs_age);
break;
}
Pthread_mutex_unlock(&bdb_gbl_recoverable_lsn_mutex);
if (bdb_state->attr->debug_log_deletion)
logmsg(LOGMSG_USER, "not ok to delete log, log file needed "
"to recover to at least %ds ago\n",
bdb_state->attr->min_keep_logs_age);
if (ctrace_info)
ctrace("not ok to delete log, log file needed to "
"recover to at least %ds ago\n",
bdb_state->attr->min_keep_logs_age);
break;
}

/* If we made it this far, we're willing to delete this file
Expand Down
10 changes: 7 additions & 3 deletions berkdb/env/env_recover.c
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,6 @@ __db_apprec(dbenv, max_lsn, trunclsn, update, flags)
} else if ((ret = __txn_checkpoint(dbenv, 0, 0, DB_FORCE|DB_RECOVERY_CKP)) != 0)
goto err;


/* Close all the db files that are open. */
if ((ret = __dbreg_close_files(dbenv)) != 0)
goto err;
Expand Down Expand Up @@ -2131,8 +2130,9 @@ __scan_logfiles_for_asof_modsnap(dbenv)

DB_LSN recoverable_lsn;
ZERO_LSN(recoverable_lsn);
for (ret = __log_c_get(logc, &last_lsn, &data, DB_LAST), lsn =
last_lsn; ret == 0;
int done = 0;
for (ret = __log_c_get(logc, &last_lsn, &data, DB_LAST), lsn=last_lsn;
ret == 0 && !done;
ret = __log_c_get(logc, &lsn, &data, DB_PREV)) {
LOGCOPY_32(&rectype, data.data);
normalize_rectype(&rectype);
Expand Down Expand Up @@ -2166,6 +2166,10 @@ __scan_logfiles_for_asof_modsnap(dbenv)
lsn.file, lsn.offset);
}

if (bdb_recovery_timestamp_fulfills_log_age_requirement(ckp_args->timestamp)) {
done = 1;
}

break;
case DB___txn_regop_gen:
if ((ret =
Expand Down
1 change: 1 addition & 0 deletions tests/siasofbounce.test/lrl.options
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
enable_snapshot_isolation
min_keep_logs_age 400

0 comments on commit 20cde44

Please sign in to comment.