Skip to content

Commit cd44965

Browse files
committed
db: document that multiple flushableEntries may share a logNum
Document this subtlety that multiple flushable entries may share the same logNum.
1 parent 97bcce6 commit cd44965

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

flushable.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,20 @@ type flushableEntry struct {
7979
// Holds the timestamp of when the flush will be issued.
8080
delayedFlushForcedAt time.Time
8181
// logNum corresponds to the WAL that contains the records present in the
82-
// receiver.
82+
// receiver. It is possible for multiple flushable entries to have the same
83+
// logNum:
84+
// 1. When a large batch is committed, it is not appended to the WAL.
85+
// Instead, the memtable is rotated, and the large batch is appended to the
86+
// flushable queue with a logNum that matches the newly immutable memtable.
87+
// Care is taken in DB.flush1 to ensure that the large batch is always
88+
// flushed alongside the memtable with the same logNum.
89+
// 2. During recovery, we replay WAL entries into the mutable memtable. The
90+
// memtable we allocate during recovery may be smaller than the memtable
91+
// that corresponded to the original WAL at the time it was written. This
92+
// means we may fill the memtable before finishing replaying the WAL,
93+
// resulting in multiple consecutive flushable entries all with the same
94+
// logNum. This is okay because we take care to flush all the flushables
95+
// during Open.
8396
logNum base.DiskFileNum
8497
// logSize is the size in bytes of the associated WAL. Protected by DB.mu.
8598
logSize uint64

0 commit comments

Comments
 (0)