mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
use constants
This commit is contained in:
parent
d9dd72ea56
commit
4729a57cc0
|
@ -8,6 +8,11 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
MasterType = "master"
|
||||||
|
FilerType = "filer"
|
||||||
|
)
|
||||||
|
|
||||||
type ClusterNode struct {
|
type ClusterNode struct {
|
||||||
Address pb.ServerAddress
|
Address pb.ServerAddress
|
||||||
Version string
|
Version string
|
||||||
|
@ -34,7 +39,7 @@ func NewCluster() *Cluster {
|
||||||
|
|
||||||
func (cluster *Cluster) AddClusterNode(nodeType string, address pb.ServerAddress, version string) []*master_pb.KeepConnectedResponse {
|
func (cluster *Cluster) AddClusterNode(nodeType string, address pb.ServerAddress, version string) []*master_pb.KeepConnectedResponse {
|
||||||
switch nodeType {
|
switch nodeType {
|
||||||
case "filer":
|
case FilerType:
|
||||||
cluster.nodesLock.Lock()
|
cluster.nodesLock.Lock()
|
||||||
defer cluster.nodesLock.Unlock()
|
defer cluster.nodesLock.Unlock()
|
||||||
if existingNode, found := cluster.nodes[address]; found {
|
if existingNode, found := cluster.nodes[address]; found {
|
||||||
|
@ -48,14 +53,14 @@ func (cluster *Cluster) AddClusterNode(nodeType string, address pb.ServerAddress
|
||||||
createdTs: time.Now(),
|
createdTs: time.Now(),
|
||||||
}
|
}
|
||||||
return cluster.ensureLeader(true, nodeType, address)
|
return cluster.ensureLeader(true, nodeType, address)
|
||||||
case "master":
|
case MasterType:
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cluster *Cluster) RemoveClusterNode(nodeType string, address pb.ServerAddress) []*master_pb.KeepConnectedResponse {
|
func (cluster *Cluster) RemoveClusterNode(nodeType string, address pb.ServerAddress) []*master_pb.KeepConnectedResponse {
|
||||||
switch nodeType {
|
switch nodeType {
|
||||||
case "filer":
|
case FilerType:
|
||||||
cluster.nodesLock.Lock()
|
cluster.nodesLock.Lock()
|
||||||
defer cluster.nodesLock.Unlock()
|
defer cluster.nodesLock.Unlock()
|
||||||
if existingNode, found := cluster.nodes[address]; !found {
|
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)
|
return cluster.ensureLeader(false, nodeType, address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "master":
|
case MasterType:
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cluster *Cluster) ListClusterNode(nodeType string) (nodes []*ClusterNode) {
|
func (cluster *Cluster) ListClusterNode(nodeType string) (nodes []*ClusterNode) {
|
||||||
switch nodeType {
|
switch nodeType {
|
||||||
case "filer":
|
case FilerType:
|
||||||
cluster.nodesLock.RLock()
|
cluster.nodesLock.RLock()
|
||||||
defer cluster.nodesLock.RUnlock()
|
defer cluster.nodesLock.RUnlock()
|
||||||
for _, node := range cluster.nodes {
|
for _, node := range cluster.nodes {
|
||||||
nodes = append(nodes, node)
|
nodes = append(nodes, node)
|
||||||
}
|
}
|
||||||
case "master":
|
case MasterType:
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package filer
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/cluster"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb"
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
||||||
"os"
|
"os"
|
||||||
|
@ -51,7 +52,7 @@ type Filer struct {
|
||||||
func NewFiler(masters []pb.ServerAddress, grpcDialOption grpc.DialOption,
|
func NewFiler(masters []pb.ServerAddress, grpcDialOption grpc.DialOption,
|
||||||
filerHost pb.ServerAddress, collection string, replication string, dataCenter string, notifyFn func()) *Filer {
|
filerHost pb.ServerAddress, collection string, replication string, dataCenter string, notifyFn func()) *Filer {
|
||||||
f := &Filer{
|
f := &Filer{
|
||||||
MasterClient: wdclient.NewMasterClient(grpcDialOption, "filer", filerHost, dataCenter, masters),
|
MasterClient: wdclient.NewMasterClient(grpcDialOption, cluster.FilerType, filerHost, dataCenter, masters),
|
||||||
fileIdDeletionQueue: util.NewUnboundedQueue(),
|
fileIdDeletionQueue: util.NewUnboundedQueue(),
|
||||||
GrpcDialOption: grpcDialOption,
|
GrpcDialOption: grpcDialOption,
|
||||||
FilerConf: NewFilerConf(),
|
FilerConf: NewFilerConf(),
|
||||||
|
@ -82,13 +83,13 @@ func (f *Filer) ListExistingPeerUpdates() (existingNodes []*master_pb.ClusterNod
|
||||||
|
|
||||||
if grpcErr := pb.WithMasterClient(f.MasterClient.GetMaster(), f.GrpcDialOption, func(client master_pb.SeaweedClient) error {
|
if grpcErr := pb.WithMasterClient(f.MasterClient.GetMaster(), f.GrpcDialOption, func(client master_pb.SeaweedClient) error {
|
||||||
resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
|
resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
|
||||||
ClientType: "filer",
|
ClientType: cluster.FilerType,
|
||||||
})
|
})
|
||||||
|
|
||||||
glog.V(0).Infof("the cluster has %d filers\n", len(resp.ClusterNodes))
|
glog.V(0).Infof("the cluster has %d filers\n", len(resp.ClusterNodes))
|
||||||
for _, node := range resp.ClusterNodes {
|
for _, node := range resp.ClusterNodes {
|
||||||
existingNodes = append(existingNodes, &master_pb.ClusterNodeUpdate{
|
existingNodes = append(existingNodes, &master_pb.ClusterNodeUpdate{
|
||||||
NodeType: "filer",
|
NodeType: cluster.FilerType,
|
||||||
Address: node.Address,
|
Address: node.Address,
|
||||||
IsLeader: node.IsLeader,
|
IsLeader: node.IsLeader,
|
||||||
IsAdd: true,
|
IsAdd: true,
|
||||||
|
|
|
@ -3,6 +3,7 @@ package filer
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/cluster"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
||||||
"github.com/chrislusf/seaweedfs/weed/util"
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
"io"
|
"io"
|
||||||
|
@ -48,7 +49,7 @@ func NewMetaAggregator(filer *Filer, self pb.ServerAddress, grpcDialOption grpc.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ma *MetaAggregator) OnPeerUpdate(update *master_pb.ClusterNodeUpdate) {
|
func (ma *MetaAggregator) OnPeerUpdate(update *master_pb.ClusterNodeUpdate) {
|
||||||
if update.NodeType != "filer" {
|
if update.NodeType != cluster.FilerType {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package broker
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/cluster"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb"
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ func (broker *MessageBroker) checkFilers() {
|
||||||
for _, master := range masters {
|
for _, master := range masters {
|
||||||
err := broker.withMasterClient(master, func(client master_pb.SeaweedClient) error {
|
err := broker.withMasterClient(master, func(client master_pb.SeaweedClient) error {
|
||||||
resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
|
resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
|
||||||
ClientType: "filer",
|
ClientType: cluster.FilerType,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -104,7 +104,7 @@ func NewMasterServer(r *mux.Router, option *MasterOption, peers []pb.ServerAddre
|
||||||
vgCh: make(chan *topology.VolumeGrowRequest, 1<<6),
|
vgCh: make(chan *topology.VolumeGrowRequest, 1<<6),
|
||||||
clientChans: make(map[string]chan *master_pb.KeepConnectedResponse),
|
clientChans: make(map[string]chan *master_pb.KeepConnectedResponse),
|
||||||
grpcDialOption: grpcDialOption,
|
grpcDialOption: grpcDialOption,
|
||||||
MasterClient: wdclient.NewMasterClient(grpcDialOption, "master", option.Master, "", peers),
|
MasterClient: wdclient.NewMasterClient(grpcDialOption, cluster.MasterType, option.Master, "", peers),
|
||||||
adminLocks: NewAdminLocks(),
|
adminLocks: NewAdminLocks(),
|
||||||
Cluster: cluster.NewCluster(),
|
Cluster: cluster.NewCluster(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/cluster"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
||||||
|
@ -37,7 +38,7 @@ func (c *commandClusterPs) Do(args []string, commandEnv *CommandEnv, writer io.W
|
||||||
|
|
||||||
err = commandEnv.MasterClient.WithClient(func(client master_pb.SeaweedClient) error {
|
err = commandEnv.MasterClient.WithClient(func(client master_pb.SeaweedClient) error {
|
||||||
resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
|
resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
|
||||||
ClientType: "filer",
|
ClientType: cluster.FilerType,
|
||||||
})
|
})
|
||||||
|
|
||||||
fmt.Fprintf(writer, "the cluster has %d filers\n", len(resp.ClusterNodes))
|
fmt.Fprintf(writer, "the cluster has %d filers\n", len(resp.ClusterNodes))
|
||||||
|
|
|
@ -3,6 +3,7 @@ package shell
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/cluster"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb"
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
||||||
|
@ -54,7 +55,7 @@ func RunShell(options ShellOptions) {
|
||||||
var filers []pb.ServerAddress
|
var filers []pb.ServerAddress
|
||||||
commandEnv.MasterClient.WithClient(func(client master_pb.SeaweedClient) error {
|
commandEnv.MasterClient.WithClient(func(client master_pb.SeaweedClient) error {
|
||||||
resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
|
resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
|
||||||
ClientType: "filer",
|
ClientType: cluster.FilerType,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue