|
@@ -4,6 +4,7 @@ import (
|
|
|
"context"
|
|
|
"fmt"
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
|
|
+ "github.com/chrislusf/seaweedfs/weed/pb/remote_pb"
|
|
|
"github.com/chrislusf/seaweedfs/weed/remote_storage"
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
|
|
"github.com/golang/protobuf/proto"
|
|
@@ -21,13 +22,13 @@ const REMOTE_STORAGE_MOUNT_FILE = "mount.mapping"
|
|
|
|
|
|
type FilerRemoteStorage struct {
|
|
|
rules ptrie.Trie
|
|
|
- storageNameToConf map[string]*filer_pb.RemoteConf
|
|
|
+ storageNameToConf map[string]*remote_pb.RemoteConf
|
|
|
}
|
|
|
|
|
|
func NewFilerRemoteStorage() (rs *FilerRemoteStorage) {
|
|
|
rs = &FilerRemoteStorage{
|
|
|
rules: ptrie.New(),
|
|
|
- storageNameToConf: make(map[string]*filer_pb.RemoteConf),
|
|
|
+ storageNameToConf: make(map[string]*remote_pb.RemoteConf),
|
|
|
}
|
|
|
return rs
|
|
|
}
|
|
@@ -56,7 +57,7 @@ func (rs *FilerRemoteStorage) LoadRemoteStorageConfigurationsAndMapping(filer *F
|
|
|
if !strings.HasSuffix(entry.Name(), REMOTE_STORAGE_CONF_SUFFIX) {
|
|
|
return nil
|
|
|
}
|
|
|
- conf := &filer_pb.RemoteConf{}
|
|
|
+ conf := &remote_pb.RemoteConf{}
|
|
|
if err := proto.Unmarshal(entry.Content, conf); err != nil {
|
|
|
return fmt.Errorf("unmarshal %s/%s: %v", DirectoryEtcRemote, entry.Name(), err)
|
|
|
}
|
|
@@ -66,7 +67,7 @@ func (rs *FilerRemoteStorage) LoadRemoteStorageConfigurationsAndMapping(filer *F
|
|
|
}
|
|
|
|
|
|
func (rs *FilerRemoteStorage) loadRemoteStorageMountMapping(data []byte) (err error) {
|
|
|
- mappings := &filer_pb.RemoteStorageMapping{}
|
|
|
+ mappings := &remote_pb.RemoteStorageMapping{}
|
|
|
if err := proto.Unmarshal(data, mappings); err != nil {
|
|
|
return fmt.Errorf("unmarshal %s/%s: %v", DirectoryEtcRemote, REMOTE_STORAGE_MOUNT_FILE, err)
|
|
|
}
|
|
@@ -76,23 +77,23 @@ func (rs *FilerRemoteStorage) loadRemoteStorageMountMapping(data []byte) (err er
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (rs *FilerRemoteStorage) mapDirectoryToRemoteStorage(dir util.FullPath, loc *filer_pb.RemoteStorageLocation) {
|
|
|
+func (rs *FilerRemoteStorage) mapDirectoryToRemoteStorage(dir util.FullPath, loc *remote_pb.RemoteStorageLocation) {
|
|
|
rs.rules.Put([]byte(dir+"/"), loc)
|
|
|
}
|
|
|
|
|
|
-func (rs *FilerRemoteStorage) FindMountDirectory(p util.FullPath) (mountDir util.FullPath, remoteLocation *filer_pb.RemoteStorageLocation) {
|
|
|
+func (rs *FilerRemoteStorage) FindMountDirectory(p util.FullPath) (mountDir util.FullPath, remoteLocation *remote_pb.RemoteStorageLocation) {
|
|
|
rs.rules.MatchPrefix([]byte(p), func(key []byte, value interface{}) bool {
|
|
|
mountDir = util.FullPath(string(key[:len(key)-1]))
|
|
|
- remoteLocation = value.(*filer_pb.RemoteStorageLocation)
|
|
|
+ remoteLocation = value.(*remote_pb.RemoteStorageLocation)
|
|
|
return true
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func (rs *FilerRemoteStorage) FindRemoteStorageClient(p util.FullPath) (client remote_storage.RemoteStorageClient, remoteConf *filer_pb.RemoteConf, found bool) {
|
|
|
- var storageLocation *filer_pb.RemoteStorageLocation
|
|
|
+func (rs *FilerRemoteStorage) FindRemoteStorageClient(p util.FullPath) (client remote_storage.RemoteStorageClient, remoteConf *remote_pb.RemoteConf, found bool) {
|
|
|
+ var storageLocation *remote_pb.RemoteStorageLocation
|
|
|
rs.rules.MatchPrefix([]byte(p), func(key []byte, value interface{}) bool {
|
|
|
- storageLocation = value.(*filer_pb.RemoteStorageLocation)
|
|
|
+ storageLocation = value.(*remote_pb.RemoteStorageLocation)
|
|
|
return true
|
|
|
})
|
|
|
|
|
@@ -104,7 +105,7 @@ func (rs *FilerRemoteStorage) FindRemoteStorageClient(p util.FullPath) (client r
|
|
|
return rs.GetRemoteStorageClient(storageLocation.Name)
|
|
|
}
|
|
|
|
|
|
-func (rs *FilerRemoteStorage) GetRemoteStorageClient(storageName string) (client remote_storage.RemoteStorageClient, remoteConf *filer_pb.RemoteConf, found bool) {
|
|
|
+func (rs *FilerRemoteStorage) GetRemoteStorageClient(storageName string) (client remote_storage.RemoteStorageClient, remoteConf *remote_pb.RemoteConf, found bool) {
|
|
|
remoteConf, found = rs.storageNameToConf[storageName]
|
|
|
if !found {
|
|
|
return
|
|
@@ -118,9 +119,9 @@ func (rs *FilerRemoteStorage) GetRemoteStorageClient(storageName string) (client
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func UnmarshalRemoteStorageMappings(oldContent []byte) (mappings *filer_pb.RemoteStorageMapping, err error) {
|
|
|
- mappings = &filer_pb.RemoteStorageMapping{
|
|
|
- Mappings: make(map[string]*filer_pb.RemoteStorageLocation),
|
|
|
+func UnmarshalRemoteStorageMappings(oldContent []byte) (mappings *remote_pb.RemoteStorageMapping, err error) {
|
|
|
+ mappings = &remote_pb.RemoteStorageMapping{
|
|
|
+ Mappings: make(map[string]*remote_pb.RemoteStorageLocation),
|
|
|
}
|
|
|
if len(oldContent) > 0 {
|
|
|
if err = proto.Unmarshal(oldContent, mappings); err != nil {
|
|
@@ -130,7 +131,7 @@ func UnmarshalRemoteStorageMappings(oldContent []byte) (mappings *filer_pb.Remot
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func AddRemoteStorageMapping(oldContent []byte, dir string, storageLocation *filer_pb.RemoteStorageLocation) (newContent []byte, err error) {
|
|
|
+func AddRemoteStorageMapping(oldContent []byte, dir string, storageLocation *remote_pb.RemoteStorageLocation) (newContent []byte, err error) {
|
|
|
mappings, unmarshalErr := UnmarshalRemoteStorageMappings(oldContent)
|
|
|
if unmarshalErr != nil {
|
|
|
// skip
|
|
@@ -162,7 +163,7 @@ func RemoveRemoteStorageMapping(oldContent []byte, dir string) (newContent []byt
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func ReadMountMappings(grpcDialOption grpc.DialOption, filerAddress string) (mappings *filer_pb.RemoteStorageMapping, readErr error) {
|
|
|
+func ReadMountMappings(grpcDialOption grpc.DialOption, filerAddress string) (mappings *remote_pb.RemoteStorageMapping, readErr error) {
|
|
|
var oldContent []byte
|
|
|
if readErr = pb.WithFilerClient(filerAddress, grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
|
|
oldContent, readErr = ReadInsideFiler(client, DirectoryEtcRemote, REMOTE_STORAGE_MOUNT_FILE)
|
|
@@ -179,7 +180,7 @@ func ReadMountMappings(grpcDialOption grpc.DialOption, filerAddress string) (map
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func ReadRemoteStorageConf(grpcDialOption grpc.DialOption, filerAddress string, storageName string) (conf *filer_pb.RemoteConf, readErr error) {
|
|
|
+func ReadRemoteStorageConf(grpcDialOption grpc.DialOption, filerAddress string, storageName string) (conf *remote_pb.RemoteConf, readErr error) {
|
|
|
var oldContent []byte
|
|
|
if readErr = pb.WithFilerClient(filerAddress, grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
|
|
oldContent, readErr = ReadInsideFiler(client, DirectoryEtcRemote, storageName+REMOTE_STORAGE_CONF_SUFFIX)
|
|
@@ -189,7 +190,7 @@ func ReadRemoteStorageConf(grpcDialOption grpc.DialOption, filerAddress string,
|
|
|
}
|
|
|
|
|
|
// unmarshal storage configuration
|
|
|
- conf = &filer_pb.RemoteConf{}
|
|
|
+ conf = &remote_pb.RemoteConf{}
|
|
|
if unMarshalErr := proto.Unmarshal(oldContent, conf); unMarshalErr != nil {
|
|
|
readErr = fmt.Errorf("unmarshal %s/%s: %v", DirectoryEtcRemote, storageName+REMOTE_STORAGE_CONF_SUFFIX, unMarshalErr)
|
|
|
return
|
|
@@ -198,7 +199,7 @@ func ReadRemoteStorageConf(grpcDialOption grpc.DialOption, filerAddress string,
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func DetectMountInfo(grpcDialOption grpc.DialOption, filerAddress string, dir string) (*filer_pb.RemoteStorageMapping, string, *filer_pb.RemoteStorageLocation, *filer_pb.RemoteConf, error) {
|
|
|
+func DetectMountInfo(grpcDialOption grpc.DialOption, filerAddress string, dir string) (*remote_pb.RemoteStorageMapping, string, *remote_pb.RemoteStorageLocation, *remote_pb.RemoteConf, error) {
|
|
|
|
|
|
mappings, listErr := ReadMountMappings(grpcDialOption, filerAddress)
|
|
|
if listErr != nil {
|
|
@@ -209,7 +210,7 @@ func DetectMountInfo(grpcDialOption grpc.DialOption, filerAddress string, dir st
|
|
|
}
|
|
|
|
|
|
var localMountedDir string
|
|
|
- var remoteStorageMountedLocation *filer_pb.RemoteStorageLocation
|
|
|
+ var remoteStorageMountedLocation *remote_pb.RemoteStorageLocation
|
|
|
for k, loc := range mappings.Mappings {
|
|
|
if strings.HasPrefix(dir, k) {
|
|
|
localMountedDir, remoteStorageMountedLocation = k, loc
|