Description
The gap is yet to be confirmed, it's unclear if it can happen. Discovered while cleaning up the raftLog/unstable
structures.
The unstable
structure tracks log entries and a snapshot in flight to storage.
The undocumented invariant seems to be: if there is a snapshot
, then the offset == snapshot.Metadata.Index + 1
. The underlying sense of this invariant is that the snapshot is a "wide entry" at index offset - 1
that immediately precedes all the entries
. Correspondingly, there is a requirement to write this snapshot
to storage earlier than the entries.
We maintain this invariant during the lifecycle of unstable
, and rely on it when extracting the log size, and terms of entries at specific indices.
However, there is one place where the invariant can be violated:
Lines 202 to 208 in 073f90d
When fromIndex < u.offset
(strictly less), we don't erase u.snapshot
, and as a result it's possible that u.offset < u.snapshot.Metadata.Index + 1
. It's also possible that the snapshot index exceeds lastIndex()
.
It's unclear if the above situation can happen, and what is the consequence. Best case: it can't happen because the layers above won't submit an append at index below the unstable.snapshot
. Worst case: it can happen, and things can be written or committed out of order.
In any case, we need to straighten invariants here, and fix this code to be safer.
To be investigated.