diff --git a/weed/shell/command_fs_verify_restore.go b/weed/shell/command_fs_verify_restore.go index b4a4fb4304..4b59733360 100644 --- a/weed/shell/command_fs_verify_restore.go +++ b/weed/shell/command_fs_verify_restore.go @@ -35,10 +35,8 @@ type restoreTarget struct { } type restorableChunk struct { - fileId string - needle *needle.Needle + chunk *filer_pb.FileChunk collection string - manifest bool } // restoreEntry copies the restorable missing chunks of an entry from the @@ -55,13 +53,13 @@ func (c *commandFsVerify) restoreEntry(path util.FullPath, attr *filer_pb.FuseAt continue } seen[fileId] = true - n, collection, err := c.readRestorableNeedle(chunk) + _, collection, err := c.readRestorableNeedle(chunk) if err != nil { fmt.Fprintf(c.writer, "not restorable %s chunk %s: %v\n", path, fileId, err) mayHold = mayHold || restoreSourceMayHold(err) continue } - ready = append(ready, restorableChunk{fileId: fileId, needle: n, collection: collection, manifest: chunk.IsChunkManifest}) + ready = append(ready, restorableChunk{chunk: chunk, collection: collection}) } if len(ready) == 0 { return false, mayHold @@ -94,12 +92,18 @@ func (c *commandFsVerify) restoreEntry(path util.FullPath, attr *filer_pb.FuseAt newFileIds := make(map[string]string) var uploaded []orphanedNeedle for _, r := range ready { - fileId, err := c.uploadRestored(restoreTarget{path, r.collection, ttlSec}, r.needle.Data, r.needle.IsCompressed(), restoreMimeType(r.needle)) + // read again rather than held, so one needle at a time is in memory + oldFileId := r.chunk.GetFileIdString() + n, _, err := c.readRestorableNeedle(r.chunk) + var fileId string + if err == nil { + fileId, err = c.uploadRestored(restoreTarget{path, r.collection, ttlSec}, n.Data, n.IsCompressed(), restoreMimeType(n)) + } if err != nil { - fmt.Fprintf(c.writer, "not restored %s chunk %s: %v\n", path, r.fileId, err) + fmt.Fprintf(c.writer, "not restored %s chunk %s: %v\n", path, oldFileId, err) continue } - newFileIds[r.fileId] = fileId + newFileIds[oldFileId] = fileId uploaded = append(uploaded, newOrphanedNeedle(fileId)) } if len(newFileIds) == 0 { @@ -170,8 +174,8 @@ func (c *commandFsVerify) restoreEntry(path util.FullPath, attr *filer_pb.FuseAt fmt.Fprintf(c.writer, "restored %s chunk %s -> %s\n", path, oldFileId, applied[oldFileId]) } for _, r := range ready { - if _, found := applied[r.fileId]; found && r.manifest { - fmt.Fprintf(c.writer, "restored %s manifest %s: run fs.verify again to check the chunks it holds\n", path, r.fileId) + if _, found := applied[r.chunk.GetFileIdString()]; found && r.chunk.IsChunkManifest { + fmt.Fprintf(c.writer, "restored %s manifest %s: run fs.verify again to check the chunks it holds\n", path, r.chunk.GetFileIdString()) } } return true, true