entrySize);
}
/* Sanity check */
if (entrySize != marshalledBuffer.limit()) {
throw new DatabaseException(
"Logged item entrySize= " + entrySize +
" but marshalledSize=" + marshalledBuffer.limit() +
" type=" + entryType + " currentLsn=" +
DbLsn.getNoFormatString(currentLsn));
}
/*
* Ask for a log buffer suitable for holding this new entry. If
* the current log buffer is full, or if we flipped into a new
* file, write it to disk and get a new, empty log buffer to
* use. The returned buffer will be latched for write.
*/
ByteBuffer useBuffer =
logBufferPool.getWriteBuffer(entrySize, flippedFile);
/* Add checksum to entry. */
marshalledBuffer =
addPrevOffsetAndChecksum(marshalledBuffer,
fileManager.getPrevEntryOffset(),
entrySize);
/*
* If the LogBufferPool buffer (useBuffer) doesn't have sufficient
* space (since they're fixed size), just use the temporary buffer
* and throw it away when we're done. That way we don't grow the
* LogBuffers in the pool permanently. We risk an OOME on this
* temporary usage, but we'll risk it. [#12674]
*/
if ((useBuffer.capacity() - useBuffer.position()) < entrySize) {
fileManager.writeLogBuffer
(new LogBuffer(marshalledBuffer, currentLsn));
usedTemporaryBuffer = true;
assert useBuffer.position() == 0;
nTempBufferWrites++;
} else {
/* Copy marshalled object into write buffer. */
useBuffer.put(marshalledBuffer);
}
} catch (Exception e) {
/*
* The LSN pointer, log buffer position, and corresponding file
* position march in lockstep.
*
* 1. We bump the LSN.
* 2. We copy loggable item into the log buffer.
* 3. We may try to write the log buffer.
*
* If we've failed to put the item into the log buffer (2), we need
* to restore old LSN state so that the log buffer doesn't have a
* hole. [SR #12638] If we fail after (2), we don't need to restore
* state, because log buffers will still match file positions.
*/
fileManager.restoreLastPosition();
if (e instanceof DatabaseException) {
throw (DatabaseException) e;
} else if (e instanceof IOException){
throw (IOException) e;
} else {
throw new DatabaseException(e);
}
}
/*
* Tell the log buffer pool that we finished the write. Record the