December 2023
Intermediate to advanced
464 pages
12h 35m
English
Split log into multiple smaller files instead of a single large file for easier operations.
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.
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(); ...