use of org.exist.storage.txn.TxnStart in project exist by eXist-db.
the class Journal method writeToLog.
/**
* Write a log entry to the journal.
*
* @param entry the journal entry to write
* @throws JournalException if the entry could not be written
*/
public synchronized void writeToLog(final Loggable entry) throws JournalException {
if (currentBuffer == null) {
throw new JournalException("Database is shut down.");
}
SanityCheck.ASSERT(!inRecovery, "Write to log during recovery. Should not happen!");
final int size = entry.getLogSize();
if (size > Short.MAX_VALUE) {
throw new JournalException("Journal can only write log entries of less that 32KB");
}
final int required = size + LOG_ENTRY_BASE_LEN;
if (required > currentBuffer.remaining()) {
flushToLog(false);
}
try {
// TODO(AR) this is needed as the journal is initialised by starting a transaction for loading the SymbolTable... before recovery! which is likely wrong!!! as Recovery Cannot run if the Journal file has been switched!
final long pos = channel != null ? channel.position() : 0;
currentLsn = new Lsn(currentJournalFileNumber, pos + currentBuffer.position() + 1);
} catch (final IOException e) {
throw new JournalException("Unable to create LSN for: " + entry.dump());
}
entry.setLsn(currentLsn);
try {
final int currentBufferEntryOffset = currentBuffer.position();
// write entryHeader
currentBuffer.put(entry.getLogType());
currentBuffer.putLong(entry.getTransactionId());
currentBuffer.putShort((short) size);
// write entry data
entry.write(currentBuffer);
// write backlink
currentBuffer.putShort((short) (size + LOG_ENTRY_HEADER_LEN));
// write checksum
final long checksum = xxHash64.hash(currentBuffer, currentBufferEntryOffset, currentBuffer.position() - currentBufferEntryOffset, XXHASH64_SEED);
currentBuffer.putLong(checksum);
} catch (final BufferOverflowException e) {
throw new JournalException("Buffer overflow while writing log record: " + entry.dump(), e);
}
// NOTE: we don't track operations on txnStart or checkpoints!
if (!(entry instanceof TxnStart || entry instanceof Checkpoint)) {
pool.getTransactionManager().trackOperation(entry.getTransactionId());
}
}
Aggregations