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.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package filesys
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/glog"
  4. "github.com/chrislusf/seaweedfs/weed/util"
  5. "google.golang.org/grpc"
  6. "github.com/chrislusf/seaweedfs/weed/pb"
  7. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  8. )
  9. var _ = filer_pb.FilerClient(&WFS{})
  10. func (wfs *WFS) WithFilerClient(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.FilerGrpcAddresses)
  14. for x := 0; x < n; x++ {
  15. filerGrpcAddress := wfs.option.FilerGrpcAddresses[i]
  16. err = pb.WithCachedGrpcClient(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. }