DiskLogIterator it = new DiskLogIterator(logFiles, from);
LSN nextLSN = null;
// apply log entries to databases ...
while (it.hasNext()) {
LogEntry le = null;
try {
le = it.next();
byte type = le.getPayloadType();
Logging.logMessage(Logging.LEVEL_DEBUG, this,
"Reading entry LSN(%s) of type (%d) with %d bytes payload from log.", le.getLSN()
.toString(), (int) type, le.getPayload().remaining());
// in normal there are only transactions to be replayed
if (type == PAYLOAD_TYPE_TRANSACTION) {
txnMan.replayTransaction(le);
// create, copy and delete are not replayed (this block
// is for backward
// compatibility)
} else if (type != PAYLOAD_TYPE_CREATE && type != PAYLOAD_TYPE_COPY
&& type != PAYLOAD_TYPE_DELETE) {
// get the processing logic for the dedicated logEntry
// type
InMemoryProcessing processingLogic = txnMan.getProcessingLogic().get(type);
// deserialize the arguments retrieved from the logEntry
OperationInternal operation = processingLogic.convertToOperation(processingLogic
.deserializeRequest(le.getPayload()));
// execute the in-memory logic
try {
processingLogic.process(operation);
} catch (BabuDBException be) {
// there might be false positives if a snapshot to
// delete has already been deleted, a snapshot to
// create has already been created, or an insertion
// has been applied to a database that has already
// been deleted
// FIXME: A clean solution needs to be provided that
// is capable of distinguishing between a corrupted
// database and a "false positive". False positives
// may occur because management operations are
// immediately applied to the persistent database
// state rather than being applied when the log is
// replayed.
// A clean solution would involve a single immutable
// configuration file per database/snapshot, which
// resides in the database directory and is written
// when the first checkpoint is created. When a
// database/snapshot gets deleted, an additional
// (empty) file is created that indicates the
// deletion. When old log files are removed in
// response to a checkpoint, the system disposes of
// all directories of databases and snapshots that
// were deleted in these log files.
if (!(type == PAYLOAD_TYPE_SNAP && (be.getErrorCode() == ErrorCode.SNAP_EXISTS || be
.getErrorCode() == ErrorCode.NO_SUCH_DB))
&& !(type == PAYLOAD_TYPE_SNAP_DELETE && be.getErrorCode() == ErrorCode.NO_SUCH_SNAPSHOT)
&& !(type == PAYLOAD_TYPE_INSERT && be.getErrorCode().equals(
ErrorCode.NO_SUCH_DB))) {
throw be;
}
}
}
// set LSN
nextLSN = new LSN(le.getViewId(), le.getLogSequenceNo() + 1L);
} finally {
if (le != null) {
le.free();
}
}
}