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.

51 lines
1.2 KiB

3 years ago
3 years ago
3 years ago
  1. package mount
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/glog"
  4. "github.com/seaweedfs/seaweedfs/weed/util"
  5. "google.golang.org/grpc"
  6. "github.com/seaweedfs/seaweedfs/weed/pb"
  7. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  8. )
  9. var _ = filer_pb.FilerClient(&WFS{})
  10. func (wfs *WFS) WithFilerClient(streamingMode bool, fn func(filer_pb.SeaweedFilerClient) error) (err error) {
  11. return util.Retry("filer grpc", func() error {
  12. i := wfs.option.filerIndex
  13. n := len(wfs.option.FilerAddresses)
  14. for x := 0; x < n; x++ {
  15. filerGrpcAddress := wfs.option.FilerAddresses[i].ToGrpcAddress()
  16. err = pb.WithGrpcClient(streamingMode, func(grpcConnection *grpc.ClientConn) error {
  17. client := filer_pb.NewSeaweedFilerClient(grpcConnection)
  18. return fn(client)
  19. }, filerGrpcAddress, wfs.option.GrpcDialOption)
  20. if err != nil {
  21. glog.V(0).Infof("WithFilerClient %d %v: %v", x, filerGrpcAddress, err)
  22. } else {
  23. wfs.option.filerIndex = i
  24. return nil
  25. }
  26. i++
  27. if i >= n {
  28. i = 0
  29. }
  30. }
  31. return err
  32. })
  33. }
  34. func (wfs *WFS) AdjustedUrl(location *filer_pb.Location) string {
  35. if wfs.option.VolumeServerAccess == "publicUrl" {
  36. return location.PublicUrl
  37. }
  38. return location.Url
  39. }