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:
Ben Darnell 2014-11-21 17:22:20 -05:00
parent 03c8881e35
commit 9ddd8ee539
3 changed files with 18 additions and 9 deletions

View File

@ -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

View File

@ -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()

View File

@ -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.