Skip to content

raft: don't apply entries when applying snapshot#14721

Merged
ahrtr merged 2 commits into
etcd-io:mainfrom
nvb:nvanbenschoten/noCommittedOnSnap
Nov 14, 2022
Merged

raft: don't apply entries when applying snapshot#14721
ahrtr merged 2 commits into
etcd-io:mainfrom
nvb:nvanbenschoten/noCommittedOnSnap

Conversation

@nvb

@nvb nvb commented Nov 10, 2022

Copy link
Copy Markdown
Contributor

This commit removes the ability to apply log entries at the same time as applying a snapshot. Doing so it possible, but it leads to complex code and raises questions about what should be applied first. It also raises additional complexity when we start allowing concurrent, asynchronous log appends and log application. It's easiest to just disallow this.

Signed-off-by: Nathan VanBenschoten nvanbenschoten@gmail.com

Extracted from #14627.

cc. @tbg

Please read https://github.com/etcd-io/etcd/blob/main/CONTRIBUTING.md#contribution-flow.

@codecov-commenter

codecov-commenter commented Nov 10, 2022

Copy link
Copy Markdown

Codecov Report

Merging #14721 (bdd5347) into main (bdd5347) will not change coverage.
The diff coverage is n/a.

❗ Current head bdd5347 differs from pull request most recent head 539a841. Consider uploading reports for the commit 539a841 to get more accurate results

@@           Coverage Diff           @@
##             main   #14721   +/-   ##
=======================================
  Coverage   76.04%   76.04%           
=======================================
  Files         457      457           
  Lines       37350    37350           
=======================================
  Hits        28403    28403           
  Misses       7162     7162           
  Partials     1785     1785           
Flag Coverage Δ
all 76.04% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@tbg

tbg commented Nov 11, 2022

Copy link
Copy Markdown
Contributor

Give me a ping when it's rebased, I'd like to glance at the diff again before merge. Thanks!

nvb added 2 commits November 11, 2022 13:57
unstable.snapshot is never an empty snapshot. This check made it look
like it could be.

Signed-off-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>
This commit removes the ability to apply log entries at the same time as
applying a snapshot. Doing so it possible, but it leads to complex code and
raises questions about what should be applied first. It also raises additional
complexity when we start allowing concurrent, asynchronous log appends and log
application. It's easiest to just disallow this.

Signed-off-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>
@nvb nvb force-pushed the nvanbenschoten/noCommittedOnSnap branch from a3c7480 to 539a841 Compare November 11, 2022 18:58
@nvb

nvb commented Nov 11, 2022

Copy link
Copy Markdown
Contributor Author

Rebased on main now that #14719 is merged. PTAL!

Comment thread raft/log.go
@@ -181,9 +181,13 @@ func (l *raftLog) unstableEntries() []pb.Entry {
// If applied is smaller than the index of snapshot, it returns all committed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stale comment.

Comment thread raft/log.go
if l.committed+1 > off {
ents, err := l.slice(off, l.committed+1, l.maxNextCommittedEntsSize)
if l.hasPendingSnapshot() {
// See comment in hasNextCommittedEnts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could even structure this method as

  1. call hasNextCommittedEnts; if false, return early.
  2. otherwise, do the slice.

That way there's no duplication in logic between the two and one need not worry about them diverging via a future change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Comment thread raft/log.go

@ahrtr ahrtr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thank you @nvanbenschoten

@ahrtr ahrtr merged commit 970ecfc into etcd-io:main Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants