Skip to content

Commit

Permalink
meta: in compaction don't skip the first slice if it's duplicated (#5159
Browse files Browse the repository at this point in the history
)
  • Loading branch information
SandyXSD authored and jiefenghuang committed Nov 26, 2024
1 parent 6f72df7 commit 2441d03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/meta/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,21 @@ func testCompaction(t *testing.T, m Meta, trash bool) {
t.Fatalf("inode %d should be compacted, but have %d slices, size %d,%d,%d",
inode, len(slices), slices[0].Len, slices[1].Len, slices[2].Len)
}

m.NewSlice(ctx, &sliceId)
_ = m.Write(ctx, inode, 3, 0, Slice{Id: sliceId, Size: 2338508, Len: 2338508}, time.Now())
_ = m.CopyFileRange(ctx, inode, 3*ChunkSize, inode, 4*ChunkSize, 2338508, 0, nil, nil)
_ = m.Fallocate(ctx, inode, fallocZeroRange, 4*ChunkSize, ChunkSize, nil)
_ = m.CopyFileRange(ctx, inode, 3*ChunkSize, inode, 4*ChunkSize, 2338508, 0, nil, nil)
if c, ok := m.(compactor); ok {
c.compactChunk(inode, 4, false, true)
}
if st := m.Read(ctx, inode, 4, &slices); st != 0 {
t.Fatalf("read inode %d chunk 4: %s", inode, st)
}
if len(slices) != 1 || slices[0].Len != 2338508 {
t.Fatalf("inode %d should be compacted, but have %d slices, size %d", inode, len(slices), slices[0].Len)
}
}

func testConcurrentWrite(t *testing.T, m Meta) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/meta/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func compactChunk(ss []*slice) (uint32, uint32, []Slice) {
func skipSome(chunk []*slice) int {
var skipped int
var total = len(chunk)
OUT:
for skipped < total {
ss := chunk[skipped:]
pos, size, c := compactChunk(ss)
Expand All @@ -189,6 +190,11 @@ func skipSome(chunk []*slice) int {
// it's not the first slice, compact it
break
}
for _, s := range ss[1:] {
if *s == *first {
break OUT
}
}
skipped++
}
return skipped
Expand Down

0 comments on commit 2441d03

Please sign in to comment.