Chris Lu
3 years ago
10 changed files with 689 additions and 484 deletions
-
9weed/command/shell.go
-
6weed/messaging/broker/broker_grpc_server_discovery.go
-
15weed/pb/master.proto
-
998weed/pb/master_pb/master.pb.go
-
22weed/server/master_grpc_server.go
-
20weed/server/master_grpc_server_cluster.go
-
3weed/server/master_server.go
-
70weed/server/master_server_cluster.go
-
24weed/shell/shell_liner.go
-
6weed/wdclient/masterclient.go
998
weed/pb/master_pb/master.pb.go
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,20 @@ |
|||||
|
package weed_server |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb" |
||||
|
) |
||||
|
|
||||
|
func (ms *MasterServer) ListClusterNodes(ctx context.Context, req *master_pb.ListClusterNodesRequest) (*master_pb.ListClusterNodesResponse, error) { |
||||
|
resp := &master_pb.ListClusterNodesResponse{} |
||||
|
|
||||
|
clusterNodes := ms.Cluster.ListClusterNode(req.ClientType) |
||||
|
|
||||
|
for _, node := range clusterNodes { |
||||
|
resp.ClusterNodes = append(resp.ClusterNodes, &master_pb.ListClusterNodesResponse_ClusterNode{ |
||||
|
Address: string(node.address), |
||||
|
Version: node.version, |
||||
|
}) |
||||
|
} |
||||
|
return resp, nil |
||||
|
} |
@ -0,0 +1,70 @@ |
|||||
|
package weed_server |
||||
|
|
||||
|
import ( |
||||
|
"github.com/chrislusf/seaweedfs/weed/pb" |
||||
|
"sync" |
||||
|
) |
||||
|
|
||||
|
type NodeType int |
||||
|
|
||||
|
const ( |
||||
|
filerNodeType NodeType = iota |
||||
|
) |
||||
|
|
||||
|
type ClusterNode struct { |
||||
|
address pb.ServerAddress |
||||
|
version string |
||||
|
} |
||||
|
|
||||
|
type Cluster struct { |
||||
|
filers map[pb.ServerAddress]*ClusterNode |
||||
|
filersLock sync.RWMutex |
||||
|
} |
||||
|
|
||||
|
func NewCluster() *Cluster { |
||||
|
return &Cluster{ |
||||
|
filers: make(map[pb.ServerAddress]*ClusterNode), |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (cluster *Cluster) AddClusterNode(nodeType string, address pb.ServerAddress, version string) { |
||||
|
switch nodeType { |
||||
|
case "filer": |
||||
|
cluster.filersLock.Lock() |
||||
|
defer cluster.filersLock.Unlock() |
||||
|
if _, found := cluster.filers[address]; found { |
||||
|
return |
||||
|
} |
||||
|
cluster.filers[address] = &ClusterNode{ |
||||
|
address: address, |
||||
|
version: version, |
||||
|
} |
||||
|
case "master": |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (cluster *Cluster) RemoveClusterNode(nodeType string, address pb.ServerAddress) { |
||||
|
switch nodeType { |
||||
|
case "filer": |
||||
|
cluster.filersLock.Lock() |
||||
|
defer cluster.filersLock.Unlock() |
||||
|
if _, found := cluster.filers[address]; !found { |
||||
|
return |
||||
|
} |
||||
|
delete(cluster.filers, address) |
||||
|
case "master": |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (cluster *Cluster) ListClusterNode(nodeType string) (nodes []*ClusterNode){ |
||||
|
switch nodeType { |
||||
|
case "filer": |
||||
|
cluster.filersLock.RLock() |
||||
|
defer cluster.filersLock.RUnlock() |
||||
|
for _, node := range cluster.filers { |
||||
|
nodes = append(nodes, node) |
||||
|
} |
||||
|
case "master": |
||||
|
} |
||||
|
return |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue