Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions core/src/main/scala/kafka/log/LogCleaner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,11 @@ class LogCleaner(val config: CleanerConfig,
* cleaner has processed up to the given offset on the specified topic/partition
*/
def awaitCleaned(topic: String, part: Int, offset: Long, timeout: Long = 30000L): Unit = {
while(!cleanerManager.allCleanerCheckpoints.contains(TopicAndPartition(topic, part)))
Thread.sleep(10)
while(true) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the timeout actually being used?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It is not used. I was going to remove this but forgot it.. Will fix it.

val cleanedOffset = cleanerManager.allCleanerCheckpoints.get(TopicAndPartition(topic, part))
if (cleanedOffset == None || cleanedOffset.get < offset) Thread.sleep(10)
else return
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The following is more idiomatic:

  while (cleanerManager.allCleanerCheckpoints.get(TopicAndPartition(topic, part)).fold(true)(_ < offset)
    Thread.sleep(10)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nice approach. I will follow your suggestion.

}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/scala/unit/kafka/admin/DeleteTopicTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class DeleteTopicTest extends ZooKeeperTestHarness {
writeDups(numKeys = 100, numDups = 3,log)

// wait for cleaner to clean
server.logManager.cleaner.awaitCleaned(topicName,0,0)
server.logManager.cleaner.awaitCleaned(topicName, 0, 0)

// delete topic
AdminUtils.deleteTopic(zkClient, "test")
Expand Down
17 changes: 12 additions & 5 deletions core/src/test/scala/unit/kafka/log/LogCleanerIntegrationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,25 @@ class LogCleanerIntegrationTest(compressionCodec: String) {
val startSize = log.size
cleaner.startup()

val lastCleaned = log.activeSegment.baseOffset
val firstDirty = log.activeSegment.baseOffset
// wait until we clean up to base_offset of active segment - minDirtyMessages
cleaner.awaitCleaned("log", 0, lastCleaned)
cleaner.awaitCleaned("log", 0, firstDirty)

val lastCleaned = cleaner.cleanerManager.allCleanerCheckpoints.get(TopicAndPartition("log", 0)).get
assertTrue("log cleaner should have processed up to offset " + firstDirty, lastCleaned >= firstDirty);

val read = readFromLog(log)
assertEquals("Contents of the map shouldn't change.", appends.toMap, read.toMap)
assertTrue(startSize > log.size)

// write some more stuff and validate again
val appends2 = appends ++ writeDups(numKeys = 100, numDups = 3, log, CompressionCodec.getCompressionCodec(compressionCodec))
val lastCleaned2 = log.activeSegment.baseOffset
cleaner.awaitCleaned("log", 0, lastCleaned2)
val firstDirty2 = log.activeSegment.baseOffset
cleaner.awaitCleaned("log", 0, firstDirty2)

val lastCleaned2 = cleaner.cleanerManager.allCleanerCheckpoints.get(TopicAndPartition("log", 0)).get
assertTrue("log cleaner should have processed up to offset " + firstDirty2, lastCleaned2 >= firstDirty2);

val read2 = readFromLog(log)
assertEquals("Contents of the map shouldn't change.", appends2.toMap, read2.toMap)

Expand All @@ -82,7 +89,6 @@ class LogCleanerIntegrationTest(compressionCodec: String) {

// we expect partition 0 to be gone
assert(!checkpoints.contains(topics(0)))

cleaner.shutdown()
}

Expand Down Expand Up @@ -111,6 +117,7 @@ class LogCleanerIntegrationTest(compressionCodec: String) {

@After
def teardown() {
time.scheduler.shutdown()
CoreUtils.rm(logDir)
}

Expand Down
1 change: 1 addition & 0 deletions core/src/test/scala/unit/kafka/utils/MockScheduler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class MockScheduler(val time: Time) extends Scheduler {

def shutdown() {
this synchronized {
tasks.foreach(_.fun())
tasks.clear()
}
}
Expand Down