/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1996, 1997, 1998
* Sleepycat Software. All rights reserved.
*/
#include "config.h"
#ifndef lint
static const char copyright[] =
"@(#) Copyright (c) 1996, 1997, 1998\n\
Sleepycat Software Inc. All rights reserved.\n";
#endif
#ifndef NO_SYSTEM_INCLUDES
#include <errno.h>
#include <string.h>
#include <time.h>
#endif
#include "db_int.h"
#include "shqueue.h"
#include "db_page.h"
#include "db_dispatch.h"
#include "db_am.h"
#include "log.h"
#include "txn.h"
#include "common_ext.h"
/*
* __db_apprec --
* Perform recovery.
*
* PUBLIC: int __db_apprec __P((DB_ENV *, u_int32_t));
*/
int
{
int ret;
void *txninfo;
/* Initialize the transaction list. */
return (ret);
/*
* Save the state of the thread flag -- we don't need it on at the
* moment because we're single-threaded until recovery is complete.
*/
/*
* Recovery is done in three passes:
* Pass #0:
* We need to find the position from which we will open files
* We need to open files beginning with the last to next
* checkpoint because we might have crashed after writing the
* last checkpoint record, but before having written out all
* the open file information.
* Pass #1:
* Read forward through the log from the second to last checkpoint
* opening and closing files so that at the end of the log we have
* the "current" set of files open.
* Pass #2:
* Read backward through the log undoing any uncompleted TXNs.
* If doing catastrophic recovery, we read to the beginning of
* the log, otherwise, to the most recent checkpoint that occurs
* before the most recent checkpoint LSN, which is returned by
* __log_findckp(). During this pass, checkpoint file information
* is ignored, and file openings and closings are undone.
* Pass #3:
* Read forward through the log from the LSN found in pass #2,
* redoing any committed TXNs. During this pass, checkpoint
* file information is ignored, and file openings and closings
* are redone.
*/
/*
* Find the second to last checkpoint in the log. This is the point
* from which we want to begin pass #1 (the TXN_OPENFILES pass).
*/
/*
* If we don't find a checkpoint, start from the beginning.
* If that fails, we're done. Note, we do not require that
* there be log records if we're performing recovery.
*/
if (ret == DB_NOTFOUND)
ret = 0;
else
goto out;
}
goto out;
goto first;
else
/*
* Now, ckp_lsn is either the lsn of the last checkpoint or the lsn
* of the first record in the log. Open_lsn is the second to last
* checkpoint or the beinning of the log; begin the TXN_OPENFILES
* pass from that lsn, and proceed to the end of the log.
*/
for (;;) {
else
goto msgerr;
if (ret == DB_NOTFOUND)
break;
goto out;
}
}
/*
* Pass #2.
*
* Before we can begin pass #2, backward roll phase, we determine how
* far back in the log to recover. If we are doing catastrophic
* recovery, then we go as far back as we have files. If we are
* doing normal recovery, we go as back to the most recent checkpoint
* that occurs before the most recent checkpoint LSN.
*/
if (LF_ISSET(DB_RECOVER_FATAL)) {
} else
/*
* We don't require that log files exist if recovery
* was specified.
*/
ret = 0;
goto out;
}
if (dbenv->db_verbose)
else
if (ret != 0)
if (ret != DB_TXN_CKP)
goto msgerr;
else
ret = 0;
}
goto out;
/*
* Pass #3.
*/
else
if (ret != 0)
if (ret != DB_TXN_CKP)
goto msgerr;
else
ret = 0;
}
if (ret != DB_NOTFOUND)
goto out;
/* Now close all the db files that are open. */
/*
* Now set the last checkpoint lsn and the current time,
* take a checkpoint, and reset the txnid.
*/
goto out;
if (dbenv->db_verbose) {
"Maximum transaction id",
"Recovery checkpoint",
}
if (0) {
}
return (ret);
}