-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
Fix state.commit is out of range on restart #11888
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9162cd6
etcdserver/*, wal/*: changes to snapshots and wal logic to fix #10219
3d2b565
etcdserver/*: changes to snapshots and wal logic to fix #10219
5435e76
etcdserver/*: fix tests
91efa67
etcdserver/*: rollback default settings
5051703
etcdserver/*, wal/*: add Sync method
bd16071
etcdserver/*, wal/*: find valid snapshots by cross checking snap file…
jpbetz b68eea2
etcdserver/*, wal/*:Add comments, clean up error messages and tests
jpbetz 743e6e9
etcdserver/*, wal/*: Remove orphaned .snap.db files during Release
jpbetz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,11 @@ import ( | |
"sync/atomic" | ||
"time" | ||
|
||
"github.com/coreos/go-semver/semver" | ||
humanize "github.com/dustin/go-humanize" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"go.uber.org/zap" | ||
|
||
"go.etcd.io/etcd/v3/auth" | ||
"go.etcd.io/etcd/v3/etcdserver/api" | ||
"go.etcd.io/etcd/v3/etcdserver/api/membership" | ||
|
@@ -59,11 +64,6 @@ import ( | |
"go.etcd.io/etcd/v3/raft/raftpb" | ||
"go.etcd.io/etcd/v3/version" | ||
"go.etcd.io/etcd/v3/wal" | ||
|
||
"github.com/coreos/go-semver/semver" | ||
humanize "github.com/dustin/go-humanize" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"go.uber.org/zap" | ||
) | ||
|
||
const ( | ||
|
@@ -414,10 +414,19 @@ func NewServer(cfg ServerConfig) (srv *EtcdServer, err error) { | |
zap.String("wal-dir", cfg.WALDir()), | ||
) | ||
} | ||
snapshot, err = ss.Load() | ||
|
||
// Find a snapshot to start/restart a raft node | ||
walSnaps, err := wal.ValidSnapshotEntries(cfg.Logger, cfg.WALDir()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// snapshot files can be orphaned if etcd crashes after writing them but before writing the corresponding | ||
// wal log entries | ||
snapshot, err := ss.LoadNewestAvailable(walSnaps) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change created a local |
||
if err != nil && err != snap.ErrNoSnapshot { | ||
return nil, err | ||
} | ||
|
||
if snapshot != nil { | ||
if err = st.Recovery(snapshot.Data); err != nil { | ||
cfg.Logger.Panic("failed to recover from snapshot", zap.Error(err)) | ||
|
@@ -2150,11 +2159,14 @@ func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) { | |
} | ||
lg.Panic("failed to create snapshot", zap.Error(err)) | ||
} | ||
// SaveSnap saves the snapshot and releases the locked wal files | ||
// to the snapshot index. | ||
// SaveSnap saves the snapshot to file and appends the corresponding WAL entry. | ||
if err = s.r.storage.SaveSnap(snap); err != nil { | ||
lg.Panic("failed to save snapshot", zap.Error(err)) | ||
} | ||
if err = s.r.storage.Release(snap); err != nil { | ||
lg.Panic("failed to release wal", zap.Error(err)) | ||
} | ||
|
||
lg.Info( | ||
"saved snapshot", | ||
zap.Uint64("snapshot-index", snap.Metadata.Index), | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
.snap.db seems to be redundant since it is suffix of filename
Also, we should continue the loop and try to release other files
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.
Submitted #11899
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.
We can't just call it
.snap
since there are already different files with that suffix. But the purpose of this PR isn't to rethink the file suffix anyway...Continuing if we hit an error sounds fine. This is merged now though, so that would need a separate PR.