Class

kafka.log

OffsetIndex

Related Doc: package log

Permalink

class OffsetIndex extends Logging

An index that maps offsets to physical file locations for a particular log segment. This index may be sparse: that is it may not hold an entry for all messages in the log.

The index is stored in a file that is pre-allocated to hold a fixed maximum number of 8-byte entries.

The index supports lookups against a memory-map of this file. These lookups are done using a simple binary search variant to locate the offset/location pair for the greatest offset less than or equal to the target offset.

Index files can be opened in two ways: either as an empty, mutable index that allows appends or an immutable read-only index file that has previously been populated. The makeReadOnly method will turn a mutable file into an immutable one and truncate off any extra bytes. This is done when the index file is rolled over.

No attempt is made to checksum the contents of this file, in the event of a crash it is rebuilt.

The file format is a series of entries. The physical format is a 4 byte "relative" offset and a 4 byte file location for the message with that offset. The offset stored is relative to the base offset of the index file. So, for example, if the base offset was 50, then the offset 55 would be stored as 5. Using relative offsets in this way let's us use only 4 bytes for the offset.

The frequency of entries is up to the user of this class.

All external APIs translate from relative offsets to full offsets, so users of this class do not interact with the internal storage format.

Linear Supertypes
Logging, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. OffsetIndex
  2. Logging
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Instance Constructors

  1. new OffsetIndex(file: File, baseOffset: Long, maxIndexSize: Int = 1)

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def append(offset: Long, position: Int): Unit

    Permalink

    Append an entry for the given offset/location pair to the index.

    Append an entry for the given offset/location pair to the index. This entry must have a larger offset than all subsequent entries.

  5. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  6. val baseOffset: Long

    Permalink
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. def close(): Unit

    Permalink

    Close the index

  9. def debug(msg: ⇒ String, e: ⇒ Throwable): Unit

    Permalink
    Definition Classes
    Logging
  10. def debug(e: ⇒ Throwable): Any

    Permalink
    Definition Classes
    Logging
  11. def debug(msg: ⇒ String): Unit

    Permalink
    Definition Classes
    Logging
  12. def delete(): Boolean

    Permalink

    Delete this index file

  13. def entries(): Int

    Permalink

    The number of entries in this index

  14. def entry(n: Int): OffsetPosition

    Permalink

    Get the nth offset mapping from the index

    Get the nth offset mapping from the index

    n

    The entry number in the index

    returns

    The offset/position pair at that entry

  15. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  16. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  17. def error(msg: ⇒ String, e: ⇒ Throwable): Unit

    Permalink
    Definition Classes
    Logging
  18. def error(e: ⇒ Throwable): Any

    Permalink
    Definition Classes
    Logging
  19. def error(msg: ⇒ String): Unit

    Permalink
    Definition Classes
    Logging
  20. def fatal(msg: ⇒ String, e: ⇒ Throwable): Unit

    Permalink
    Definition Classes
    Logging
  21. def fatal(e: ⇒ Throwable): Any

    Permalink
    Definition Classes
    Logging
  22. def fatal(msg: ⇒ String): Unit

    Permalink
    Definition Classes
    Logging
  23. var file: File

    Permalink
  24. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  25. def flush(): Unit

    Permalink

    Flush the data in the index to disk

  26. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  27. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  28. def info(msg: ⇒ String, e: ⇒ Throwable): Unit

    Permalink
    Definition Classes
    Logging
  29. def info(e: ⇒ Throwable): Any

    Permalink
    Definition Classes
    Logging
  30. def info(msg: ⇒ String): Unit

    Permalink
    Definition Classes
    Logging
  31. def isFull: Boolean

    Permalink

    True iff there are no more slots available in this index

  32. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  33. var lastOffset: Long

    Permalink
  34. var logIdent: String

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  35. lazy val logger: Logger

    Permalink
    Definition Classes
    Logging
  36. val loggerName: String

    Permalink
    Definition Classes
    Logging
  37. def lookup(targetOffset: Long): OffsetPosition

    Permalink

    Find the largest offset less than or equal to the given targetOffset and return a pair holding this offset and its corresponding physical file position.

    Find the largest offset less than or equal to the given targetOffset and return a pair holding this offset and its corresponding physical file position.

    targetOffset

    The offset to look up.

    returns

    The offset found and the corresponding file position for this offset. If the target offset is smaller than the least entry in the index (or the index is empty), the pair (baseOffset, 0) is returned.

  38. var maxEntries: Int

    Permalink

    The maximum number of eight-byte entries this index can hold

  39. val maxIndexSize: Int

    Permalink
  40. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  41. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  42. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  43. def readLastEntry(): OffsetPosition

    Permalink

    The last entry in the index

  44. def renameTo(f: File): Boolean

    Permalink

    Rename the file that backs this offset index

    Rename the file that backs this offset index

    returns

    true iff the rename was successful

  45. def resize(newSize: Int): Unit

    Permalink

    Reset the size of the memory map and the underneath file.

    Reset the size of the memory map and the underneath file. This is used in two kinds of cases: (1) in trimToValidSize() which is called at closing the segment or new segment being rolled; (2) at loading segments from disk or truncating back to an old segment where a new log segment became active; we want to reset the index size to maximum index size to avoid rolling new segment.

  46. def sanityCheck(): Unit

    Permalink

    Do a basic sanity check on this index to detect obvious problems

    Do a basic sanity check on this index to detect obvious problems

    Exceptions thrown

    IllegalArgumentException if any problems are found

  47. def sizeInBytes(): Int

    Permalink

    The number of bytes actually used by this index

  48. def swallow(action: ⇒ Unit): Unit

    Permalink
    Definition Classes
    Logging
  49. def swallowDebug(action: ⇒ Unit): Unit

    Permalink
    Definition Classes
    Logging
  50. def swallowError(action: ⇒ Unit): Unit

    Permalink
    Definition Classes
    Logging
  51. def swallowInfo(action: ⇒ Unit): Unit

    Permalink
    Definition Classes
    Logging
  52. def swallowTrace(action: ⇒ Unit): Unit

    Permalink
    Definition Classes
    Logging
  53. def swallowWarn(action: ⇒ Unit): Unit

    Permalink
    Definition Classes
    Logging
  54. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  55. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  56. def trace(msg: ⇒ String, e: ⇒ Throwable): Unit

    Permalink
    Definition Classes
    Logging
  57. def trace(e: ⇒ Throwable): Any

    Permalink
    Definition Classes
    Logging
  58. def trace(msg: ⇒ String): Unit

    Permalink
    Definition Classes
    Logging
  59. def trimToValidSize(): Unit

    Permalink

    Trim this segment to fit just the valid entries, deleting all trailing unwritten bytes from the file.

  60. def truncate(): Unit

    Permalink

    Truncate the entire index, deleting all entries

  61. def truncateTo(offset: Long): Unit

    Permalink

    Remove all entries from the index which have an offset greater than or equal to the given offset.

    Remove all entries from the index which have an offset greater than or equal to the given offset. Truncating to an offset larger than the largest in the index has no effect.

  62. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  63. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  64. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  65. def warn(msg: ⇒ String, e: ⇒ Throwable): Unit

    Permalink
    Definition Classes
    Logging
  66. def warn(e: ⇒ Throwable): Any

    Permalink
    Definition Classes
    Logging
  67. def warn(msg: ⇒ String): Unit

    Permalink
    Definition Classes
    Logging

Inherited from Logging

Inherited from AnyRef

Inherited from Any

Ungrouped