currentLogFileNumber = lastGoodLogFileNumber;
if ( ( lastGoodLogFileNumber < LogAnchor.MIN_LOG_NUMBER ) ||
( lastGoodLogFileOffset < LogAnchor.MIN_LOG_OFFSET ) )
{
throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
}
scanPoint.resetLogAnchor( lastGoodLogFileNumber, lastGoodLogFileOffset,
LogAnchor.UNKNOWN_LSN );
if ( anchorComparator.compare( scanPoint, minLogAnchor ) < 0 )
{
throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
}
/*
* If invalid content at the end of file:
* if we are past the header of file, then
* truncate the file to the end of the last
* read log record, otherwise we read a partially
* written log file header, in this case reformat the log file.
* Also check next for the existence of next file to make
* sure we really read the last log file.
*/
if ( invalidLog )
{
// Check if next log file exists
reader = null;
try
{
reader = logFileManager.getReaderForLogFile( ( lastGoodLogFileNumber + 1 ) );
}
catch ( FileNotFoundException e )
{
// Fine, this is what we want
}
finally
{
if ( reader != null )
{
reader.close();
}
}
if ( reader != null )
{
throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
}
if ( lastGoodLogFileOffset >= LogFileRecords.LOG_FILE_HEADER_SIZE )
{
logFileManager.truncateLogFile( lastGoodLogFileNumber, lastGoodLogFileOffset );
}
else
{
// Reformat the existing log file
this.createNextLogFile( true );
}
}
}
{
/*
* Control file does not exist. Either we are at the very beginning or
* maybe we crashed in the middle of creating the first log file.
* We should have the min log file at most with the file header formatted.
*/
reader = null;
boolean fileExists = false;
currentLogFileNumber = LogAnchor.MIN_LOG_NUMBER;
try
{
reader = logFileManager.getReaderForLogFile( LogAnchor.MIN_LOG_NUMBER );
if ( reader.getLength() > LogFileRecords.LOG_FILE_HEADER_SIZE )
{
throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
}
fileExists = true;
}
catch ( FileNotFoundException e )
{