mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver/*, wal/*:Add comments, clean up error messages and tests
This commit is contained in:
parent
bd16071846
commit
b68eea236e
@ -250,8 +250,9 @@ func (r *raftNode) start(rh *raftReadyHandler) {
|
|||||||
// Force WAL to fsync its hard state before Release() releases
|
// Force WAL to fsync its hard state before Release() releases
|
||||||
// old data from the WAL. Otherwise could get an error like:
|
// old data from the WAL. Otherwise could get an error like:
|
||||||
// panic: tocommit(107) is out of range [lastIndex(84)]. Was the raft log corrupted, truncated, or lost?
|
// panic: tocommit(107) is out of range [lastIndex(84)]. Was the raft log corrupted, truncated, or lost?
|
||||||
|
// See https://github.com/etcd-io/etcd/issues/10219 for more details.
|
||||||
if err := r.storage.Sync(); err != nil {
|
if err := r.storage.Sync(); err != nil {
|
||||||
log.Fatal(err)
|
r.lg.Fatal("failed to sync Raft snapshot", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
// etcdserver now claim the snapshot has been persisted onto the disk
|
// etcdserver now claim the snapshot has been persisted onto the disk
|
||||||
@ -263,7 +264,7 @@ func (r *raftNode) start(rh *raftReadyHandler) {
|
|||||||
// gofail: var raftAfterApplySnap struct{}
|
// gofail: var raftAfterApplySnap struct{}
|
||||||
|
|
||||||
if err := r.storage.Release(rd.Snapshot); err != nil {
|
if err := r.storage.Release(rd.Snapshot); err != nil {
|
||||||
log.Fatal(err)
|
r.lg.Fatal("failed to release Raft wal", zap.Error(err))
|
||||||
}
|
}
|
||||||
// gofail: var raftAfterWALRelease struct{}
|
// gofail: var raftAfterWALRelease struct{}
|
||||||
}
|
}
|
||||||
|
@ -1162,7 +1162,7 @@ func TestTriggerSnap(t *testing.T) {
|
|||||||
// each operation is recorded as a Save
|
// each operation is recorded as a Save
|
||||||
// (SnapshotCount+1) * Puts + SaveSnap = (SnapshotCount+1) * Save + SaveSnap + Release
|
// (SnapshotCount+1) * Puts + SaveSnap = (SnapshotCount+1) * Save + SaveSnap + Release
|
||||||
if len(gaction) != wcnt {
|
if len(gaction) != wcnt {
|
||||||
fmt.Println("gaction", gaction)
|
t.Logf("gaction: %v", gaction)
|
||||||
t.Fatalf("len(action) = %d, want %d", len(gaction), wcnt)
|
t.Fatalf("len(action) = %d, want %d", len(gaction), wcnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -583,7 +583,7 @@ func ValidSnapshotEntries(lg *zap.Logger, walDir string) ([]walpb.Snapshot, erro
|
|||||||
n++
|
n++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
snaps = snaps[:n]
|
snaps = snaps[:n:n]
|
||||||
|
|
||||||
return snaps, nil
|
return snaps, nil
|
||||||
}
|
}
|
||||||
|
@ -1011,9 +1011,11 @@ func TestValidSnapshotEntries(t *testing.T) {
|
|||||||
defer os.RemoveAll(p)
|
defer os.RemoveAll(p)
|
||||||
snap0 := walpb.Snapshot{Index: 0, Term: 0}
|
snap0 := walpb.Snapshot{Index: 0, Term: 0}
|
||||||
snap1 := walpb.Snapshot{Index: 1, Term: 1}
|
snap1 := walpb.Snapshot{Index: 1, Term: 1}
|
||||||
|
state1 := raftpb.HardState{Commit: 1, Term: 1}
|
||||||
snap2 := walpb.Snapshot{Index: 2, Term: 1}
|
snap2 := walpb.Snapshot{Index: 2, Term: 1}
|
||||||
snap3 := walpb.Snapshot{Index: 3, Term: 2}
|
snap3 := walpb.Snapshot{Index: 3, Term: 2}
|
||||||
snap4 := walpb.Snapshot{Index: 4, Term: 2}
|
state2 := raftpb.HardState{Commit: 3, Term: 2}
|
||||||
|
snap4 := walpb.Snapshot{Index: 4, Term: 2} // will be orphaned since the last committed entry will be snap3
|
||||||
func() {
|
func() {
|
||||||
w, err := Create(zap.NewExample(), p, nil)
|
w, err := Create(zap.NewExample(), p, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1025,8 +1027,7 @@ func TestValidSnapshotEntries(t *testing.T) {
|
|||||||
if err = w.SaveSnapshot(snap1); err != nil {
|
if err = w.SaveSnapshot(snap1); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
state := raftpb.HardState{Commit: 1, Term: 1}
|
if err = w.Save(state1, nil); err != nil {
|
||||||
if err = w.Save(state, nil); err != nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err = w.SaveSnapshot(snap2); err != nil {
|
if err = w.SaveSnapshot(snap2); err != nil {
|
||||||
@ -1035,7 +1036,6 @@ func TestValidSnapshotEntries(t *testing.T) {
|
|||||||
if err = w.SaveSnapshot(snap3); err != nil {
|
if err = w.SaveSnapshot(snap3); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
state2 := raftpb.HardState{Commit: 3, Term: 2}
|
|
||||||
if err = w.Save(state2, nil); err != nil {
|
if err = w.Save(state2, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -1048,12 +1048,7 @@ func TestValidSnapshotEntries(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
expected := []walpb.Snapshot{snap0, snap1, snap2, snap3}
|
expected := []walpb.Snapshot{snap0, snap1, snap2, snap3}
|
||||||
if len(walSnaps) != len(expected) {
|
if !reflect.DeepEqual(walSnaps, expected) {
|
||||||
t.Fatalf("expected 4 walSnaps, got %d", len(expected))
|
t.Errorf("expected walSnaps %+v, got %+v", expected, walSnaps)
|
||||||
}
|
|
||||||
for i := 0; i < len(expected); i++ {
|
|
||||||
if walSnaps[i].Index != expected[i].Index || walSnaps[i].Term != expected[i].Term {
|
|
||||||
t.Errorf("expected walSnaps %+v at index %d, got %+v", expected[i], i, walSnaps[i])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user