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.

72 lines
1.8 KiB

3 years ago
3 years ago
  1. package broker
  2. import (
  3. "context"
  4. "github.com/chrislusf/seaweedfs/weed/cluster"
  5. "github.com/chrislusf/seaweedfs/weed/pb"
  6. "time"
  7. "github.com/chrislusf/seaweedfs/weed/glog"
  8. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  9. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  10. )
  11. func (broker *MessageQueueBroker) checkFilers() {
  12. // contact a filer about masters
  13. var masters []pb.ServerAddress
  14. found := false
  15. for !found {
  16. for _, filer := range broker.option.Filers {
  17. err := broker.withFilerClient(false, filer, func(client filer_pb.SeaweedFilerClient) error {
  18. resp, err := client.GetFilerConfiguration(context.Background(), &filer_pb.GetFilerConfigurationRequest{})
  19. if err != nil {
  20. return err
  21. }
  22. for _, m := range resp.Masters {
  23. masters = append(masters, pb.ServerAddress(m))
  24. }
  25. return nil
  26. })
  27. if err == nil {
  28. found = true
  29. break
  30. }
  31. glog.V(0).Infof("failed to read masters from %+v: %v", broker.option.Filers, err)
  32. time.Sleep(time.Second)
  33. }
  34. }
  35. glog.V(0).Infof("received master list: %s", masters)
  36. // contact each masters for filers
  37. var filers []pb.ServerAddress
  38. found = false
  39. for !found {
  40. for _, master := range masters {
  41. err := broker.withMasterClient(false, master, func(client master_pb.SeaweedClient) error {
  42. resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
  43. ClientType: cluster.FilerType,
  44. })
  45. if err != nil {
  46. return err
  47. }
  48. for _, clusterNode := range resp.ClusterNodes {
  49. filers = append(filers, pb.ServerAddress(clusterNode.Address))
  50. }
  51. return nil
  52. })
  53. if err == nil {
  54. found = true
  55. break
  56. }
  57. glog.V(0).Infof("failed to list filers: %v", err)
  58. time.Sleep(time.Second)
  59. }
  60. }
  61. glog.V(0).Infof("received filer list: %s", filers)
  62. broker.option.Filers = filers
  63. }