Browse Source

sorting chunks

Chris Lu 4 years ago
parent
commit
d60bcbf08a
3 changed files with 10 additions and 2 deletions
  1. 1 1
      weed/filer2/filechunks.go
  2. 1 1
      weed/filesys/file.go
  3. 8 0
      weed/shell/command_fs_meta_cat.go

+ 1 - 1
weed/filer2/filechunks.go

@@ -219,7 +219,7 @@ func NonOverlappingVisibleIntervals(lookupFileIdFn LookupFileIdFunctionType, chu
 	chunks, _, err = ResolveChunkManifest(lookupFileIdFn, chunks)
 
 	sort.Slice(chunks, func(i, j int) bool {
-		return chunks[i].Mtime < chunks[j].Mtime
+		return chunks[i].Fid.FileKey < chunks[j].Fid.FileKey
 	})
 
 	var newVisibles []VisibleInterval

+ 1 - 1
weed/filesys/file.go

@@ -258,7 +258,7 @@ func (file *File) maybeLoadEntry(ctx context.Context) error {
 func (file *File) addChunks(chunks []*filer_pb.FileChunk) {
 
 	sort.Slice(chunks, func(i, j int) bool {
-		return chunks[i].Mtime < chunks[j].Mtime
+		return chunks[i].Fid.FileKey < chunks[j].Fid.FileKey
 	})
 
 	var newVisibles []filer2.VisibleInterval

+ 8 - 0
weed/shell/command_fs_meta_cat.go

@@ -3,6 +3,7 @@ package shell
 import (
 	"fmt"
 	"io"
+	"sort"
 
 	"github.com/golang/protobuf/jsonpb"
 
@@ -54,6 +55,13 @@ func (c *commandFsMetaCat) Do(args []string, commandEnv *CommandEnv, writer io.W
 			Indent:       "  ",
 		}
 
+		sort.Slice(respLookupEntry.Entry.Chunks, func(i, j int) bool {
+			if respLookupEntry.Entry.Chunks[i].Offset == respLookupEntry.Entry.Chunks[j].Offset {
+				return respLookupEntry.Entry.Chunks[i].Mtime < respLookupEntry.Entry.Chunks[j].Mtime
+			}
+			return respLookupEntry.Entry.Chunks[i].Offset < respLookupEntry.Entry.Chunks[j].Offset
+		})
+
 		text, marshalErr := m.MarshalToString(respLookupEntry.Entry)
 		if marshalErr != nil {
 			return fmt.Errorf("marshal meta: %v", marshalErr)