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.

remote.cache remote.uncache supports all mounted directories

Chris Lu57a95887d237
diff --git a/weed/shell/command_remote_cache.go b/weed/shell/command_remote_cache.go
index 51f1706667..58b6d7b5e7 100644
--- a/weed/shell/command_remote_cache.go
+++ b/weed/shell/command_remote_cache.go
@@ -50,7 +50,7 @@ func (c *commandRemoteCache) Do(args []string, commandEnv *CommandEnv, writer io
remoteMountCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
- dir := remoteMountCommand.String("dir", "", "a directory in filer")
+ dir := remoteMountCommand.String("dir", "", "a mounted directory or one of its sub folders in filer")
concurrency := remoteMountCommand.Int("concurrent", 32, "concurrent file downloading")
fileFiler := newFileFilter(remoteMountCommand)
@@ -58,15 +58,37 @@ func (c *commandRemoteCache) Do(args []string, commandEnv *CommandEnv, writer io
return nil
}
- mappings, localMountedDir, remoteStorageMountedLocation, remoteStorageConf, detectErr := detectMountInfo(commandEnv, writer, *dir)
+ if *dir != "" {
+ if err := c.doCacheOneDirectory(commandEnv, writer, *dir, fileFiler, *concurrency); err != nil {
+ return err
+ }
+ return nil
+ }
+
+ mappings, err := filer.ReadMountMappings(commandEnv.option.GrpcDialOption, commandEnv.option.FilerAddress)
+ if err != nil {
+ return err
+ }
+
+ for key, _ := range mappings.Mappings {
+ if err := c.doCacheOneDirectory(commandEnv, writer, key, fileFiler, *concurrency); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+func (c *commandRemoteCache) doCacheOneDirectory(commandEnv *CommandEnv, writer io.Writer, dir string, fileFiler *FileFilter, concurrency int) (error) {
+ mappings, localMountedDir, remoteStorageMountedLocation, remoteStorageConf, detectErr := detectMountInfo(commandEnv, writer, dir)
if detectErr != nil {
jsonPrintln(writer, mappings)
return detectErr
}
// pull content from remote
- if err = c.cacheContentData(commandEnv, writer, util.FullPath(localMountedDir), remoteStorageMountedLocation, util.FullPath(*dir), fileFiler, remoteStorageConf, *concurrency); err != nil {
- return fmt.Errorf("cache content data: %v", err)
+ if err := c.cacheContentData(commandEnv, writer, util.FullPath(localMountedDir), remoteStorageMountedLocation, util.FullPath(dir), fileFiler, remoteStorageConf, concurrency); err != nil {
+ return fmt.Errorf("cache content data on %s: %v", localMountedDir, err)
}
return nil
diff --git a/weed/shell/command_remote_uncache.go b/weed/shell/command_remote_uncache.go
index 77f3a25754..0d4e0cf7d1 100644
--- a/weed/shell/command_remote_uncache.go
+++ b/weed/shell/command_remote_uncache.go
@@ -54,27 +54,30 @@ func (c *commandRemoteUncache) Do(args []string, commandEnv *CommandEnv, writer
if listErr != nil {
return listErr
}
- if *dir == "" {
- jsonPrintln(writer, mappings)
- fmt.Fprintln(writer, "need to specify '-dir' option")
- return nil
- }
+ if *dir != "" {
+ var localMountedDir string
+ for k := range mappings.Mappings {
+ if strings.HasPrefix(*dir, k) {
+ localMountedDir = k
+ }
+ }
+ if localMountedDir == "" {
+ jsonPrintln(writer, mappings)
+ fmt.Fprintf(writer, "%s is not mounted\n", *dir)
+ return nil
+ }
- var localMountedDir string
- for k := range mappings.Mappings {
- if strings.HasPrefix(*dir, k) {
- localMountedDir = k
+ // pull content from remote
+ if err = c.uncacheContentData(commandEnv, writer, util.FullPath(*dir), fileFiler); err != nil {
+ return fmt.Errorf("uncache content data: %v", err)
}
- }
- if localMountedDir == "" {
- jsonPrintln(writer, mappings)
- fmt.Fprintf(writer, "%s is not mounted\n", *dir)
return nil
}
- // pull content from remote
- if err = c.uncacheContentData(commandEnv, writer, util.FullPath(*dir), fileFiler); err != nil {
- return fmt.Errorf("uncache content data: %v", err)
+ for key, _ := range mappings.Mappings {
+ if err := c.uncacheContentData(commandEnv, writer, util.FullPath(key), fileFiler); err != nil {
+ return err
+ }
}
return nil