mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Rename Storage.HardState back to InitialState and include ConfState.
This fixes integration/migration_test.go (and highlights the fact that we need some more raft-level testing of restoring from snapshots).
This commit is contained in:
parent
03c8881e35
commit
9ddd8ee539
15
raft/raft.go
15
raft/raft.go
@ -145,10 +145,19 @@ func newRaft(id uint64, peers []uint64, election, heartbeat int, storage Storage
|
||||
panic("cannot use none id")
|
||||
}
|
||||
log := newLog(storage)
|
||||
st, err := storage.HardState()
|
||||
hs, cs, err := storage.InitialState()
|
||||
if err != nil {
|
||||
panic(err) // TODO(bdarnell)
|
||||
}
|
||||
if len(cs.Nodes) > 0 {
|
||||
if len(peers) > 0 {
|
||||
// TODO(bdarnell): the peers argument is always nil except in
|
||||
// tests; the argument should be removed and these tests should be
|
||||
// updated to specify their nodes through a snapshot.
|
||||
panic("cannot specify both newRaft(peers) and ConfState.Nodes)")
|
||||
}
|
||||
peers = cs.Nodes
|
||||
}
|
||||
r := &raft{
|
||||
id: id,
|
||||
lead: None,
|
||||
@ -161,8 +170,8 @@ func newRaft(id uint64, peers []uint64, election, heartbeat int, storage Storage
|
||||
for _, p := range peers {
|
||||
r.prs[p] = &progress{next: 1}
|
||||
}
|
||||
if !isHardStateEqual(st, emptyState) {
|
||||
r.loadState(st)
|
||||
if !isHardStateEqual(hs, emptyState) {
|
||||
r.loadState(hs)
|
||||
}
|
||||
r.becomeFollower(0, None)
|
||||
return r
|
||||
|
@ -974,7 +974,7 @@ func TestBcastBeat(t *testing.T) {
|
||||
}
|
||||
storage := NewMemoryStorage()
|
||||
storage.ApplySnapshot(s)
|
||||
sm := newRaft(1, []uint64{1, 2, 3}, 10, 1, storage)
|
||||
sm := newRaft(1, nil, 10, 1, storage)
|
||||
sm.Term = 1
|
||||
|
||||
sm.becomeCandidate()
|
||||
|
@ -35,8 +35,8 @@ var ErrCompacted = errors.New("requested index is unavailable due to compaction"
|
||||
// become inoperable and refuse to participate in elections; the
|
||||
// application is responsible for cleanup and recovery in this case.
|
||||
type Storage interface {
|
||||
// HardState returns the saved HardState information.
|
||||
HardState() (pb.HardState, error)
|
||||
// InitialState returns the saved HardState and ConfState information.
|
||||
InitialState() (pb.HardState, pb.ConfState, error)
|
||||
// Entries returns a slice of log entries in the range [lo,hi).
|
||||
Entries(lo, hi uint64) ([]pb.Entry, error)
|
||||
// Term returns the term of entry i, which must be in the range
|
||||
@ -79,9 +79,9 @@ func NewMemoryStorage() *MemoryStorage {
|
||||
}
|
||||
}
|
||||
|
||||
// HardState implements the Storage interface.
|
||||
func (ms *MemoryStorage) HardState() (pb.HardState, error) {
|
||||
return ms.hardState, nil
|
||||
// InitialState implements the Storage interface.
|
||||
func (ms *MemoryStorage) InitialState() (pb.HardState, pb.ConfState, error) {
|
||||
return ms.hardState, ms.snapshot.Metadata.ConfState, nil
|
||||
}
|
||||
|
||||
// SetHardState saves the current HardState.
|
||||
|
Loading…
x
Reference in New Issue
Block a user