-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logstore: load last entry term #142016
base: master
Are you sure you want to change the base?
logstore: load last entry term #142016
Conversation
See the function comment. RawNode never accesses log indices above the storage.LastIndex() because it has them covered by the unstable log. Epic: none Release note: none
Epic: none Release note: none
Stacked on top of #142014. |
We already read the last entry term when initializing RawNode, so there is no additional overhead, except the fact that this entry is now not stashed into the raft entry cache. There appears to be low benefit in putting it into the cache though. Typically, we wouldn't need exactly the LastIndex entry post startup. Eventually, on startup we will load the term cache instead of the last entry. Epic: none Release note: none
We always know the term of the last entry. It is now loaded on replica startup. The applySnapshot code resets the log to empty, and knows the term of the last entry. Epic: none Release note: none
47128f4
to
0d6c315
Compare
LastIndex: state.RaftAppliedIndex, | ||
LastTerm: invalidLastTerm, | ||
LastTerm: state.RaftAppliedIndexTerm, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logically, these should be set based on truncState
(scoped to log storage) rather than ReplicaState
(scoped to state machine), even though these index/term are the same in applySnapshot
(need to double-check).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to involve a lot of refactor, lets save this task for the future.
We already read the last entry term when initializing
RawNode
, so there is no additional overhead, except the fact that this entry is now not stashed into the raft entry cache. There appears to be low benefit in putting it into the cache though. Typically, we wouldn't need exactly theLastIndex
entry post startup, it would more likely be an earlier entry. So puttingLastIndex
into the cache actually makes it ineffective because the cache drops entries below the cached slice.Eventually, on startup we will load the term cache instead of the last entry.
As a nice side-effect, this PR removes the
invalidLastTerm
oddity. It also introduces an invariant thatReplica
always knows the last raft log entry index/term. We can use this to improve theraft.Storage
API (e.g. addLastEntryID()
method and remove this panic).Resolves #142013