liveBook · Manning

Log segment

As explained in Kafka Streams in Action, Second Edition

A Kafka log segment is a file-backed portion of a partition's append-only log that contains a contiguous range of records along with its indexes.

A Kafka log segment is a discrete, file-backed portion of a topic partition. The broker appends records to the active segment, then creates a new active segment when the configured size or age limit is reached. Older segments remain available for consumers. section 2.6

Each segment works with companion indexes to support storage and reads:

  • The .log file stores records and associated fields such as offset, size, and physical position. section 2.6.3
  • The .index file maps relative offsets to physical positions, letting the broker binary-search for a read starting point. section 2.6.3
  • The .timeindex file maps timestamps to relative offsets. section 2.6.3
  • Segment filenames use the base offset, while index offsets are stored relative to that base offset. section 2.6.3

Rolling a purchases partition

A purchases-0 directory may begin with 00000000000000000000.log, .index, and .timeindex. After the active segment rolls, another group such as 00000000000000037348.log and its indexes appears. The broker can then remove an entire older segment when its records satisfy time- or size-based retention. section 2.6.3 section 2.6.1

Figure 2.6 Creating new segments
figure

Visualizes how incoming records move from the active segment into successive segments. section 2.6

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains rolling triggers, directory files, relative offsets, binary search, and segment deletion, but not segment implementation code.
Examples
Uses purchases-0 directory listings, numbered segment files, and active-segment rollover to illustrate storage.
What it assumes
Assumes topic partitions, records, offsets, and broker appends, while clarifying their relationship to physical segment files.
What you can do after
Evaluate/understand how Kafka locates records, rolls partition files, and removes segments under retention settings.
How it connects
Connects log segments with topic partitions, offsets, indexes, time indexes, consumers, and data retention.

Also explained in

Compare how 2 books explain log segment →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka Streams in Action, Second Edition. The section links point to the parts of the book it draws on.