From 114b20ec5c25f4094d3118acf2bce1946911e3a5 Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Thu, 1 Oct 2015 16:52:14 -0500 Subject: [PATCH] need some locking, remove redundant check --- meta/store.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/meta/store.go b/meta/store.go index d1fb17c465..1b2e9f5fbd 100644 --- a/meta/store.go +++ b/meta/store.go @@ -378,6 +378,8 @@ func (s *Store) joinCluster() error { } func (s *Store) enableLocalRaft() error { + s.mu.Lock() + defer s.mu.Unlock() if _, ok := s.raftState.(*localRaft); ok { return nil } @@ -398,6 +400,13 @@ func (s *Store) enableRemoteRaft() error { } func (s *Store) checkRaftState() error { + s.mu.RLock() + if s.raftState == nil { + s.mu.RUnlock() + return nil + } + s.mu.RUnlock() + peers, err := s.raftState.peers() if err != nil { return err @@ -414,10 +423,6 @@ func (s *Store) checkRaftState() error { return nil } - if _, ok := s.raftState.(*localRaft); ok { - return nil - } - return s.enableLocalRaft() } @@ -905,6 +910,13 @@ func (s *Store) DeleteNode(id uint64, force bool) error { func (s *Store) promoteRandomNodeToPeer() error { // Only do this if you are the leader if s.raftState.isLeader() { + s.mu.Lock() + defer s.mu.Unlock() + + if s.raftState == nil { + return nil + } + peers, err := s.raftState.peers() if err != nil { return err