wfs_filer_client.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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(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. }