소스 검색

etcdserver: get existing snapshot instead of requesting one

This fixes the problem that proposal cannot be applied.

When start the etcdserver.run loop, it expects to get the latest
existing snapshot. It should not attempt to request one because the loop
is the entity to create the snapshot.
Yicheng Qin 10 년 전
부모
커밋
8c94ae0ee3
2개의 변경된 파일7개의 추가작업 그리고 3개의 파일을 삭제
  1. 1 0
      etcdserver/raft.go
  2. 6 3
      etcdserver/raft_storage.go

+ 1 - 0
etcdserver/raft.go

@@ -120,6 +120,7 @@ type raftNode struct {
 // TODO: Ideally raftNode should get rid of the passed in server structure.
 // TODO: Ideally raftNode should get rid of the passed in server structure.
 func (r *raftNode) start(s *EtcdServer) {
 func (r *raftNode) start(s *EtcdServer) {
 	r.s = s
 	r.s = s
+	r.raftStorage.raftStarted = true
 	r.applyc = make(chan apply)
 	r.applyc = make(chan apply)
 	r.stopped = make(chan struct{})
 	r.stopped = make(chan struct{})
 	r.done = make(chan struct{})
 	r.done = make(chan struct{})

+ 6 - 3
etcdserver/raft_storage.go

@@ -24,6 +24,9 @@ type raftStorage struct {
 	// snapStore is the place to request snapshot when v3demo is enabled.
 	// snapStore is the place to request snapshot when v3demo is enabled.
 	// If snapStore is nil, it uses the snapshot saved in MemoryStorage.
 	// If snapStore is nil, it uses the snapshot saved in MemoryStorage.
 	snapStore *snapshotStore
 	snapStore *snapshotStore
+	// raftStarted indicates whether raft starts to function. If not, it cannot
+	// request snapshot, and should get snapshot from MemoryStorage.
+	raftStarted bool
 }
 }
 
 
 func newRaftStorage() *raftStorage {
 func newRaftStorage() *raftStorage {
@@ -46,11 +49,11 @@ func (rs *raftStorage) raftsnap() chan<- raftpb.Snapshot {
 	return rs.snapStore.raftsnapc
 	return rs.snapStore.raftsnapc
 }
 }
 
 
-// Snapshot returns raft snapshot. If snapStore is nil, this method
-// returns snapshot saved in MemoryStorage. If snapStore exists, this method
+// Snapshot returns raft snapshot. If snapStore is nil or raft is not started, this method
+// returns snapshot saved in MemoryStorage. Otherwise, this method
 // returns snapshot from snapStore.
 // returns snapshot from snapStore.
 func (rs *raftStorage) Snapshot() (raftpb.Snapshot, error) {
 func (rs *raftStorage) Snapshot() (raftpb.Snapshot, error) {
-	if rs.snapStore == nil {
+	if rs.snapStore == nil || !rs.raftStarted {
 		return rs.MemoryStorage.Snapshot()
 		return rs.MemoryStorage.Snapshot()
 	}
 	}
 	snap, err := rs.snapStore.getSnap()
 	snap, err := rs.snapStore.getSnap()