Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

refactoring

Chris Lud84c31169922
diff --git a/weed/command/shell.go b/weed/command/shell.go
index c9976e809d..4a9f4b027c 100644
--- a/weed/command/shell.go
+++ b/weed/command/shell.go
@@ -55,6 +55,7 @@ func runShell(command *Command, args []string) bool {
var err error
shellOptions.FilerHost, shellOptions.FilerPort, err = util.ParseHostPort(*shellInitialFiler)
+ shellOptions.FilerAddress = *shellInitialFiler
if err != nil {
fmt.Printf("failed to parse filer %s: %v\n", *shellInitialFiler, err)
return false
diff --git a/weed/remote_storage/mount_mapping.go b/weed/remote_storage/mount_mapping.go
new file mode 100644
index 0000000000..65e7be362b
--- /dev/null
+++ b/weed/remote_storage/mount_mapping.go
@@ -0,0 +1,26 @@
+package remote_storage
+
+import (
+ "fmt"
+ "github.com/chrislusf/seaweedfs/weed/filer"
+ "github.com/chrislusf/seaweedfs/weed/pb"
+ "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
+ "google.golang.org/grpc"
+)
+
+func ReadMountMappings(grpcDialOption grpc.DialOption, filerAddress string) (mappings *filer_pb.RemoteStorageMapping, readErr error) {
+ var oldContent []byte
+ if readErr = pb.WithFilerClient(filerAddress, grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
+ oldContent, readErr = filer.ReadInsideFiler(client, filer.DirectoryEtcRemote, filer.REMOTE_STORAGE_MOUNT_FILE)
+ return readErr
+ }); readErr != nil {
+ return nil, readErr
+ }
+
+ mappings, readErr = filer.UnmarshalRemoteStorageMappings(oldContent)
+ if readErr != nil {
+ return nil, fmt.Errorf("unmarshal mappings: %v", readErr)
+ }
+
+ return
+}
diff --git a/weed/server/master_server.go b/weed/server/master_server.go
index 9d222a342e..a23ad0698e 100644
--- a/weed/server/master_server.go
+++ b/weed/server/master_server.go
@@ -228,6 +228,7 @@ func (ms *MasterServer) startAdminScripts() {
shellOptions.Masters = &masterAddress
shellOptions.FilerHost, shellOptions.FilerPort, err = util.ParseHostPort(filerHostPort)
+ shellOptions.FilerAddress = filerHostPort
shellOptions.Directory = "/"
if err != nil {
glog.V(0).Infof("failed to parse master.filer.default = %s : %v\n", filerHostPort, err)
diff --git a/weed/shell/command_remote_mount.go b/weed/shell/command_remote_mount.go
index 55dfb42ca8..5cd69f3b0b 100644
--- a/weed/shell/command_remote_mount.go
+++ b/weed/shell/command_remote_mount.go
@@ -79,20 +79,9 @@ func (c *commandRemoteMount) Do(args []string, commandEnv *CommandEnv, writer io
func (c *commandRemoteMount) listExistingRemoteStorageMounts(commandEnv *CommandEnv, writer io.Writer) (err error) {
// read current mapping
- var oldContent []byte
- err = commandEnv.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)
- }
- }
-
- mappings, unmarshalErr := filer.UnmarshalRemoteStorageMappings(oldContent)
- if unmarshalErr != nil {
- return unmarshalErr
+ mappings, readErr := remote_storage.ReadMountMappings(commandEnv.option.GrpcDialOption, commandEnv.option.FilerAddress)
+ if readErr != nil {
+ return readErr
}
m := jsonpb.Marshaler{
diff --git a/weed/shell/commands.go b/weed/shell/commands.go
index 0e285214bf..5b78f1ff90 100644
--- a/weed/shell/commands.go
+++ b/weed/shell/commands.go
@@ -20,9 +20,10 @@ type ShellOptions struct {
Masters *string
GrpcDialOption grpc.DialOption
// shell transient context
- FilerHost string
- FilerPort int64
- Directory string
+ FilerHost string
+ FilerPort int64
+ FilerAddress string
+ Directory string
}
type CommandEnv struct {