Explorar el Código

raft: make memory storage set method thread safe

杜军 hace 9 años
padre
commit
8151d4d0bc
Se han modificado 1 ficheros con 2 adiciones y 0 borrados
  1. 2 0
      raft/storage.go

+ 2 - 0
raft/storage.go

@@ -98,6 +98,8 @@ func (ms *MemoryStorage) InitialState() (pb.HardState, pb.ConfState, error) {
 
 
 // SetHardState saves the current HardState.
 // SetHardState saves the current HardState.
 func (ms *MemoryStorage) SetHardState(st pb.HardState) error {
 func (ms *MemoryStorage) SetHardState(st pb.HardState) error {
+	ms.Lock()
+	defer ms.Unlock()
 	ms.hardState = st
 	ms.hardState = st
 	return nil
 	return nil
 }
 }