Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAFKA-8306: Initialize log end offset accurately when start offset is non-zero #6652

Merged
merged 6 commits into from May 4, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions core/src/main/scala/kafka/log/Log.scala
Expand Up @@ -573,13 +573,13 @@ class Log(@volatile var dir: File,
if (logSegments.isEmpty) {
// no existing segments, create a new mutable segment beginning at offset 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the comment needs to be updated.

addSegment(LogSegment.open(dir = dir,
baseOffset = 0,
baseOffset = logStartOffset,
config,
time = time,
fileAlreadyExists = false,
initFileSize = this.initFileSize,
preallocate = config.preallocate))
0
logStartOffset
} else if (!dir.getAbsolutePath.endsWith(Log.DeleteDirSuffix)) {
val nextOffset = retryOnOffsetOverflow {
recoverLog()
Expand All @@ -588,7 +588,9 @@ class Log(@volatile var dir: File,
// reset the index size of the currently active log segment to allow more entries
activeSegment.resizeIndexes(config.maxIndexSize)
nextOffset
hachikuji marked this conversation as resolved.
Show resolved Hide resolved
} else 0
} else {
0
}
}

private def updateLogEndOffset(messageOffset: Long) {
Expand Down
9 changes: 9 additions & 0 deletions core/src/test/scala/unit/kafka/log/LogTest.scala
Expand Up @@ -278,6 +278,15 @@ class LogTest {
testProducerSnapshotsRecoveryAfterUncleanShutdown(ApiVersion.latestVersion.version)
}

@Test
def logReinitializeAfterManualDelete(): Unit = {
val logConfig = LogTest.createLogConfig()
// simulate a case where log data does not exist but the start offset is non-zero
val log = createLog(logDir, logConfig, logStartOffset = 500)
assertEquals(500, log.logStartOffset)
assertEquals(500, log.logEndOffset)
}

private def testProducerSnapshotsRecoveryAfterUncleanShutdown(messageFormatVersion: String): Unit = {
val logConfig = LogTest.createLogConfig(segmentBytes = 64 * 10, messageFormatVersion = messageFormatVersion)
var log = createLog(logDir, logConfig)
Expand Down