in cassandra-four-zero/src/main/java/org/apache/cassandra/db/commitlog/BufferingCommitLogReader.java [224:280]
private void readCommitLogSegment() throws IOException
{
long startTimeNanos = System.nanoTime();
SeekableCommitLogSegmentReader segmentReader;
try
{
segmentReader = new SeekableCommitLogSegmentReader(this, descriptor, reader, logger, false);
}
catch (Exception exception)
{
handleUnrecoverableError(new CommitLogReadException(
String.format("Unable to create segment reader for commit log file: %s", exception),
CommitLogReadErrorReason.UNRECOVERABLE_UNKNOWN_ERROR,
false));
return;
}
try
{
if (descriptor.id == highWaterMark.segmentId() && reader.getFilePointer() < highWaterMark.position())
{
segmentReader.seek(highWaterMark.position());
}
for (CommitLogSegmentReader.SyncSegment syncSegment : segmentReader)
{
// Only tolerate truncationSerializationHeader if we allow in both global and segment
// statusTracker.tolerateErrorsInSection = tolerateTruncation && syncSegment.toleratesErrorsInSection;
statusTracker.errorContext = String.format("Next section at %d in %s",
syncSegment.fileStartPosition, descriptor.fileName());
readSection(syncSegment.input, syncSegment.endPosition, descriptor);
// Track the position at end of previous section after successfully reading mutations,
// so we can update highwater mark after reading
position = (int) reader.getFilePointer();
if (!statusTracker.shouldContinue())
{
break;
}
}
}
// Unfortunately CommitLogSegmentReader.SegmentIterator (for-loop) cannot throw a checked exception,
// so we check to see if a RuntimeException is wrapping an IOException
catch (RuntimeException exception)
{
if (exception.getCause() instanceof IOException)
{
throw (IOException) exception.getCause();
}
throw exception;
}
logger.info("Finished reading commit log", "updates", updates.size(),
"timeNanos", System.nanoTime() - startTimeNanos);
}