if (!journalDirectory.exists())
{
if (!journalDirectory.mkdirs())
{
throw new JournalManagementException("err.rpc.file.journalIoErr",
new Object[] {journalDirectory.getAbsolutePath()});
}
}
m_journalFile = new File(journalDirectory, JOURNAL_FILE1_NAME);
m_compactionJournalFile = new File(journalDirectory, JOURNAL_FILE2_NAME);
m_activeJournalPointerFile = new File(journalDirectory, JOURNAL_POINTER_FILE_NAME);
m_journal = new LockableFile(m_journalFile);
m_compactionJournal = new LockableFile(m_compactionJournalFile);
boolean bReady = false;
try
{
if (!m_journal.tryLock(false))
{
throw new IllegalStateException("Journal \"" + m_journalFile.getAbsolutePath() + "\" is already locked.");
}
if (!m_compactionJournal.tryLock(false))
{
throw new IllegalStateException("Journal \"" + m_compactionJournalFile.getAbsolutePath() + "\" is already locked.");
}
boolean bSecondFileIsActive = true;
if (m_activeJournalPointerFile.exists())
{
//Read the active journal pointer.
try
{
FileInputStream activePointerStream = new FileInputStream(m_activeJournalPointerFile);
try
{
bSecondFileIsActive = activePointerStream.read() == 2;
}
finally
{
IOUtil.close(activePointerStream);
}
}
catch (IOException ex)
{
throw new JournalManagementException("err.rpc.file.journalIoErr",
new Object[] {m_activeJournalPointerFile.getAbsolutePath()}, ex);
}
}
else
{
writeActiveJournalPointer((byte)2);
}
if (bSecondFileIsActive)
{
swapJournalFiles();
}
//Check/write version code
try
{
if (m_journalFile.length() >= JOURNAL_VERSION.length)
{
InputStream istream = m_journal.getInputStream();
byte[] nVersionCodeArray = new byte[JOURNAL_VERSION.length];
istream.read(nVersionCodeArray);
if (Binary.compare(nVersionCodeArray, JOURNAL_VERSION) != 0)
{
throw new JournalManagementException("err.rpc.file.versionMismatch",
new Object[]{new Binary(JOURNAL_VERSION).toString(),
new Binary(nVersionCodeArray).toString(),
journalDirectory.getAbsolutePath()});
}
}
else
{
m_journal.writeData(new Binary(JOURNAL_VERSION));
}
}
catch (IOException ex)
{
throw new JournalManagementException("err.rpc.file.journalIoErr",
new Object[] {m_journalFile.getAbsolutePath()}, ex);
}
m_indoubtXids = recoverInternal();
m_activeXids = new HashHolder();