Merge pull request #15 from kuba--/no-mu

No mu
This commit is contained in:
Kuba Podgórski 2021-02-03 22:06:39 +01:00 committed by GitHub
commit 893b5ea6ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 35 deletions

View file

@ -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

View file

@ -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),

View file

@ -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)
}

View file

@ -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