Skip to content

Commit

Permalink
Set generation from ckp-logs
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Hannum <[email protected]>
  • Loading branch information
markhannum committed Dec 26, 2024
1 parent 56eaf05 commit 35a263b
Show file tree
Hide file tree
Showing 26 changed files with 459 additions and 228 deletions.
11 changes: 6 additions & 5 deletions bdb/phys_rep_lsn.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
logmsg(lvl, "physrep: " __VA_ARGS__); \
} while (0)

int matchable_log_type(int rectype);
int matchable_log_type(DB_ENV *dbenv, int rectype);

extern int gbl_physrep_debug;
int gbl_physrep_exit_on_invalid_logstream = 0;
Expand Down Expand Up @@ -126,7 +126,7 @@ int find_log_timestamp(bdb_state_type *bdb_state, time_t time,
LOGCOPY_32(&rectype, logrec.data);
normalize_rectype(&rectype);

} while (!matchable_log_type(rectype));
} while (!matchable_log_type(bdb_state->dbenv, rectype));

my_time = get_timestamp_from_matchable_record(logrec.data);
if (gbl_physrep_debug) {
Expand Down Expand Up @@ -194,7 +194,7 @@ static int get_next_matchable(DB_LOGC *logc, LOG_INFO *info, int check_current,
LOGCOPY_32(&rectype, logrec->data);
normalize_rectype(&rectype);

if (matchable_log_type(rectype) && in_parent_range(&match_lsn, parent_highest, parent_lowest)) {
if (matchable_log_type(logc->dbenv, rectype) && in_parent_range(&match_lsn, parent_highest, parent_lowest)) {
if (gbl_physrep_debug) {
physrep_logmsg(LOGMSG_USER, "%s: Initial rec {%u:%u} is matchable\n",
__func__, info->file, info->offset);
Expand Down Expand Up @@ -228,7 +228,8 @@ static int get_next_matchable(DB_LOGC *logc, LOG_INFO *info, int check_current,

LOGCOPY_32(&rectype, logrec->data);
normalize_rectype(&rectype);
matchable = (matchable_log_type(rectype) && in_parent_range(&match_lsn, parent_highest, parent_lowest));
matchable =
(matchable_log_type(logc->dbenv, rectype) && in_parent_range(&match_lsn, parent_highest, parent_lowest));
} while (!matchable);

info->file = match_lsn.file;
Expand Down Expand Up @@ -565,7 +566,7 @@ int physrep_bdb_wait_for_seqnum(bdb_state_type *bdb_state, DB_LSN *lsn, void *da

LOGCOPY_32(&rectype, data);
normalize_rectype(&rectype);
if (!matchable_log_type(rectype)) {
if (!matchable_log_type(bdb_state->dbenv, rectype)) {
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions berkdb/build/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ struct txn_properties;
#define DB_TXN_NOT_DURABLE 0x0000200 /* Do not log changes. */
#define DB_USE_ENVIRON 0x0000400 /* Use the environment. */
#define DB_USE_ENVIRON_ROOT 0x0000800 /* Use the environment if root. */
#define DB_RECOVERY_CKP 0x0001000 /* Do recovery checkpoint */

/*
* Common flags --
Expand Down
62 changes: 34 additions & 28 deletions berkdb/db/db_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,57 +105,56 @@ dump_log_event_counts(void)
{
int events[] = {
DB___bam_split, DB___bam_rsplit, DB___bam_adj, DB___bam_cadjust,
DB___bam_cdel,
DB___bam_cdel,
DB___bam_repl, DB___bam_root, DB___bam_curadj, DB___bam_rcuradj,
DB___crdel_metasub,
DB___crdel_metasub,
DB___db_addrem, DB___db_big, DB___db_ovref, DB___db_relink,
DB___db_debug,
DB___db_debug,
DB___db_noop, DB___db_pg_alloc, DB___db_pg_free, DB___db_cksum,
DB___db_pg_freedata,
DB___db_pg_freedata,
DB___db_pg_prepare, DB___db_pg_new, DB___dbreg_register,
DB___fop_create,
DB___fop_create,
DB___fop_remove, DB___fop_write, DB___fop_rename,
DB___fop_file_remove, DB___ham_insdel,
DB___fop_file_remove, DB___ham_insdel,
DB___ham_newpage, DB___ham_splitdata, DB___ham_replace,
DB___ham_copypage,
DB___ham_copypage,
DB___ham_metagroup, DB___ham_groupalloc, DB___ham_curadj,
DB___ham_chgpg, DB___qam_incfirst,
DB___ham_chgpg, DB___qam_incfirst,
DB___qam_mvptr, DB___qam_del, DB___qam_add, DB___qam_delext,
DB___txn_regop, DB___txn_dist_prepare, DB___txn_dist_abort,
DB___txn_regop, DB___txn_dist_prepare, DB___txn_dist_abort,
DB___txn_regop_gen, DB___txn_regop_rowlocks, DB___txn_dist_commit,
DB___txn_ckp, DB___txn_child, DB___txn_xa_regop,
DB___txn_recycle
DB___txn_ckp, DB___txn_ckp_recovery, DB___txn_child,
DB___txn_xa_regop, DB___txn_recycle
};
char *event_names[] = {
"DB___bam_split", "DB___bam_rsplit", "DB___bam_adj",
"DB___bam_cadjust", "DB___bam_cdel",
"DB___bam_cadjust", "DB___bam_cdel",
"DB___bam_repl", "DB___bam_root", "DB___bam_curadj",
"DB___bam_rcuradj", "DB___crdel_metasub",
"DB___bam_rcuradj", "DB___crdel_metasub",
"DB___db_addrem", "DB___db_big", "DB___db_ovref",
"DB___db_relink", "DB___db_debug",
"DB___db_relink", "DB___db_debug",
"DB___db_noop", "DB___db_pg_alloc", "DB___db_pg_free",
"DB___db_cksum", "DB___db_pg_freedata",
"DB___db_cksum", "DB___db_pg_freedata",
"DB___db_pg_prepare", "DB___db_pg_new", "DB___dbreg_register",
"DB___fop_create",
"DB___fop_create",
"DB___fop_remove", "DB___fop_write", "DB___fop_rename",
"DB___fop_file_remove", "DB___ham_insdel",
"DB___fop_file_remove", "DB___ham_insdel",
"DB___ham_newpage", "DB___ham_splitdata", "DB___ham_replace",
"DB___ham_copypage",
"DB___ham_copypage",
"DB___ham_metagroup", "DB___ham_groupalloc", "DB___ham_curadj",
"DB___ham_chgpg", "DB___qam_incfirst",
"DB___qam_mvptr", "DB___qam_del", "DB___qam_add",
"DB___qam_delext", "DB___txn_regop",
"DB___txn_dist_prepare", "DB___txn_dist_abort",
"DB___ham_chgpg", "DB___qam_incfirst",
"DB___qam_mvptr", "DB___qam_del", "DB___qam_add", "DB___qam_delext",
"DB___txn_regop", "DB___txn_dist_prepare", "DB___txn_dist_abort",
"DB___txn_regop_gen", "DB___txn_regop_rowlocks", "DB___txn_dist_commit",
"DB___txn_ckp", "DB___txn_child", "DB___txn_xa_regop",
"DB___txn_recycle"
"DB___txn_ckp", "DB___txn_ckp_recovery", "DB___txn_child",
"DB___txn_xa_regop", "DB___txn_recycle"
};
int i;

for (i = 0; i < sizeof(events) / sizeof(events[0]); i++) {
if (log_event_counts[events[i]])
logmsg(LOGMSG_USER, "%-20s %d\n", event_names[i],
log_event_counts[events[i]]);
log_event_counts[events[i]]);
}
}

Expand Down Expand Up @@ -262,6 +261,8 @@ optostr(int op)
return "DB___txn_dist_prepare";
case DB___txn_ckp:
return "DB___txn_ckp";
case DB___txn_ckp_recovery:
return "DB___txn_ckp_recovery";
case DB___txn_child:
return "DB___txn_child";
case DB___txn_xa_regop:
Expand Down Expand Up @@ -386,6 +387,7 @@ ufid_for_recovery_record(DB_ENV *env, DB_LSN *lsn, int rectype,
case DB___txn_dist_abort:
case DB___txn_regop_rowlocks:
case DB___txn_ckp:
case DB___txn_ckp_recovery:
case DB___txn_child:
case DB___txn_xa_regop:
case DB___txn_recycle:
Expand Down Expand Up @@ -469,7 +471,7 @@ __db_dispatch(dbenv, dtab, dtabsize, db, lsnp, redo, info)

if (normalize_rectype(&rectype) && (redo == DB_TXN_OPENFILES)) {
LOGCOPY_64(&utxnid, &((char*)db->data)[4 + 4 + 8]);
if (rectype == DB___txn_ckp) {
if (rectype == DB___txn_ckp || rectype == DB___txn_ckp_recovery) {
LOGCOPY_64(&maxutxnid, &((char*)db->data)[4 + 4 + 8 + 8 + 8 + 8 + 4 + 4]);
}
Pthread_mutex_lock(&dbenv->utxnid_lock);
Expand Down Expand Up @@ -559,8 +561,10 @@ __db_dispatch(dbenv, dtab, dtabsize, db, lsnp, redo, info)
/* FALLTHROUGH */
case DB_TXN_POPENFILES:
if (rectype == DB___dbreg_register ||
rectype == DB___txn_child ||
rectype == DB___txn_ckp || rectype == DB___txn_recycle)
rectype == DB___txn_child ||
rectype == DB___txn_ckp ||
rectype == DB___txn_ckp_recovery ||
rectype == DB___txn_recycle)
return (dtab[rectype] (dbenv, db, lsnp, redo, info));
break;
case DB_TXN_BACKWARD_ROLL:
Expand All @@ -583,6 +587,7 @@ __db_dispatch(dbenv, dtab, dtabsize, db, lsnp, redo, info)
case DB___txn_regop_rowlocks:
case DB___txn_recycle:
case DB___txn_ckp:
case DB___txn_ckp_recovery:
case DB___db_noop:
case DB___fop_file_remove:
case DB___txn_child:
Expand Down Expand Up @@ -647,6 +652,7 @@ __db_dispatch(dbenv, dtab, dtabsize, db, lsnp, redo, info)
switch (rectype) {
case DB___txn_recycle:
case DB___txn_ckp:
case DB___txn_ckp_recovery:
case DB___db_noop:
make_call = 1;
break;
Expand Down
13 changes: 13 additions & 0 deletions berkdb/dbinc_auto/txn_auto.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,17 @@ typedef struct __txn_dist_commit_args {
u_int64_t timestamp;
DBT dist_txnid;
} __txn_dist_commit_args;

#define DB___txn_ckp_recovery 20
typedef struct __txn_ckp_recovery_args {
u_int32_t type;
DB_TXN *txnid;
DB_LSN prev_lsn;
DB_LSN ckp_lsn;
DB_LSN last_ckp;
int32_t timestamp;
u_int32_t rep_gen;
u_int64_t max_utxnid;
} __txn_ckp_recovery_args;

#endif
2 changes: 1 addition & 1 deletion berkdb/dbinc_auto/txn_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int __txn_regop_rowlocks_getpgnos __P((DB_ENV *, DBT *, DB_LSN *, db_recops, voi
int __txn_regop_rowlocks_getallpgnos __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
int __txn_regop_rowlocks_print __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
int __txn_regop_rowlocks_read __P((DB_ENV *, void *, __txn_regop_rowlocks_args **));
int __txn_ckp_log __P((DB_ENV *, DB_TXN *, DB_LSN *, u_int32_t, DB_LSN *, DB_LSN *, int32_t, u_int32_t, u_int64_t));
int __txn_ckp_log __P((DB_ENV *, DB_TXN *, u_int32_t, DB_LSN *, u_int32_t, DB_LSN *, DB_LSN *, int32_t, u_int32_t, u_int64_t));
int __txn_ckp_getpgnos __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
int __txn_ckp_getallpgnos __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
int __txn_ckp_print __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
Expand Down
13 changes: 7 additions & 6 deletions berkdb/env/env_recover.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ __checkpoint_get_recovery_lsn(DB_ENV *dbenv, DB_LSN *lsnout)

LOGCOPY_32(&type, dbt.data);
normalize_rectype(&type);
if (type != DB___txn_ckp) {
if (type != DB___txn_ckp && type != DB___txn_ckp_recovery) {
logmsg(LOGMSG_ERROR, "checkpoint record unexpeted type %d\n", type);
goto err;
}
Expand Down Expand Up @@ -775,7 +775,7 @@ int __dbenv_build_mintruncate_list(dbenv)
Pthread_mutex_unlock(&dbenv->mintruncate_lk);
}

if (type == DB___txn_ckp) {
if (type == DB___txn_ckp || type == DB___txn_ckp_recovery) {
if ((ret = __txn_ckp_read(dbenv, rec.data, &ckp_args)) != 0)
abort();

Expand Down Expand Up @@ -1528,7 +1528,7 @@ __db_apprec(dbenv, max_lsn, trunclsn, update, flags)
logmsg(LOGMSG_ERROR, "memp_sync returned %d\n", ret);
goto err;
}
} else if ((ret = __txn_checkpoint(dbenv, 0, 0, DB_FORCE)) != 0)
} else if ((ret = __txn_checkpoint(dbenv, 0, 0, DB_FORCE|DB_RECOVERY_CKP)) != 0)
goto err;


Expand Down Expand Up @@ -1836,7 +1836,7 @@ __log_find_latest_checkpoint_before_lsn_try_harder(DB_ENV * dbenv,
if (data.size >= sizeof(u_int32_t)) {
LOGCOPY_32(&type, data.data);
normalize_rectype(&type);
if (type == DB___txn_ckp) {
if (type == DB___txn_ckp || type == DB___txn_ckp_recovery) {
if (log_compare(&lsn, max_lsn) < 0) {
*foundlsn = lsn;
free(data.data);
Expand Down Expand Up @@ -1959,7 +1959,7 @@ __log_earliest(dbenv, logc, lowtime, lowlsn)
ret == 0; ret = __log_c_get(logc, &lsn, &data, DB_NEXT)) {
LOGCOPY_32(&rectype, data.data);
normalize_rectype(&rectype);
if (rectype != DB___txn_ckp)
if (rectype != DB___txn_ckp && rectype != DB___txn_ckp_recovery)
continue;
if ((ret = __txn_ckp_read(dbenv, data.data, &ckpargs)) == 0) {
cmp = log_compare(&ckpargs->ckp_lsn, &first_lsn);
Expand Down Expand Up @@ -2153,6 +2153,7 @@ __recover_logfile_pglogs(dbenv, fileid_tbl)
LOGCOPY_32(&rectype, data.data);
normalize_rectype(&rectype);
switch (rectype) {
case DB___txn_ckp_recovery:
case DB___txn_ckp:
if ((ret =
__txn_ckp_read(dbenv, data.data,
Expand Down Expand Up @@ -2507,7 +2508,7 @@ __env_find_verify_recover_start(dbenv, lsnp)
do {
LOGCOPY_32(&rectype, rec.data);
normalize_rectype(&rectype);
} while ((!matchable_log_type(rectype) || log_compare(lsnp, &s_lsn) >= 0) &&
} while ((!matchable_log_type(dbenv, rectype) || log_compare(lsnp, &s_lsn) >= 0) &&
(ret = __log_c_get(logc, lsnp, &rec, DB_PREV)) == 0);

if (ret != 0)
Expand Down
4 changes: 2 additions & 2 deletions berkdb/log/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ __log_get_last_ckp(DB_ENV *dbenv, DB_LSN *lsn)

LOGCOPY_32(&rectype, dbt.data);
normalize_rectype(&rectype);
if (rectype == DB___txn_ckp) {
if (rectype == DB___txn_ckp || rectype == DB___txn_ckp_recovery) {
/* found it */
(void)__log_c_close(logc);
return 0;
Expand Down Expand Up @@ -415,7 +415,7 @@ __log_recover(dblp)
continue;
LOGCOPY_32(&rectype, dbt.data);
normalize_rectype(&rectype);
if (rectype == DB___txn_ckp)
if (rectype == DB___txn_ckp || rectype == DB___txn_ckp_recovery)
/*
* If we happen to run into a checkpoint, cache its
* LSN so that the transaction system doesn't have
Expand Down
2 changes: 1 addition & 1 deletion berkdb/mp/mp_bh.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ berkdb_verify_lsn_written_to_disk(DB_ENV *dbenv, DB_LSN *lsn,
LOGCOPY_32(&type, logent);
normalize_rectype(&type);
/* check that the checkpoint lsn is valid and readable */
if (type == DB___txn_ckp && check_checkpoint) {
if ((type == DB___txn_ckp || type == DB___txn_ckp_recovery) && check_checkpoint) {
__txn_ckp_args *ckp = NULL;

rc = __txn_ckp_read(dbenv, logent, &ckp);
Expand Down
Loading

0 comments on commit 35a263b

Please sign in to comment.