disable chunk file output

This commit is contained in:
Chris Lu 2020-03-24 00:08:02 -07:00
parent bb9b97e2b4
commit 443b229ef7

View file

@ -38,15 +38,6 @@ func (c *commandFsMetaSave) Help() string {
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 file.
These meta data can be later loaded by fs.meta.load command, These meta data can be later loaded by fs.meta.load command,
Another usage is to export all data chunk file ids used by the files.
fs.meta.save -chunks <filer.chunks>
The output chunks file will contain lines as:
<file key> <tab> <volumeId, fileKey, cookie> <tab> <file name>
This output chunks can be used to find out missing chunks or files.
` `
} }
@ -55,7 +46,7 @@ func (c *commandFsMetaSave) Do(args []string, commandEnv *CommandEnv, writer io.
fsMetaSaveCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) fsMetaSaveCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
verbose := fsMetaSaveCommand.Bool("v", false, "print out each processed files") 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")
chunksFileName := fsMetaSaveCommand.String("chunks", "", "output all the chunks to this file") // chunksFileName := fsMetaSaveCommand.String("chunks", "", "output all the chunks to this file")
if err = fsMetaSaveCommand.Parse(args); err != nil { if err = fsMetaSaveCommand.Parse(args); err != nil {
return nil return nil
} }
@ -72,7 +63,14 @@ func (c *commandFsMetaSave) Do(args []string, commandEnv *CommandEnv, writer io.
fileName = fmt.Sprintf("%s-%d-%4d%02d%02d-%02d%02d%02d.meta", fileName = fmt.Sprintf("%s-%d-%4d%02d%02d-%02d%02d%02d.meta",
commandEnv.option.FilerHost, commandEnv.option.FilerPort, t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second()) commandEnv.option.FilerHost, commandEnv.option.FilerPort, t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
} }
return doTraverseBfsAndSaving(fileName, commandEnv, writer, path, *verbose, func(dst io.Writer, outputChan chan []byte) {
dst, 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()
return doTraverseBfsAndSaving(commandEnv, writer, path, *verbose, func(dst io.Writer, outputChan chan []byte) {
sizeBuf := make([]byte, 4) sizeBuf := make([]byte, 4)
for b := range outputChan { for b := range outputChan {
util.Uint32toBytes(sizeBuf, uint32(len(b))) util.Uint32toBytes(sizeBuf, uint32(len(b)))
@ -91,8 +89,16 @@ func (c *commandFsMetaSave) Do(args []string, commandEnv *CommandEnv, writer io.
}) })
} }
if *chunksFileName != "" { var chunksFileName = ""
return doTraverseBfsAndSaving(*chunksFileName, commandEnv, writer, path, *verbose, func(dst io.Writer, outputChan chan []byte) { if chunksFileName != "" {
dst, openErr := os.OpenFile(chunksFileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if openErr != nil {
return fmt.Errorf("failed to create file %s: %v", chunksFileName, openErr)
}
defer dst.Close()
return doTraverseBfsAndSaving(commandEnv, writer, path, *verbose, func(dst io.Writer, outputChan chan []byte) {
for b := range outputChan { for b := range outputChan {
dst.Write(b) dst.Write(b)
} }
@ -113,15 +119,7 @@ func (c *commandFsMetaSave) Do(args []string, commandEnv *CommandEnv, writer io.
} }
func doTraverseBfsAndSaving(fileName string, commandEnv *CommandEnv, writer io.Writer, path string, verbose bool, func doTraverseBfsAndSaving(commandEnv *CommandEnv, writer io.Writer, path string, verbose bool, saveFn func(dst io.Writer, outputChan chan []byte), genFn func(entry *filer_pb.FullEntry, outputChan chan []byte) error) error {
saveFn func(dst io.Writer, outputChan chan []byte),
genFn func(entry *filer_pb.FullEntry, outputChan chan []byte) error) error {
dst, 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()
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(1) wg.Add(1)