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.

de/compress the fs meta file if filename ends with gz/gzip (#7500)

Feng Shao0299e78de7c7
diff --git a/weed/shell/command_fs_meta_load.go b/weed/shell/command_fs_meta_load.go
index f43574f499..c2e01dfc2b 100644
--- a/weed/shell/command_fs_meta_load.go
+++ b/weed/shell/command_fs_meta_load.go
@@ -1,6 +1,7 @@
package shell
import (
+ "compress/gzip"
"context"
"flag"
"fmt"
@@ -60,11 +61,31 @@ func (c *commandFsMetaLoad) Do(args []string, commandEnv *CommandEnv, writer io.
return nil
}
- dst, err := os.OpenFile(fileName, os.O_RDONLY, 0644)
+ var dst io.Reader
+
+ f, err := os.OpenFile(fileName, os.O_RDONLY, 0644)
if err != nil {
- return nil
+ return fmt.Errorf("failed to open file %s: %v", fileName, err)
+ }
+ defer f.Close()
+
+ dst = f
+
+ if strings.HasSuffix(fileName, ".gz") || strings.HasSuffix(fileName, ".gzip") {
+ var gr *gzip.Reader
+ gr, err = gzip.NewReader(dst)
+ if err != nil {
+ return err
+ }
+ defer func() {
+ err1 := gr.Close()
+ if err == nil {
+ err = err1
+ }
+ }()
+
+ dst = gr
}
- defer dst.Close()
var dirCount, fileCount uint64
lastLogTime := time.Now()
diff --git a/weed/shell/command_fs_meta_save.go b/weed/shell/command_fs_meta_save.go
index a8be9fe2cf..ce982820dd 100644
--- a/weed/shell/command_fs_meta_save.go
+++ b/weed/shell/command_fs_meta_save.go
@@ -1,9 +1,9 @@
package shell
import (
+ "compress/gzip"
"flag"
"fmt"
- "github.com/seaweedfs/seaweedfs/weed/filer"
"io"
"os"
"path/filepath"
@@ -12,6 +12,8 @@ import (
"sync/atomic"
"time"
+ "github.com/seaweedfs/seaweedfs/weed/filer"
+
"google.golang.org/protobuf/proto"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
@@ -38,7 +40,7 @@ func (c *commandFsMetaSave) Help() string {
fs.meta.save . # save from current directory
fs.meta.save # save from current directory
- The meta data will be saved into a local <filer_host>-<port>-<time>.meta file.
+ The meta data will be saved into a local <filer_host>-<port>-<time>.meta.gz file.
These meta data can be later loaded by fs.meta.load command
`
@@ -52,7 +54,7 @@ func (c *commandFsMetaSave) Do(args []string, commandEnv *CommandEnv, writer io.
fsMetaSaveCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
verbose := fsMetaSaveCommand.Bool("v", false, "print out each processed files")
- outputFileName := fsMetaSaveCommand.String("o", "", "output the meta data to this file")
+ outputFileName := fsMetaSaveCommand.String("o", "", "output the meta data to this file. If file name ends with .gz or .gzip, it will be gzip compressed")
isObfuscate := fsMetaSaveCommand.Bool("obfuscate", false, "obfuscate the file names")
// chunksFileName := fsMetaSaveCommand.String("chunks", "", "output all the chunks to this file")
if err = fsMetaSaveCommand.Parse(args); err != nil {
@@ -67,15 +69,31 @@ func (c *commandFsMetaSave) Do(args []string, commandEnv *CommandEnv, writer io.
fileName := *outputFileName
if fileName == "" {
t := time.Now()
- fileName = fmt.Sprintf("%s-%4d%02d%02d-%02d%02d%02d.meta",
+ fileName = fmt.Sprintf("%s-%4d%02d%02d-%02d%02d%02d.meta.gz",
commandEnv.option.FilerAddress.ToHttpAddress(), t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
}
- dst, openErr := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
+ var dst io.Writer
+
+ f, openErr := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if openErr != nil {
return fmt.Errorf("failed to create file %s: %v", fileName, openErr)
}
- defer dst.Close()
+ defer f.Close()
+
+ dst = f
+
+ if strings.HasSuffix(fileName, ".gz") || strings.HasSuffix(fileName, ".gzip") {
+ gw := gzip.NewWriter(dst)
+ defer func() {
+ err1 := gw.Close()
+ if err == nil {
+ err = err1
+ }
+ }()
+
+ dst = gw
+ }
var cipherKey util.CipherKey
if *isObfuscate {