@@ -292,10 +292,6 @@ func (l *raftLog) hasNextUnstableEnts() bool {
292292// entries from the unstable log may be returned; otherwise, only entries known
293293// to reside locally on stable storage will be returned.
294294func (l * raftLog ) nextCommittedEnts (allowUnstable bool ) (ents []pb.Entry ) {
295- if l .hasNextOrInProgressSnapshot () {
296- // See comment in hasNextCommittedEnts.
297- return nil
298- }
299295 lo , hi := l .applying , l .maxAppliableIndex (allowUnstable ) // (lo, hi]
300296 if lo >= hi {
301297 // Nothing to apply.
@@ -311,26 +307,37 @@ func (l *raftLog) nextCommittedEnts(allowUnstable bool) (ents []pb.Entry) {
311307// hasNextCommittedEnts returns if there is any available entries for execution.
312308// This is a fast check without heavy raftLog.slice() in nextCommittedEnts().
313309func (l * raftLog ) hasNextCommittedEnts (allowUnstable bool ) bool {
314- if l .hasNextOrInProgressSnapshot () {
315- // If we have a snapshot to apply, don't also return any committed
316- // entries. Doing so raises questions about what should be applied
317- // first.
318- return false
319- }
320- lo , hi := l .applying + 1 , l .maxAppliableIndex (allowUnstable )+ 1 // [lo, hi)
321- return lo < hi
310+ return l .applying < l .maxAppliableIndex (allowUnstable )
322311}
323312
324313// maxAppliableIndex returns the maximum committed index that can be applied.
325314// If allowUnstable is true, committed entries from the unstable log can be
326315// applied; otherwise, only entries known to reside locally on stable storage
327316// can be applied.
317+ //
318+ // The maxAppliableIndex never regresses, and is always >= l.applying, assuming
319+ // allowUnstable does not change from true to false. As of today, this flag is
320+ // configured statically.
321+ //
322+ // If there is a pending snapshot, maxAppliableIndex returns l.applying, i.e.
323+ // the application of committed entries is paused until the snapshot is applied.
328324func (l * raftLog ) maxAppliableIndex (allowUnstable bool ) uint64 {
329- hi := l .committed
330- if ! allowUnstable {
331- hi = min (hi , l .unstable .prev .index )
332- }
333- return hi
325+ if l .hasNextOrInProgressSnapshot () {
326+ // If we have a snapshot to apply, don't return any committed entries. Doing
327+ // so raises questions about what should be applied first.
328+ //
329+ // TODO(pav-kv): the answer to the questions is - the snapshot should be
330+ // applied first, and then the entries. The code must make sure that the
331+ // overall sequence of "apply" batches is in the increasing order of the
332+ // commit index.
333+ return l .applying
334+ }
335+ if allowUnstable {
336+ return l .committed
337+ }
338+ // NB: this returns >= l.applying because l.applying <= prev.index, assuming
339+ // that allowUnstable hasn't flipped from true to false.
340+ return min (l .committed , l .unstable .prev .index )
334341}
335342
336343// nextUnstableSnapshot returns the snapshot, if present, that is available to
0 commit comments