From 56df44845f02d9c1f37e957df1b09fd1a6d9a7fd Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 4 Feb 2024 09:22:24 -0800 Subject: [PATCH] fix when two consecutive chunks with the same modified_ts_ns fix https://github.com/seaweedfs/seaweedfs/issues/5276 --- weed/filer/filechunks_read.go | 4 ++-- weed/filer/filechunks_test.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/weed/filer/filechunks_read.go b/weed/filer/filechunks_read.go index b8768ed63..11b297a3c 100644 --- a/weed/filer/filechunks_read.go +++ b/weed/filer/filechunks_read.go @@ -38,10 +38,10 @@ func readResolvedChunks(chunks []*filer_pb.FileChunk, startOffset int64, stopOff return int(a.ts - b.ts) } if a.isStart { - return -1 + return 1 } if b.isStart { - return 1 + return -1 } return 0 }) diff --git a/weed/filer/filechunks_test.go b/weed/filer/filechunks_test.go index b448950a9..7554b0080 100644 --- a/weed/filer/filechunks_test.go +++ b/weed/filer/filechunks_test.go @@ -553,3 +553,18 @@ func TestViewFromVisibleIntervals3(t *testing.T) { } } + +func TestCompactFileChunks3(t *testing.T) { + chunks := []*filer_pb.FileChunk{ + {Offset: 0, Size: 100, FileId: "abc", ModifiedTsNs: 50}, + {Offset: 100, Size: 100, FileId: "ghi", ModifiedTsNs: 50}, + {Offset: 200, Size: 100, FileId: "jkl", ModifiedTsNs: 100}, + {Offset: 300, Size: 100, FileId: "def", ModifiedTsNs: 200}, + } + + compacted, _ := CompactFileChunks(nil, chunks) + + if len(compacted) != 4 { + t.Fatalf("unexpected compacted: %d", len(compacted)) + } +}