rafthttp: remove failureMap from peerStatus

The logging mechanism is verbose, so it is removed from peerStatus.

We would like to see the status change
of connection with peers, and one error that leads to deactivation.
There is no need to print out all non-repeated errors.
This commit is contained in:
Yicheng Qin 2015-11-04 07:05:26 -08:00
parent 099d8674c4
commit 5329159b5e

View File

@ -31,14 +31,12 @@ type peerStatus struct {
id types.ID id types.ID
mu sync.Mutex // protect variables below mu sync.Mutex // protect variables below
active bool active bool
failureMap map[failureType]string
activeSince time.Time activeSince time.Time
} }
func newPeerStatus(id types.ID) *peerStatus { func newPeerStatus(id types.ID) *peerStatus {
return &peerStatus{ return &peerStatus{
id: id, id: id,
failureMap: make(map[failureType]string),
} }
} }
@ -49,25 +47,21 @@ func (s *peerStatus) activate() {
plog.Infof("the connection with %s became active", s.id) plog.Infof("the connection with %s became active", s.id)
s.active = true s.active = true
s.activeSince = time.Now() s.activeSince = time.Now()
s.failureMap = make(map[failureType]string)
} }
} }
func (s *peerStatus) deactivate(failure failureType, reason string) { func (s *peerStatus) deactivate(failure failureType, reason string) {
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock() defer s.mu.Unlock()
msg := fmt.Sprintf("failed to %s %s on %s (%s)", failure.action, s.id, failure.source, reason)
if s.active { if s.active {
plog.Errorf(msg)
plog.Infof("the connection with %s became inactive", s.id) plog.Infof("the connection with %s became inactive", s.id)
s.active = false s.active = false
s.activeSince = time.Time{} s.activeSince = time.Time{}
}
logline := fmt.Sprintf("failed to %s %s on %s (%s)", failure.action, s.id, failure.source, reason)
if r, ok := s.failureMap[failure]; ok && r == reason {
plog.Debugf(logline)
return return
} }
s.failureMap[failure] = reason plog.Debugf(msg)
plog.Errorf(logline)
} }
func (s *peerStatus) isActive() bool { func (s *peerStatus) isActive() bool {