add lock around Node.status to avoid race condition

This commit is contained in:
Travis Turner 2018-01-24 16:03:36 -06:00
parent ee503c455a
commit 88fa51e6bf
No known key found for this signature in database
GPG key ID: 7F08008DFD9314C9

View file

@ -17,6 +17,7 @@ package pilosa
import (
"encoding/binary"
"hash/fnv"
"sync"
"time"
"github.com/pilosa/pilosa/internal"
@ -41,16 +42,21 @@ type Node struct {
Scheme string `json:"scheme"`
Host string `json:"host"`
mu sync.Mutex
status *internal.NodeStatus `json:"status"`
}
// SetStatus sets the NodeStatus.
func (n *Node) SetStatus(s *internal.NodeStatus) {
n.mu.Lock()
n.status = s
n.mu.Unlock()
}
// SetState sets the Node.status.state.
func (n *Node) SetState(s string) {
n.mu.Lock()
defer n.mu.Unlock()
if n.status == nil {
n.status = &internal.NodeStatus{}
}