mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-13 08:01:02 +00:00
commit
893b5ea6ab
4 changed files with 9 additions and 35 deletions
26
cluster.go
26
cluster.go
|
|
@ -353,25 +353,21 @@ func (c *cluster) addNodeBasicSorted(node *topology.Node) bool {
|
|||
n := c.unprotectedNodeByID(node.ID)
|
||||
|
||||
if n != nil {
|
||||
// prevent race on node.URI read against http/client.go:1929
|
||||
n.Mu.Lock()
|
||||
defer n.Mu.Unlock()
|
||||
|
||||
nn := &topology.Node{
|
||||
ID: node.ID,
|
||||
URI: node.URI,
|
||||
GRPCURI: node.GRPCURI,
|
||||
IsPrimary: node.IsPrimary,
|
||||
State: node.State,
|
||||
}
|
||||
if n.State != node.State || n.IsPrimary != node.IsPrimary || n.URI != node.URI {
|
||||
n.State = node.State
|
||||
n.IsPrimary = node.IsPrimary
|
||||
n.URI = node.URI
|
||||
n.GRPCURI = node.GRPCURI
|
||||
*n = *nn
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
c.noder.AppendNode(node)
|
||||
|
||||
// All hosts must be merged in the same order on all nodes in the cluster.
|
||||
// sort.Sort(topology.ByID(c.nodes)) // TODO: this should no longer apply
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
@ -1859,12 +1855,6 @@ func (c *cluster) ReceiveEvent(e *NodeEvent) (err error) {
|
|||
}
|
||||
switch e.Event {
|
||||
case NodeJoin:
|
||||
e.Node.Mu.Lock()
|
||||
c.Node.Mu.Lock()
|
||||
c.logger.Debugf("nodeJoin of %s on %s", e.Node.URI, c.Node.URI)
|
||||
c.Node.Mu.Unlock()
|
||||
e.Node.Mu.Unlock()
|
||||
|
||||
// Ignore the event if this is not the coordinator.
|
||||
if !c.isCoordinator() {
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -671,7 +671,7 @@ func (s Serializer) encodeNodes(a []*topology.Node) []*internal.Node {
|
|||
|
||||
// s.encodeNode converts a Node into its internal representation.
|
||||
func (s Serializer) encodeNode(m *topology.Node) *internal.Node {
|
||||
n := m.ProtectedClone()
|
||||
n := m.Clone()
|
||||
return &internal.Node{
|
||||
ID: n.ID,
|
||||
URI: s.encodeURI(n.URI),
|
||||
|
|
|
|||
|
|
@ -940,11 +940,7 @@ func (s *Server) SendSync(m Message) error {
|
|||
|
||||
for _, node := range s.cluster.Nodes() {
|
||||
node := node
|
||||
|
||||
// prevent race against cluster.addNodeBasicSorted() in cluster.go
|
||||
node.Mu.Lock()
|
||||
uri := node.URI // URI is a struct value
|
||||
node.Mu.Unlock()
|
||||
|
||||
// Don't forward the message to ourselves.
|
||||
if s.uri == uri {
|
||||
|
|
@ -972,10 +968,7 @@ func (s *Server) SendTo(node *topology.Node, m Message) error {
|
|||
}
|
||||
msg = append([]byte{getMessageType(m)}, msg...)
|
||||
|
||||
// prevent race against cluster.addNodeBasicSorted() in cluster.go
|
||||
node.Mu.Lock()
|
||||
uri := node.URI // URI is a struct value
|
||||
node.Mu.Unlock()
|
||||
|
||||
return s.defaultClient.SendMessage(context.Background(), &uri, msg)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,15 +16,12 @@ package topology
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/pilosa/pilosa/v2/net"
|
||||
)
|
||||
|
||||
// Node represents a node in the cluster.
|
||||
type Node struct {
|
||||
Mu sync.Mutex `json:"-"` // TODO: we really need to get rid of this
|
||||
|
||||
ID string `json:"id"`
|
||||
URI net.URI `json:"uri"`
|
||||
GRPCURI net.URI `json:"grpc-uri"`
|
||||
|
|
@ -32,12 +29,6 @@ type Node struct {
|
|||
State string `json:"state"`
|
||||
}
|
||||
|
||||
func (n *Node) ProtectedClone() *Node {
|
||||
n.Mu.Lock()
|
||||
defer n.Mu.Unlock()
|
||||
return n.Clone()
|
||||
}
|
||||
|
||||
func (n *Node) Clone() *Node {
|
||||
if n == nil {
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue