2021-07-29 13:43:12 +08:00
|
|
|
package filer
|
|
|
|
|
|
|
|
import (
|
2021-08-10 05:35:18 +08:00
|
|
|
"context"
|
2021-07-29 17:08:55 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2021-08-27 06:18:34 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/remote_pb"
|
2021-08-10 05:35:18 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2021-07-29 13:43:12 +08:00
|
|
|
)
|
|
|
|
|
2021-08-01 14:52:09 +08:00
|
|
|
func (entry *Entry) IsInRemoteOnly() bool {
|
2021-08-10 05:35:18 +08:00
|
|
|
return len(entry.Chunks) == 0 && entry.Remote != nil && entry.Remote.RemoteSize > 0
|
2021-07-29 13:43:12 +08:00
|
|
|
}
|
|
|
|
|
2021-08-27 06:18:34 +08:00
|
|
|
func MapFullPathToRemoteStorageLocation(localMountedDir util.FullPath, remoteMountedLocation *remote_pb.RemoteStorageLocation, fp util.FullPath) *remote_pb.RemoteStorageLocation {
|
|
|
|
remoteLocation := &remote_pb.RemoteStorageLocation{
|
2021-08-10 05:35:18 +08:00
|
|
|
Name: remoteMountedLocation.Name,
|
|
|
|
Bucket: remoteMountedLocation.Bucket,
|
|
|
|
Path: remoteMountedLocation.Path,
|
2021-07-29 17:08:55 +08:00
|
|
|
}
|
2021-08-15 16:53:46 +08:00
|
|
|
remoteLocation.Path = string(util.FullPath(remoteLocation.Path).Child(string(fp)[len(localMountedDir):]))
|
2021-08-10 05:35:18 +08:00
|
|
|
return remoteLocation
|
|
|
|
}
|
2021-07-29 13:43:12 +08:00
|
|
|
|
2021-09-01 17:45:42 +08:00
|
|
|
func MapRemoteStorageLocationPathToFullPath(localMountedDir util.FullPath, remoteMountedLocation *remote_pb.RemoteStorageLocation, remoteLocationPath string) (fp util.FullPath) {
|
2021-08-15 16:53:46 +08:00
|
|
|
return localMountedDir.Child(remoteLocationPath[len(remoteMountedLocation.Path):])
|
|
|
|
}
|
|
|
|
|
2021-10-31 10:27:25 +08:00
|
|
|
func CacheRemoteObjectToLocalCluster(filerClient filer_pb.FilerClient, remoteConf *remote_pb.RemoteConf, remoteLocation *remote_pb.RemoteStorageLocation, parent util.FullPath, entry *filer_pb.Entry) error {
|
2021-12-26 16:15:03 +08:00
|
|
|
return filerClient.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
2021-10-31 10:27:25 +08:00
|
|
|
_, err := client.CacheRemoteObjectToLocalCluster(context.Background(), &filer_pb.CacheRemoteObjectToLocalClusterRequest{
|
2021-08-10 05:35:18 +08:00
|
|
|
Directory: string(parent),
|
|
|
|
Name: entry.Name,
|
|
|
|
})
|
|
|
|
return err
|
|
|
|
})
|
2021-07-29 13:43:12 +08:00
|
|
|
}
|