Browse Source

handle possible race condition

pull/2427/head
Chris Lu 3 years ago
parent
commit
3c245c69d3
  1. 13
      weed/server/master_server_cluster.go

13
weed/server/master_server_cluster.go

@ -14,6 +14,7 @@ const (
type ClusterNode struct { type ClusterNode struct {
address pb.ServerAddress address pb.ServerAddress
version string version string
counter int
} }
type Cluster struct { type Cluster struct {
@ -32,12 +33,14 @@ func (cluster *Cluster) AddClusterNode(nodeType string, address pb.ServerAddress
case "filer": case "filer":
cluster.filersLock.Lock() cluster.filersLock.Lock()
defer cluster.filersLock.Unlock() defer cluster.filersLock.Unlock()
if _, found := cluster.filers[address]; found {
if existingNode, found := cluster.filers[address]; found {
existingNode.counter++
return return
} }
cluster.filers[address] = &ClusterNode{ cluster.filers[address] = &ClusterNode{
address: address, address: address,
version: version, version: version,
counter: 1,
} }
case "master": case "master":
} }
@ -48,10 +51,14 @@ func (cluster *Cluster) RemoveClusterNode(nodeType string, address pb.ServerAddr
case "filer": case "filer":
cluster.filersLock.Lock() cluster.filersLock.Lock()
defer cluster.filersLock.Unlock() defer cluster.filersLock.Unlock()
if _, found := cluster.filers[address]; !found {
if existingNode, found := cluster.filers[address]; !found {
return return
} else {
existingNode.counter--
if existingNode.counter <= 0 {
delete(cluster.filers, address)
}
} }
delete(cluster.filers, address)
case "master": case "master":
} }
} }

Loading…
Cancel
Save