mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
refactor
This commit is contained in:
parent
13cc2ef723
commit
8707ef00a6
38
weed/filer/remote_mapping.go
Normal file
38
weed/filer/remote_mapping.go
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
package filer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/pb/remote_pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SaveMountMapping(filerClient filer_pb.FilerClient, dir string, remoteStorageLocation *remote_pb.RemoteStorageLocation) (err error) {
|
||||||
|
|
||||||
|
// read current mapping
|
||||||
|
var oldContent, newContent []byte
|
||||||
|
err = filerClient.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||||
|
oldContent, err = ReadInsideFiler(client, DirectoryEtcRemote, REMOTE_STORAGE_MOUNT_FILE)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
if err != filer_pb.ErrNotFound {
|
||||||
|
return fmt.Errorf("read existing mapping: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add new mapping
|
||||||
|
newContent, err = AddRemoteStorageMapping(oldContent, dir, remoteStorageLocation)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("add mapping %s~%s: %v", dir, remoteStorageLocation, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// save back
|
||||||
|
err = filerClient.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||||
|
return SaveInsideFiler(client, DirectoryEtcRemote, REMOTE_STORAGE_MOUNT_FILE, newContent)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("save mapping: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -79,7 +79,7 @@ func (c *commandRemoteMount) Do(args []string, commandEnv *CommandEnv, writer io
|
||||||
}
|
}
|
||||||
|
|
||||||
// store a mount configuration in filer
|
// store a mount configuration in filer
|
||||||
if err = c.saveMountMapping(commandEnv, *dir, remoteStorageLocation); err != nil {
|
if err = filer.SaveMountMapping(commandEnv, *dir, remoteStorageLocation); err != nil {
|
||||||
return fmt.Errorf("save mount mapping: %v", err)
|
return fmt.Errorf("save mount mapping: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,36 +177,6 @@ func (c *commandRemoteMount) syncMetadata(commandEnv *CommandEnv, writer io.Writ
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *commandRemoteMount) saveMountMapping(filerClient filer_pb.FilerClient, dir string, remoteStorageLocation *remote_pb.RemoteStorageLocation) (err error) {
|
|
||||||
|
|
||||||
// read current mapping
|
|
||||||
var oldContent, newContent []byte
|
|
||||||
err = filerClient.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
|
||||||
oldContent, err = filer.ReadInsideFiler(client, filer.DirectoryEtcRemote, filer.REMOTE_STORAGE_MOUNT_FILE)
|
|
||||||
return err
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
if err != filer_pb.ErrNotFound {
|
|
||||||
return fmt.Errorf("read existing mapping: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add new mapping
|
|
||||||
newContent, err = filer.AddRemoteStorageMapping(oldContent, dir, remoteStorageLocation)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("add mapping %s~%s: %v", dir, remoteStorageLocation, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// save back
|
|
||||||
err = filerClient.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
|
||||||
return filer.SaveInsideFiler(client, filer.DirectoryEtcRemote, filer.REMOTE_STORAGE_MOUNT_FILE, newContent)
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("save mapping: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// if an entry has synchronized metadata but has not synchronized content
|
// if an entry has synchronized metadata but has not synchronized content
|
||||||
// entry.Attributes.FileSize == entry.RemoteEntry.RemoteSize
|
// entry.Attributes.FileSize == entry.RemoteEntry.RemoteSize
|
||||||
|
|
Loading…
Reference in a new issue