chrislu
2 years ago
6 changed files with 72 additions and 128 deletions
-
34weed/cluster/master_client.go
-
30weed/command/mq_broker.go
-
1weed/command/server.go
-
23weed/filer/filer.go
-
72weed/mq/broker/broker_grpc_server_discovery.go
-
40weed/mq/broker/broker_server.go
@ -0,0 +1,34 @@ |
|||
package cluster |
|||
|
|||
import ( |
|||
"context" |
|||
"github.com/chrislusf/seaweedfs/weed/glog" |
|||
"github.com/chrislusf/seaweedfs/weed/pb" |
|||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb" |
|||
"google.golang.org/grpc" |
|||
) |
|||
|
|||
func ListExistingPeerUpdates(master pb.ServerAddress, grpcDialOption grpc.DialOption, filerGroup string, clientType string) (existingNodes []*master_pb.ClusterNodeUpdate) { |
|||
|
|||
if grpcErr := pb.WithMasterClient(false, master, grpcDialOption, func(client master_pb.SeaweedClient) error { |
|||
resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{ |
|||
ClientType: clientType, |
|||
FilerGroup: filerGroup, |
|||
}) |
|||
|
|||
glog.V(0).Infof("the cluster has %d %s\n", len(resp.ClusterNodes), clientType) |
|||
for _, node := range resp.ClusterNodes { |
|||
existingNodes = append(existingNodes, &master_pb.ClusterNodeUpdate{ |
|||
NodeType: FilerType, |
|||
Address: node.Address, |
|||
IsLeader: node.IsLeader, |
|||
IsAdd: true, |
|||
CreatedAtNs: node.CreatedAtNs, |
|||
}) |
|||
} |
|||
return err |
|||
}); grpcErr != nil { |
|||
glog.V(0).Infof("connect to %s: %v", master, grpcErr) |
|||
} |
|||
return |
|||
} |
@ -1,72 +0,0 @@ |
|||
package broker |
|||
|
|||
import ( |
|||
"context" |
|||
"github.com/chrislusf/seaweedfs/weed/cluster" |
|||
"github.com/chrislusf/seaweedfs/weed/pb" |
|||
"time" |
|||
|
|||
"github.com/chrislusf/seaweedfs/weed/glog" |
|||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" |
|||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb" |
|||
) |
|||
|
|||
func (broker *MessageQueueBroker) checkFilers() { |
|||
|
|||
// contact a filer about masters
|
|||
var masters []pb.ServerAddress |
|||
found := false |
|||
for !found { |
|||
for _, filer := range broker.option.Filers { |
|||
err := broker.withFilerClient(false, filer, func(client filer_pb.SeaweedFilerClient) error { |
|||
resp, err := client.GetFilerConfiguration(context.Background(), &filer_pb.GetFilerConfigurationRequest{}) |
|||
if err != nil { |
|||
return err |
|||
} |
|||
for _, m := range resp.Masters { |
|||
masters = append(masters, pb.ServerAddress(m)) |
|||
} |
|||
return nil |
|||
}) |
|||
if err == nil { |
|||
found = true |
|||
break |
|||
} |
|||
glog.V(0).Infof("failed to read masters from %+v: %v", broker.option.Filers, err) |
|||
time.Sleep(time.Second) |
|||
} |
|||
} |
|||
glog.V(0).Infof("received master list: %s", masters) |
|||
|
|||
// contact each masters for filers
|
|||
var filers []pb.ServerAddress |
|||
found = false |
|||
for !found { |
|||
for _, master := range masters { |
|||
err := broker.withMasterClient(false, master, func(client master_pb.SeaweedClient) error { |
|||
resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{ |
|||
ClientType: cluster.FilerType, |
|||
}) |
|||
if err != nil { |
|||
return err |
|||
} |
|||
|
|||
for _, clusterNode := range resp.ClusterNodes { |
|||
filers = append(filers, pb.ServerAddress(clusterNode.Address)) |
|||
} |
|||
|
|||
return nil |
|||
}) |
|||
if err == nil { |
|||
found = true |
|||
break |
|||
} |
|||
glog.V(0).Infof("failed to list filers: %v", err) |
|||
time.Sleep(time.Second) |
|||
} |
|||
} |
|||
glog.V(0).Infof("received filer list: %s", filers) |
|||
|
|||
broker.option.Filers = filers |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue