read_remote.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package filer
  2. import (
  3. "context"
  4. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  5. "github.com/seaweedfs/seaweedfs/weed/pb/remote_pb"
  6. "github.com/seaweedfs/seaweedfs/weed/util"
  7. )
  8. func (entry *Entry) IsInRemoteOnly() bool {
  9. return len(entry.GetChunks()) == 0 && entry.Remote != nil && entry.Remote.RemoteSize > 0
  10. }
  11. func MapFullPathToRemoteStorageLocation(localMountedDir util.FullPath, remoteMountedLocation *remote_pb.RemoteStorageLocation, fp util.FullPath) *remote_pb.RemoteStorageLocation {
  12. remoteLocation := &remote_pb.RemoteStorageLocation{
  13. Name: remoteMountedLocation.Name,
  14. Bucket: remoteMountedLocation.Bucket,
  15. Path: remoteMountedLocation.Path,
  16. }
  17. remoteLocation.Path = string(util.FullPath(remoteLocation.Path).Child(string(fp)[len(localMountedDir):]))
  18. return remoteLocation
  19. }
  20. func MapRemoteStorageLocationPathToFullPath(localMountedDir util.FullPath, remoteMountedLocation *remote_pb.RemoteStorageLocation, remoteLocationPath string) (fp util.FullPath) {
  21. return localMountedDir.Child(remoteLocationPath[len(remoteMountedLocation.Path):])
  22. }
  23. func CacheRemoteObjectToLocalCluster(filerClient filer_pb.FilerClient, remoteConf *remote_pb.RemoteConf, remoteLocation *remote_pb.RemoteStorageLocation, parent util.FullPath, entry *filer_pb.Entry) error {
  24. return filerClient.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
  25. _, err := client.CacheRemoteObjectToLocalCluster(context.Background(), &filer_pb.CacheRemoteObjectToLocalClusterRequest{
  26. Directory: string(parent),
  27. Name: entry.Name,
  28. })
  29. return err
  30. })
  31. }