#include "db_config.h"

#include "db_int.h"
#include "dbinc/db_page.h"
#include "dbinc/__bam.h"
#include "dbinc/log.h"

/*
 * __bam_split_recover --
 *	Recovery function for split.
 *
 * PUBLIC: int __bam_split_recover
 * PUBLIC:   __P((env *, DBT *, DB_LSN *, db_recops, void *));
 */
int
__bam_split_recover(env, dbtp, lsnp, op, info)
	env *env;
	DBT *dbtp;
	DB_LSN *lsnp;
	db_recops op;
	void *info;
{
	__bam_split_args *argp;
	DB *file_dbp;
	DBC *dbc;
	DB_MPOOLFILE *mpf;
	DB_THREAD_INFO *ip;
	PAGE *pagep;
	int cmp_n, cmp_p, modified, ret;

	ip = ((DB_TXNHEAD *)info)->thread_info;

	REC_PRINT(__bam_split_print);
	REC_INTRO(__bam_split_read, ip, 0);

	if ((ret = mpf->get(mpf, &argp->pgno, 0, &pagep)) != 0)
		if (DB_REDO(op)) {
			if ((ret = mpf->get(mpf,
			    &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
				goto out;
		} else {
			*lsnp = argp->prev_lsn;
			ret = 0;
			goto out;
		}

	modified = 0;
	cmp_n = log_compare(lsnp, &LSN(pagep));

	/*
	 * Use this when there is something like "pagelsn" in the argp
	 * structure.  Sometimes, you might need to compare meta-data
	 * lsn's instead.
	 *
	 * cmp_p = log_compare(&LSN(pagep), argp->pagelsn);
	 */
	if (cmp_p == 0 && DB_REDO(op)) {
		/* Need to redo update described. */
		modified = 1;
	} else if (cmp_n == 0 && !DB_REDO(op)) {
		/* Need to undo update described. */
		modified = 1;
	}
	if (ret = mpf->put(mpf, pagep, modified ? DB_MPOOL_DIRTY : 0))
		goto out;

	*lsnp = argp->prev_lsn;
	ret = 0;

out:	REC_CLOSE;
}

/*
 * __bam_rsplit_recover --
 *	Recovery function for rsplit.
 *
 * PUBLIC: int __bam_rsplit_recover
 * PUBLIC:   __P((env *, DBT *, DB_LSN *, db_recops, void *));
 */
int
__bam_rsplit_recover(env, dbtp, lsnp, op, info)
	env *env;
	DBT *dbtp;
	DB_LSN *lsnp;
	db_recops op;
	void *info;
{
	__bam_rsplit_args *argp;
	DB *file_dbp;
	DBC *dbc;
	DB_MPOOLFILE *mpf;
	DB_THREAD_INFO *ip;
	PAGE *pagep;
	int cmp_n, cmp_p, modified, ret;

	ip = ((DB_TXNHEAD *)info)->thread_info;

	REC_PRINT(__bam_rsplit_print);
	REC_INTRO(__bam_rsplit_read, ip, 0);

	if ((ret = mpf->get(mpf, &argp->pgno, 0, &pagep)) != 0)
		if (DB_REDO(op)) {
			if ((ret = mpf->get(mpf,
			    &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
				goto out;
		} else {
			*lsnp = argp->prev_lsn;
			ret = 0;
			goto out;
		}

	modified = 0;
	cmp_n = log_compare(lsnp, &LSN(pagep));

	/*
	 * Use this when there is something like "pagelsn" in the argp
	 * structure.  Sometimes, you might need to compare meta-data
	 * lsn's instead.
	 *
	 * cmp_p = log_compare(&LSN(pagep), argp->pagelsn);
	 */
	if (cmp_p == 0 && DB_REDO(op)) {
		/* Need to redo update described. */
		modified = 1;
	} else if (cmp_n == 0 && !DB_REDO(op)) {
		/* Need to undo update described. */
		modified = 1;
	}
	if (ret = mpf->put(mpf, pagep, modified ? DB_MPOOL_DIRTY : 0))
		goto out;

	*lsnp = argp->prev_lsn;
	ret = 0;

out:	REC_CLOSE;
}

/*
 * __bam_adj_recover --
 *	Recovery function for adj.
 *
 * PUBLIC: int __bam_adj_recover
 * PUBLIC:   __P((env *, DBT *, DB_LSN *, db_recops, void *));
 */
int
__bam_adj_recover(env, dbtp, lsnp, op, info)
	env *env;
	DBT *dbtp;
	DB_LSN *lsnp;
	db_recops op;
	void *info;
{
	__bam_adj_args *argp;
	DB *file_dbp;
	DBC *dbc;
	DB_MPOOLFILE *mpf;
	DB_THREAD_INFO *ip;
	PAGE *pagep;
	int cmp_n, cmp_p, modified, ret;

	ip = ((DB_TXNHEAD *)info)->thread_info;

	REC_PRINT(__bam_adj_print);
	REC_INTRO(__bam_adj_read, ip, 0);

	if ((ret = mpf->get(mpf, &argp->pgno, 0, &pagep)) != 0)
		if (DB_REDO(op)) {
			if ((ret = mpf->get(mpf,
			    &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
				goto out;
		} else {
			*lsnp = argp->prev_lsn;
			ret = 0;
			goto out;
		}

	modified = 0;
	cmp_n = log_compare(lsnp, &LSN(pagep));

	/*
	 * Use this when there is something like "pagelsn" in the argp
	 * structure.  Sometimes, you might need to compare meta-data
	 * lsn's instead.
	 *
	 * cmp_p = log_compare(&LSN(pagep), argp->pagelsn);
	 */
	if (cmp_p == 0 && DB_REDO(op)) {
		/* Need to redo update described. */
		modified = 1;
	} else if (cmp_n == 0 && !DB_REDO(op)) {
		/* Need to undo update described. */
		modified = 1;
	}
	if (ret = mpf->put(mpf, pagep, modified ? DB_MPOOL_DIRTY : 0))
		goto out;

	*lsnp = argp->prev_lsn;
	ret = 0;

out:	REC_CLOSE;
}

/*
 * __bam_cadjust_recover --
 *	Recovery function for cadjust.
 *
 * PUBLIC: int __bam_cadjust_recover
 * PUBLIC:   __P((env *, DBT *, DB_LSN *, db_recops, void *));
 */
int
__bam_cadjust_recover(env, dbtp, lsnp, op, info)
	env *env;
	DBT *dbtp;
	DB_LSN *lsnp;
	db_recops op;
	void *info;
{
	__bam_cadjust_args *argp;
	DB *file_dbp;
	DBC *dbc;
	DB_MPOOLFILE *mpf;
	DB_THREAD_INFO *ip;
	PAGE *pagep;
	int cmp_n, cmp_p, modified, ret;

	ip = ((DB_TXNHEAD *)info)->thread_info;

	REC_PRINT(__bam_cadjust_print);
	REC_INTRO(__bam_cadjust_read, ip, 0);

	if ((ret = mpf->get(mpf, &argp->pgno, 0, &pagep)) != 0)
		if (DB_REDO(op)) {
			if ((ret = mpf->get(mpf,
			    &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
				goto out;
		} else {
			*lsnp = argp->prev_lsn;
			ret = 0;
			goto out;
		}

	modified = 0;
	cmp_n = log_compare(lsnp, &LSN(pagep));

	/*
	 * Use this when there is something like "pagelsn" in the argp
	 * structure.  Sometimes, you might need to compare meta-data
	 * lsn's instead.
	 *
	 * cmp_p = log_compare(&LSN(pagep), argp->pagelsn);
	 */
	if (cmp_p == 0 && DB_REDO(op)) {
		/* Need to redo update described. */
		modified = 1;
	} else if (cmp_n == 0 && !DB_REDO(op)) {
		/* Need to undo update described. */
		modified = 1;
	}
	if (ret = mpf->put(mpf, pagep, modified ? DB_MPOOL_DIRTY : 0))
		goto out;

	*lsnp = argp->prev_lsn;
	ret = 0;

out:	REC_CLOSE;
}

/*
 * __bam_cdel_recover --
 *	Recovery function for cdel.
 *
 * PUBLIC: int __bam_cdel_recover
 * PUBLIC:   __P((env *, DBT *, DB_LSN *, db_recops, void *));
 */
int
__bam_cdel_recover(env, dbtp, lsnp, op, info)
	env *env;
	DBT *dbtp;
	DB_LSN *lsnp;
	db_recops op;
	void *info;
{
	__bam_cdel_args *argp;
	DB *file_dbp;
	DBC *dbc;
	DB_MPOOLFILE *mpf;
	DB_THREAD_INFO *ip;
	PAGE *pagep;
	int cmp_n, cmp_p, modified, ret;

	ip = ((DB_TXNHEAD *)info)->thread_info;

	REC_PRINT(__bam_cdel_print);
	REC_INTRO(__bam_cdel_read, ip, 0);

	if ((ret = mpf->get(mpf, &argp->pgno, 0, &pagep)) != 0)
		if (DB_REDO(op)) {
			if ((ret = mpf->get(mpf,
			    &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
				goto out;
		} else {
			*lsnp = argp->prev_lsn;
			ret = 0;
			goto out;
		}

	modified = 0;
	cmp_n = log_compare(lsnp, &LSN(pagep));

	/*
	 * Use this when there is something like "pagelsn" in the argp
	 * structure.  Sometimes, you might need to compare meta-data
	 * lsn's instead.
	 *
	 * cmp_p = log_compare(&LSN(pagep), argp->pagelsn);
	 */
	if (cmp_p == 0 && DB_REDO(op)) {
		/* Need to redo update described. */
		modified = 1;
	} else if (cmp_n == 0 && !DB_REDO(op)) {
		/* Need to undo update described. */
		modified = 1;
	}
	if (ret = mpf->put(mpf, pagep, modified ? DB_MPOOL_DIRTY : 0))
		goto out;

	*lsnp = argp->prev_lsn;
	ret = 0;

out:	REC_CLOSE;
}

/*
 * __bam_repl_recover --
 *	Recovery function for repl.
 *
 * PUBLIC: int __bam_repl_recover
 * PUBLIC:   __P((env *, DBT *, DB_LSN *, db_recops, void *));
 */
int
__bam_repl_recover(env, dbtp, lsnp, op, info)
	env *env;
	DBT *dbtp;
	DB_LSN *lsnp;
	db_recops op;
	void *info;
{
	__bam_repl_args *argp;
	DB *file_dbp;
	DBC *dbc;
	DB_MPOOLFILE *mpf;
	DB_THREAD_INFO *ip;
	PAGE *pagep;
	int cmp_n, cmp_p, modified, ret;

	ip = ((DB_TXNHEAD *)info)->thread_info;

	REC_PRINT(__bam_repl_print);
	REC_INTRO(__bam_repl_read, ip, 0);

	if ((ret = mpf->get(mpf, &argp->pgno, 0, &pagep)) != 0)
		if (DB_REDO(op)) {
			if ((ret = mpf->get(mpf,
			    &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
				goto out;
		} else {
			*lsnp = argp->prev_lsn;
			ret = 0;
			goto out;
		}

	modified = 0;
	cmp_n = log_compare(lsnp, &LSN(pagep));

	/*
	 * Use this when there is something like "pagelsn" in the argp
	 * structure.  Sometimes, you might need to compare meta-data
	 * lsn's instead.
	 *
	 * cmp_p = log_compare(&LSN(pagep), argp->pagelsn);
	 */
	if (cmp_p == 0 && DB_REDO(op)) {
		/* Need to redo update described. */
		modified = 1;
	} else if (cmp_n == 0 && !DB_REDO(op)) {
		/* Need to undo update described. */
		modified = 1;
	}
	if (ret = mpf->put(mpf, pagep, modified ? DB_MPOOL_DIRTY : 0))
		goto out;

	*lsnp = argp->prev_lsn;
	ret = 0;

out:	REC_CLOSE;
}

/*
 * __bam_root_recover --
 *	Recovery function for root.
 *
 * PUBLIC: int __bam_root_recover
 * PUBLIC:   __P((env *, DBT *, DB_LSN *, db_recops, void *));
 */
int
__bam_root_recover(env, dbtp, lsnp, op, info)
	env *env;
	DBT *dbtp;
	DB_LSN *lsnp;
	db_recops op;
	void *info;
{
	__bam_root_args *argp;
	DB *file_dbp;
	DBC *dbc;
	DB_MPOOLFILE *mpf;
	DB_THREAD_INFO *ip;
	PAGE *pagep;
	int cmp_n, cmp_p, modified, ret;

	ip = ((DB_TXNHEAD *)info)->thread_info;

	REC_PRINT(__bam_root_print);
	REC_INTRO(__bam_root_read, ip, 0);

	if ((ret = mpf->get(mpf, &argp->pgno, 0, &pagep)) != 0)
		if (DB_REDO(op)) {
			if ((ret = mpf->get(mpf,
			    &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
				goto out;
		} else {
			*lsnp = argp->prev_lsn;
			ret = 0;
			goto out;
		}

	modified = 0;
	cmp_n = log_compare(lsnp, &LSN(pagep));

	/*
	 * Use this when there is something like "pagelsn" in the argp
	 * structure.  Sometimes, you might need to compare meta-data
	 * lsn's instead.
	 *
	 * cmp_p = log_compare(&LSN(pagep), argp->pagelsn);
	 */
	if (cmp_p == 0 && DB_REDO(op)) {
		/* Need to redo update described. */
		modified = 1;
	} else if (cmp_n == 0 && !DB_REDO(op)) {
		/* Need to undo update described. */
		modified = 1;
	}
	if (ret = mpf->put(mpf, pagep, modified ? DB_MPOOL_DIRTY : 0))
		goto out;

	*lsnp = argp->prev_lsn;
	ret = 0;

out:	REC_CLOSE;
}

/*
 * __bam_curadj_recover --
 *	Recovery function for curadj.
 *
 * PUBLIC: int __bam_curadj_recover
 * PUBLIC:   __P((env *, DBT *, DB_LSN *, db_recops, void *));
 */
int
__bam_curadj_recover(env, dbtp, lsnp, op, info)
	env *env;
	DBT *dbtp;
	DB_LSN *lsnp;
	db_recops op;
	void *info;
{
	__bam_curadj_args *argp;
	DB *file_dbp;
	DBC *dbc;
	DB_MPOOLFILE *mpf;
	DB_THREAD_INFO *ip;
	PAGE *pagep;
	int cmp_n, cmp_p, modified, ret;

	ip = ((DB_TXNHEAD *)info)->thread_info;

	REC_PRINT(__bam_curadj_print);
	REC_INTRO(__bam_curadj_read, ip, 0);

	if ((ret = mpf->get(mpf, &argp->pgno, 0, &pagep)) != 0)
		if (DB_REDO(op)) {
			if ((ret = mpf->get(mpf,
			    &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
				goto out;
		} else {
			*lsnp = argp->prev_lsn;
			ret = 0;
			goto out;
		}

	modified = 0;
	cmp_n = log_compare(lsnp, &LSN(pagep));

	/*
	 * Use this when there is something like "pagelsn" in the argp
	 * structure.  Sometimes, you might need to compare meta-data
	 * lsn's instead.
	 *
	 * cmp_p = log_compare(&LSN(pagep), argp->pagelsn);
	 */
	if (cmp_p == 0 && DB_REDO(op)) {
		/* Need to redo update described. */
		modified = 1;
	} else if (cmp_n == 0 && !DB_REDO(op)) {
		/* Need to undo update described. */
		modified = 1;
	}
	if (ret = mpf->put(mpf, pagep, modified ? DB_MPOOL_DIRTY : 0))
		goto out;

	*lsnp = argp->prev_lsn;
	ret = 0;

out:	REC_CLOSE;
}

/*
 * __bam_rcuradj_recover --
 *	Recovery function for rcuradj.
 *
 * PUBLIC: int __bam_rcuradj_recover
 * PUBLIC:   __P((env *, DBT *, DB_LSN *, db_recops, void *));
 */
int
__bam_rcuradj_recover(env, dbtp, lsnp, op, info)
	env *env;
	DBT *dbtp;
	DB_LSN *lsnp;
	db_recops op;
	void *info;
{
	__bam_rcuradj_args *argp;
	DB *file_dbp;
	DBC *dbc;
	DB_MPOOLFILE *mpf;
	DB_THREAD_INFO *ip;
	PAGE *pagep;
	int cmp_n, cmp_p, modified, ret;

	ip = ((DB_TXNHEAD *)info)->thread_info;

	REC_PRINT(__bam_rcuradj_print);
	REC_INTRO(__bam_rcuradj_read, ip, 0);

	if ((ret = mpf->get(mpf, &argp->pgno, 0, &pagep)) != 0)
		if (DB_REDO(op)) {
			if ((ret = mpf->get(mpf,
			    &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
				goto out;
		} else {
			*lsnp = argp->prev_lsn;
			ret = 0;
			goto out;
		}

	modified = 0;
	cmp_n = log_compare(lsnp, &LSN(pagep));

	/*
	 * Use this when there is something like "pagelsn" in the argp
	 * structure.  Sometimes, you might need to compare meta-data
	 * lsn's instead.
	 *
	 * cmp_p = log_compare(&LSN(pagep), argp->pagelsn);
	 */
	if (cmp_p == 0 && DB_REDO(op)) {
		/* Need to redo update described. */
		modified = 1;
	} else if (cmp_n == 0 && !DB_REDO(op)) {
		/* Need to undo update described. */
		modified = 1;
	}
	if (ret = mpf->put(mpf, pagep, modified ? DB_MPOOL_DIRTY : 0))
		goto out;

	*lsnp = argp->prev_lsn;
	ret = 0;

out:	REC_CLOSE;
}

/*
 * __bam_relink_recover --
 *	Recovery function for relink.
 *
 * PUBLIC: int __bam_relink_recover
 * PUBLIC:   __P((env *, DBT *, DB_LSN *, db_recops, void *));
 */
int
__bam_relink_recover(env, dbtp, lsnp, op, info)
	env *env;
	DBT *dbtp;
	DB_LSN *lsnp;
	db_recops op;
	void *info;
{
	__bam_relink_args *argp;
	DB *file_dbp;
	DBC *dbc;
	DB_MPOOLFILE *mpf;
	DB_THREAD_INFO *ip;
	PAGE *pagep;
	int cmp_n, cmp_p, modified, ret;

	ip = ((DB_TXNHEAD *)info)->thread_info;

	REC_PRINT(__bam_relink_print);
	REC_INTRO(__bam_relink_read, ip, 0);

	if ((ret = mpf->get(mpf, &argp->pgno, 0, &pagep)) != 0)
		if (DB_REDO(op)) {
			if ((ret = mpf->get(mpf,
			    &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
				goto out;
		} else {
			*lsnp = argp->prev_lsn;
			ret = 0;
			goto out;
		}

	modified = 0;
	cmp_n = log_compare(lsnp, &LSN(pagep));

	/*
	 * Use this when there is something like "pagelsn" in the argp
	 * structure.  Sometimes, you might need to compare meta-data
	 * lsn's instead.
	 *
	 * cmp_p = log_compare(&LSN(pagep), argp->pagelsn);
	 */
	if (cmp_p == 0 && DB_REDO(op)) {
		/* Need to redo update described. */
		modified = 1;
	} else if (cmp_n == 0 && !DB_REDO(op)) {
		/* Need to undo update described. */
		modified = 1;
	}
	if (ret = mpf->put(mpf, pagep, modified ? DB_MPOOL_DIRTY : 0))
		goto out;

	*lsnp = argp->prev_lsn;
	ret = 0;

out:	REC_CLOSE;
}

/*
 * __bam_relink_recover --
 *	Recovery function for relink.
 *
 * PUBLIC: int __bam_relink_recover
 * PUBLIC:   __P((env *, DBT *, DB_LSN *, db_recops, void *));
 */
int
__bam_relink_recover(env, dbtp, lsnp, op, info)
	env *env;
	DBT *dbtp;
	DB_LSN *lsnp;
	db_recops op;
	void *info;
{
	__bam_relink_args *argp;
	DB *file_dbp;
	DBC *dbc;
	DB_MPOOLFILE *mpf;
	DB_THREAD_INFO *ip;
	PAGE *pagep;
	int cmp_n, cmp_p, modified, ret;

	ip = ((DB_TXNHEAD *)info)->thread_info;

	REC_PRINT(__bam_relink_print);
	REC_INTRO(__bam_relink_read, ip, 0);

	if ((ret = mpf->get(mpf, &argp->pgno, 0, &pagep)) != 0)
		if (DB_REDO(op)) {
			if ((ret = mpf->get(mpf,
			    &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
				goto out;
		} else {
			*lsnp = argp->prev_lsn;
			ret = 0;
			goto out;
		}

	modified = 0;
	cmp_n = log_compare(lsnp, &LSN(pagep));

	/*
	 * Use this when there is something like "pagelsn" in the argp
	 * structure.  Sometimes, you might need to compare meta-data
	 * lsn's instead.
	 *
	 * cmp_p = log_compare(&LSN(pagep), argp->pagelsn);
	 */
	if (cmp_p == 0 && DB_REDO(op)) {
		/* Need to redo update described. */
		modified = 1;
	} else if (cmp_n == 0 && !DB_REDO(op)) {
		/* Need to undo update described. */
		modified = 1;
	}
	if (ret = mpf->put(mpf, pagep, modified ? DB_MPOOL_DIRTY : 0))
		goto out;

	*lsnp = argp->prev_lsn;
	ret = 0;

out:	REC_CLOSE;
}

/*
 * __bam_merge_recover --
 *	Recovery function for merge.
 *
 * PUBLIC: int __bam_merge_recover
 * PUBLIC:   __P((env *, DBT *, DB_LSN *, db_recops, void *));
 */
int
__bam_merge_recover(env, dbtp, lsnp, op, info)
	env *env;
	DBT *dbtp;
	DB_LSN *lsnp;
	db_recops op;
	void *info;
{
	__bam_merge_args *argp;
	DB *file_dbp;
	DBC *dbc;
	DB_MPOOLFILE *mpf;
	DB_THREAD_INFO *ip;
	PAGE *pagep;
	int cmp_n, cmp_p, modified, ret;

	ip = ((DB_TXNHEAD *)info)->thread_info;

	REC_PRINT(__bam_merge_print);
	REC_INTRO(__bam_merge_read, ip, 0);

	if ((ret = mpf->get(mpf, &argp->pgno, 0, &pagep)) != 0)
		if (DB_REDO(op)) {
			if ((ret = mpf->get(mpf,
			    &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
				goto out;
		} else {
			*lsnp = argp->prev_lsn;
			ret = 0;
			goto out;
		}

	modified = 0;
	cmp_n = log_compare(lsnp, &LSN(pagep));

	/*
	 * Use this when there is something like "pagelsn" in the argp
	 * structure.  Sometimes, you might need to compare meta-data
	 * lsn's instead.
	 *
	 * cmp_p = log_compare(&LSN(pagep), argp->pagelsn);
	 */
	if (cmp_p == 0 && DB_REDO(op)) {
		/* Need to redo update described. */
		modified = 1;
	} else if (cmp_n == 0 && !DB_REDO(op)) {
		/* Need to undo update described. */
		modified = 1;
	}
	if (ret = mpf->put(mpf, pagep, modified ? DB_MPOOL_DIRTY : 0))
		goto out;

	*lsnp = argp->prev_lsn;
	ret = 0;

out:	REC_CLOSE;
}

/*
 * __bam_merge_recover --
 *	Recovery function for merge.
 *
 * PUBLIC: int __bam_merge_recover
 * PUBLIC:   __P((env *, DBT *, DB_LSN *, db_recops, void *));
 */
int
__bam_merge_recover(env, dbtp, lsnp, op, info)
	env *env;
	DBT *dbtp;
	DB_LSN *lsnp;
	db_recops op;
	void *info;
{
	__bam_merge_args *argp;
	DB *file_dbp;
	DBC *dbc;
	DB_MPOOLFILE *mpf;
	DB_THREAD_INFO *ip;
	PAGE *pagep;
	int cmp_n, cmp_p, modified, ret;

	ip = ((DB_TXNHEAD *)info)->thread_info;

	REC_PRINT(__bam_merge_print);
	REC_INTRO(__bam_merge_read, ip, 0);

	if ((ret = mpf->get(mpf, &argp->pgno, 0, &pagep)) != 0)
		if (DB_REDO(op)) {
			if ((ret = mpf->get(mpf,
			    &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
				goto out;
		} else {
			*lsnp = argp->prev_lsn;
			ret = 0;
			goto out;
		}

	modified = 0;
	cmp_n = log_compare(lsnp, &LSN(pagep));

	/*
	 * Use this when there is something like "pagelsn" in the argp
	 * structure.  Sometimes, you might need to compare meta-data
	 * lsn's instead.
	 *
	 * cmp_p = log_compare(&LSN(pagep), argp->pagelsn);
	 */
	if (cmp_p == 0 && DB_REDO(op)) {
		/* Need to redo update described. */
		modified = 1;
	} else if (cmp_n == 0 && !DB_REDO(op)) {
		/* Need to undo update described. */
		modified = 1;
	}
	if (ret = mpf->put(mpf, pagep, modified ? DB_MPOOL_DIRTY : 0))
		goto out;

	*lsnp = argp->prev_lsn;
	ret = 0;

out:	REC_CLOSE;
}

/*
 * __bam_pgno_recover --
 *	Recovery function for pgno.
 *
 * PUBLIC: int __bam_pgno_recover
 * PUBLIC:   __P((env *, DBT *, DB_LSN *, db_recops, void *));
 */
int
__bam_pgno_recover(env, dbtp, lsnp, op, info)
	env *env;
	DBT *dbtp;
	DB_LSN *lsnp;
	db_recops op;
	void *info;
{
	__bam_pgno_args *argp;
	DB *file_dbp;
	DBC *dbc;
	DB_MPOOLFILE *mpf;
	DB_THREAD_INFO *ip;
	PAGE *pagep;
	int cmp_n, cmp_p, modified, ret;

	ip = ((DB_TXNHEAD *)info)->thread_info;

	REC_PRINT(__bam_pgno_print);
	REC_INTRO(__bam_pgno_read, ip, 0);

	if ((ret = mpf->get(mpf, &argp->pgno, 0, &pagep)) != 0)
		if (DB_REDO(op)) {
			if ((ret = mpf->get(mpf,
			    &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
				goto out;
		} else {
			*lsnp = argp->prev_lsn;
			ret = 0;
			goto out;
		}

	modified = 0;
	cmp_n = log_compare(lsnp, &LSN(pagep));

	/*
	 * Use this when there is something like "pagelsn" in the argp
	 * structure.  Sometimes, you might need to compare meta-data
	 * lsn's instead.
	 *
	 * cmp_p = log_compare(&LSN(pagep), argp->pagelsn);
	 */
	if (cmp_p == 0 && DB_REDO(op)) {
		/* Need to redo update described. */
		modified = 1;
	} else if (cmp_n == 0 && !DB_REDO(op)) {
		/* Need to undo update described. */
		modified = 1;
	}
	if (ret = mpf->put(mpf, pagep, modified ? DB_MPOOL_DIRTY : 0))
		goto out;

	*lsnp = argp->prev_lsn;
	ret = 0;

out:	REC_CLOSE;
}

