You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.3 KiB

3 years ago
  1. package weed_server
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/pb"
  4. "sync"
  5. )
  6. type NodeType int
  7. const (
  8. filerNodeType NodeType = iota
  9. )
  10. type ClusterNode struct {
  11. address pb.ServerAddress
  12. version string
  13. }
  14. type Cluster struct {
  15. filers map[pb.ServerAddress]*ClusterNode
  16. filersLock sync.RWMutex
  17. }
  18. func NewCluster() *Cluster {
  19. return &Cluster{
  20. filers: make(map[pb.ServerAddress]*ClusterNode),
  21. }
  22. }
  23. func (cluster *Cluster) AddClusterNode(nodeType string, address pb.ServerAddress, version string) {
  24. switch nodeType {
  25. case "filer":
  26. cluster.filersLock.Lock()
  27. defer cluster.filersLock.Unlock()
  28. if _, found := cluster.filers[address]; found {
  29. return
  30. }
  31. cluster.filers[address] = &ClusterNode{
  32. address: address,
  33. version: version,
  34. }
  35. case "master":
  36. }
  37. }
  38. func (cluster *Cluster) RemoveClusterNode(nodeType string, address pb.ServerAddress) {
  39. switch nodeType {
  40. case "filer":
  41. cluster.filersLock.Lock()
  42. defer cluster.filersLock.Unlock()
  43. if _, found := cluster.filers[address]; !found {
  44. return
  45. }
  46. delete(cluster.filers, address)
  47. case "master":
  48. }
  49. }
  50. func (cluster *Cluster) ListClusterNode(nodeType string) (nodes []*ClusterNode) {
  51. switch nodeType {
  52. case "filer":
  53. cluster.filersLock.RLock()
  54. defer cluster.filersLock.RUnlock()
  55. for _, node := range cluster.filers {
  56. nodes = append(nodes, node)
  57. }
  58. case "master":
  59. }
  60. return
  61. }