Skip to Main Content
Patterns of Distributed Systems
book

Patterns of Distributed Systems

by Unmesh Joshi
December 2023
Intermediate to advanced content levelIntermediate to advanced
464 pages
12h 35m
English
Addison-Wesley Professional
Content preview from Patterns of Distributed Systems

Chapter 4

Segmented Log

Split log into multiple smaller files instead of a single large file for easier operations.

Problem

A single log file can grow and become a performance bottleneck as it is read at startup. Older logs are cleaned up periodically, but doing cleanup operations on a single huge file is difficult to implement.

Solution

Single log is split into multiple segments. Log files are rolled after a specified size limit.

class WriteAheadLog...

  public Long writeEntry(WALEntry entry) {
      maybeRoll();
      return openSegment.writeEntry(entry);
  }

  private void maybeRoll() { if (openSegment. size() >= config.getMaxLogSize()) { openSegment.flush(); sortedSavedSegments.add(openSegment); long lastId = openSegment.getLastLogEntryIndex(); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Designing Distributed Systems

Designing Distributed Systems

Brendan Burns