2021-07-29 13:43:12 +08:00
|
|
|
package filer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-07-29 17:08:55 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2021-07-29 13:43:12 +08:00
|
|
|
)
|
|
|
|
|
2021-08-01 14:52:09 +08:00
|
|
|
func (entry *Entry) IsInRemoteOnly() bool {
|
2021-07-29 13:43:12 +08:00
|
|
|
return len(entry.Chunks) == 0 && entry.Remote != nil && entry.Remote.Size > 0
|
|
|
|
}
|
|
|
|
|
2021-08-01 13:39:38 +08:00
|
|
|
func (f *Filer) ReadRemote(entry *Entry, offset int64, size int64) (data[]byte, err error) {
|
2021-07-29 17:08:55 +08:00
|
|
|
client, _, found := f.RemoteStorage.GetRemoteStorageClient(entry.Remote.StorageName)
|
2021-07-29 13:43:12 +08:00
|
|
|
if !found {
|
2021-08-01 13:39:38 +08:00
|
|
|
return nil, fmt.Errorf("remote storage %v not found", entry.Remote.StorageName)
|
2021-07-29 13:43:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
mountDir, remoteLoation := f.RemoteStorage.FindMountDirectory(entry.FullPath)
|
|
|
|
|
2021-07-29 17:08:55 +08:00
|
|
|
remoteFullPath := remoteLoation.Path + string(entry.FullPath[len(mountDir):])
|
2021-07-29 13:43:12 +08:00
|
|
|
|
2021-07-29 17:08:55 +08:00
|
|
|
sourceLoc := &filer_pb.RemoteStorageLocation{
|
|
|
|
Name: remoteLoation.Name,
|
|
|
|
Bucket: remoteLoation.Bucket,
|
|
|
|
Path: remoteFullPath,
|
|
|
|
}
|
2021-07-29 13:43:12 +08:00
|
|
|
|
2021-08-01 13:39:38 +08:00
|
|
|
return client.ReadFile(sourceLoc, offset, size)
|
2021-07-29 13:43:12 +08:00
|
|
|
}
|