ex_apprec_template   [plain text]


#include "db.h"

/*
 * ex_apprec_mkdir_recover --
 *	Recovery function for mkdir.
 *
 * PUBLIC: int ex_apprec_mkdir_recover
 * PUBLIC:   __P((dbenv *, DBT *, DB_LSN *, db_recops));
 */
int
ex_apprec_mkdir_recover(dbenv, dbtp, lsnp, op)
	dbenv *dbenv;
	DBT *dbtp;
	DB_LSN *lsnp;
	db_recops op;
{
	ex_apprec_mkdir_args *argp;
	int cmp_n, cmp_p, modified, ret;

#ifdef DEBUG_RECOVER
	(void)ex_apprec_mkdir_print(dbenv, dbtp, lsnp, op);
#endif
	argp = NULL;
	if ((ret = ex_apprec_mkdir_read(dbenv, dbtp->data, &argp)) != 0)
		goto out;

	modified = 0;
	cmp_n = 0;
	cmp_p = 0;

	/*
	 * The function now needs to calculate cmp_n and cmp_p based
	 * on whatever is in argp (usually an LSN representing the state
	 * of an object BEFORE the operation described in this record was
	 * applied) and whatever other information the function needs,
	 * e.g., the LSN of the object as it exists now.
	 *
	 * cmp_p should be set to 0 if the current state of the object
	 * is believed to be same as the state of the object BEFORE the
	 * described operation was applied.  For example, if you had an
	 * LSN in the log record (argp->prevlsn) and a current LSN of the
	 * object (curlsn), you might want to do:
	 *
	 * cmp_p = log_compare(curlsn, argp->prevlsn);
	 *
	 * Similarly, cmp_n should be set to 0 if the current state
	 * of the object reflects the object AFTER this operation has
	 * been applied.  Thus, if you can figure out an object's current
	 * LSN, yo might set cmp_n as:
	 *
	 * cmp_n = log_compare(lsnp, curlsn);
	 */
	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;
	}

	/* Allow for following LSN pointers through a transaction. */
	*lsnp = argp->prev_lsn;
	ret = 0;

out:	if (argp != NULL)
		free(argp);

	return (ret);
}