fc.close();
String currentTxLog = txLogDir + separator
+ UTF8.decode( fileName ).trim();
if ( !new File( currentTxLog ).exists() )
{
throw new TransactionFailureException(
"Unable to start TM, " + "active tx log file[" +
currentTxLog + "] not found." );
}
txLog = new TxLog( currentTxLog );
msgLog.logMessage( "TM opening log: " + currentTxLog, true );
}
else
{
if ( new File( txLogDir + separator + txLog1FileName ).exists()
|| new File( txLogDir + separator + txLog2FileName )
.exists() )
{
throw new TransactionFailureException(
"Unable to start TM, "
+ "no active tx log file found but found either "
+ txLog1FileName + " or " + txLog2FileName
+ " file, please set one of them as active or "
+ "remove them." );
}
ByteBuffer buf = ByteBuffer.wrap( txLog1FileName
.getBytes( "UTF-8" ) );
FileChannel fc = new RandomAccessFile( logSwitcherFileName,
"rw" ).getChannel();
fc.write( buf );
txLog = new TxLog( txLogDir + separator + txLog1FileName );
msgLog.logMessage( "TM new log: " + txLog1FileName, true );
fc.force( true );
fc.close();
}
Iterator<List<TxLog.Record>> danglingRecordList =
txLog.getDanglingRecords();
if ( danglingRecordList.hasNext() )
{
log.info( "Unresolved transactions found, " +
"recovery started ..." );
recover( danglingRecordList );
log.info( "Recovery completed, all transactions have been " +
"resolved to a consistent state." );
msgLog.logMessage( "Recovery completed, all transactions have been " +
"resolved to a consistent state." );
}
getTxLog().truncate();
tmOk = true;
}
catch ( IOException e )
{
log.severe( "Unable to start TM" );
throw new TransactionFailureException( "Unable to start TM", e );
}
}