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-6569: Move OffsetIndex/TimeIndex logger to companion object #4586

Merged
merged 3 commits into from Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 8 additions & 3 deletions core/src/main/scala/kafka/log/AbstractIndex.scala
Expand Up @@ -39,7 +39,8 @@ import scala.math.ceil
* @param maxIndexSize The maximum index size in bytes.
*/
abstract class AbstractIndex[K, V](@volatile var file: File, val baseOffset: Long,
val maxIndexSize: Int = -1, val writable: Boolean) extends Closeable with Logging {
val maxIndexSize: Int = -1, val writable: Boolean) extends Closeable {
import AbstractIndex._

// Length of the index file
@volatile
Expand Down Expand Up @@ -135,7 +136,7 @@ abstract class AbstractIndex[K, V](@volatile var file: File, val baseOffset: Lon
idx.position(roundDownToExactMultiple(idx.limit(), entrySize))
idx
} finally {
CoreUtils.swallow(raf.close(), this)
CoreUtils.swallow(raf.close(), AbstractIndex)
}
}

Expand Down Expand Up @@ -190,7 +191,7 @@ abstract class AbstractIndex[K, V](@volatile var file: File, val baseOffset: Lon
mmap.position(position)
true
} finally {
CoreUtils.swallow(raf.close(), this)
CoreUtils.swallow(raf.close(), AbstractIndex)
}
}
}
Expand Down Expand Up @@ -422,6 +423,10 @@ abstract class AbstractIndex[K, V](@volatile var file: File, val baseOffset: Lon

}

object AbstractIndex extends Logging {
override val loggerName: String = classOf[AbstractIndex[_, _]].getName
}

object IndexSearchType extends Enumeration {
type IndexSearchEntity = Value
val KEY, VALUE = Value
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/scala/kafka/log/OffsetIndex.scala
Expand Up @@ -21,6 +21,7 @@ import java.io.File
import java.nio.ByteBuffer

import kafka.utils.CoreUtils.inLock
import kafka.utils.Logging
import org.apache.kafka.common.errors.InvalidOffsetException

/**
Expand Down Expand Up @@ -51,6 +52,7 @@ import org.apache.kafka.common.errors.InvalidOffsetException
// Avoid shadowing mutable `file` in AbstractIndex
class OffsetIndex(_file: File, baseOffset: Long, maxIndexSize: Int = -1, writable: Boolean = true)
extends AbstractIndex[Long, Int](_file, baseOffset, maxIndexSize, writable) {
import OffsetIndex._

override def entrySize = 8

Expand Down Expand Up @@ -197,3 +199,7 @@ class OffsetIndex(_file: File, baseOffset: Long, maxIndexSize: Int = -1, writabl
}

}

object OffsetIndex extends Logging {
override val loggerName: String = classOf[OffsetIndex].getName
}
9 changes: 7 additions & 2 deletions core/src/main/scala/kafka/log/TimeIndex.scala
Expand Up @@ -20,7 +20,7 @@ package kafka.log
import java.io.File
import java.nio.ByteBuffer

import kafka.utils.CoreUtils._
import kafka.utils.CoreUtils.inLock
import kafka.utils.Logging
import org.apache.kafka.common.errors.InvalidOffsetException
import org.apache.kafka.common.record.RecordBatch
Expand Down Expand Up @@ -51,7 +51,8 @@ import org.apache.kafka.common.record.RecordBatch
*/
// Avoid shadowing mutable file in AbstractIndex
class TimeIndex(_file: File, baseOffset: Long, maxIndexSize: Int = -1, writable: Boolean = true)
extends AbstractIndex[Long, Long](_file, baseOffset, maxIndexSize, writable) with Logging {
extends AbstractIndex[Long, Long](_file, baseOffset, maxIndexSize, writable) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This class also should provide the Logger, Right?

Copy link
Contributor

Choose a reason for hiding this comment

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

There are no log statements in this class.

Copy link
Contributor

@omkreddy omkreddy Feb 18, 2019

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch! CoreUtils was exposing its logger, so I fixed both in a new commit.

import TimeIndex._

@volatile private var _lastEntry = lastEntryFromIndexFile

Expand Down Expand Up @@ -220,3 +221,7 @@ class TimeIndex(_file: File, baseOffset: Long, maxIndexSize: Int = -1, writable:
s"which is neither positive nor a multiple of $entrySize.")
}
}

object TimeIndex extends Logging {
override val loggerName: String = classOf[TimeIndex].getName
}
6 changes: 4 additions & 2 deletions core/src/main/scala/kafka/utils/CoreUtils.scala
Expand Up @@ -24,6 +24,7 @@ import java.util.concurrent.locks.{Lock, ReadWriteLock}
import java.lang.management._
import java.util.{Base64, Properties, UUID}

import com.typesafe.scalalogging.Logger
import javax.management._

import scala.collection._
Expand All @@ -45,7 +46,8 @@ import org.slf4j.event.Level
* 2. It is the most general possible utility, not just the thing you needed in one particular place
* 3. You have tests for it if it is nontrivial in any way
*/
object CoreUtils extends Logging {
object CoreUtils {
private val logger = Logger(getClass)

/**
* Return the smallest element in `traversable` if it is not empty. Otherwise return `ifEmpty`.
Expand Down Expand Up @@ -147,7 +149,7 @@ object CoreUtils extends Logging {
}
} catch {
case e: Exception => {
error(s"Failed to register Mbean $name", e)
logger.error(s"Failed to register Mbean $name", e)
false
}
}
Expand Down