mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Merge pull request #1068 from travisturner/node-status-mutex
add lock around Node.status to avoid race condition
This commit is contained in:
commit
c6ed7345c7
1 changed files with 14 additions and 1 deletions
15
cluster.go
15
cluster.go
|
|
@ -17,6 +17,7 @@ package pilosa
|
|||
import (
|
||||
"encoding/binary"
|
||||
"hash/fnv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pilosa/pilosa/internal"
|
||||
|
|
@ -41,16 +42,28 @@ type Node struct {
|
|||
Scheme string `json:"scheme"`
|
||||
Host string `json:"host"`
|
||||
|
||||
mu sync.RWMutex
|
||||
status *internal.NodeStatus `json:"status"`
|
||||
}
|
||||
|
||||
// Status gets the NodeStatus.
|
||||
func (n *Node) Status() *internal.NodeStatus {
|
||||
n.mu.RLock()
|
||||
defer n.mu.RUnlock()
|
||||
return n.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{}
|
||||
}
|
||||
|
|
@ -197,7 +210,7 @@ func (c *Cluster) Status() *internal.ClusterStatus {
|
|||
func encodeClusterStatus(a []*Node) []*internal.NodeStatus {
|
||||
other := make([]*internal.NodeStatus, len(a))
|
||||
for i := range a {
|
||||
other[i] = a[i].status
|
||||
other[i] = a[i].Status()
|
||||
}
|
||||
return other
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue