diff options
| author | Chris Lu <chris.lu@gmail.com> | 2021-11-08 00:09:11 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2021-11-08 17:47:56 -0800 |
| commit | 4729a57cc01ca360e7aa70c43b2290bb2e8bcd2d (patch) | |
| tree | 6003837cf15ab74ec1c6e809708dc146a8bc2f1a /weed/cluster | |
| parent | d9dd72ea560da14ecb3cbf06cdf94b82071a9658 (diff) | |
| download | seaweedfs-4729a57cc01ca360e7aa70c43b2290bb2e8bcd2d.tar.xz seaweedfs-4729a57cc01ca360e7aa70c43b2290bb2e8bcd2d.zip | |
use constants
Diffstat (limited to 'weed/cluster')
| -rw-r--r-- | weed/cluster/cluster.go | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/weed/cluster/cluster.go b/weed/cluster/cluster.go index 11187169e..348646f04 100644 --- a/weed/cluster/cluster.go +++ b/weed/cluster/cluster.go @@ -8,6 +8,11 @@ import ( "time" ) +const ( + MasterType = "master" + FilerType = "filer" +) + type ClusterNode struct { Address pb.ServerAddress Version string @@ -34,7 +39,7 @@ func NewCluster() *Cluster { func (cluster *Cluster) AddClusterNode(nodeType string, address pb.ServerAddress, version string) []*master_pb.KeepConnectedResponse { switch nodeType { - case "filer": + case FilerType: cluster.nodesLock.Lock() defer cluster.nodesLock.Unlock() if existingNode, found := cluster.nodes[address]; found { @@ -48,14 +53,14 @@ func (cluster *Cluster) AddClusterNode(nodeType string, address pb.ServerAddress createdTs: time.Now(), } return cluster.ensureLeader(true, nodeType, address) - case "master": + case MasterType: } return nil } func (cluster *Cluster) RemoveClusterNode(nodeType string, address pb.ServerAddress) []*master_pb.KeepConnectedResponse { switch nodeType { - case "filer": + case FilerType: cluster.nodesLock.Lock() defer cluster.nodesLock.Unlock() if existingNode, found := cluster.nodes[address]; !found { @@ -67,20 +72,20 @@ func (cluster *Cluster) RemoveClusterNode(nodeType string, address pb.ServerAddr return cluster.ensureLeader(false, nodeType, address) } } - case "master": + case MasterType: } return nil } func (cluster *Cluster) ListClusterNode(nodeType string) (nodes []*ClusterNode) { switch nodeType { - case "filer": + case FilerType: cluster.nodesLock.RLock() defer cluster.nodesLock.RUnlock() for _, node := range cluster.nodes { nodes = append(nodes, node) } - case "master": + case MasterType: } return } |
