2023-01-10 16:46:46 +08:00
|
|
|
package filer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_removeGarbageChunks(t *testing.T) {
|
|
|
|
section := NewFileChunkSection(0)
|
2023-01-13 15:07:36 +08:00
|
|
|
section.chunks = append(section.chunks, &filer_pb.FileChunk{
|
2023-01-10 16:46:46 +08:00
|
|
|
FileId: "0",
|
|
|
|
Offset: 0,
|
|
|
|
Size: 1,
|
|
|
|
ModifiedTsNs: 0,
|
|
|
|
})
|
2023-01-13 15:07:36 +08:00
|
|
|
section.chunks = append(section.chunks, &filer_pb.FileChunk{
|
2023-01-10 16:46:46 +08:00
|
|
|
FileId: "1",
|
|
|
|
Offset: 1,
|
|
|
|
Size: 1,
|
|
|
|
ModifiedTsNs: 1,
|
|
|
|
})
|
2023-01-13 15:07:36 +08:00
|
|
|
section.chunks = append(section.chunks, &filer_pb.FileChunk{
|
2023-01-10 16:46:46 +08:00
|
|
|
FileId: "2",
|
|
|
|
Offset: 2,
|
|
|
|
Size: 1,
|
|
|
|
ModifiedTsNs: 2,
|
|
|
|
})
|
2023-01-13 15:07:36 +08:00
|
|
|
section.chunks = append(section.chunks, &filer_pb.FileChunk{
|
2023-01-10 16:46:46 +08:00
|
|
|
FileId: "3",
|
|
|
|
Offset: 3,
|
|
|
|
Size: 1,
|
|
|
|
ModifiedTsNs: 3,
|
|
|
|
})
|
2023-01-13 15:07:36 +08:00
|
|
|
section.chunks = append(section.chunks, &filer_pb.FileChunk{
|
2023-01-10 16:46:46 +08:00
|
|
|
FileId: "4",
|
|
|
|
Offset: 4,
|
|
|
|
Size: 1,
|
|
|
|
ModifiedTsNs: 4,
|
|
|
|
})
|
|
|
|
garbageFileIds := make(map[string]struct{})
|
|
|
|
garbageFileIds["0"] = struct{}{}
|
|
|
|
garbageFileIds["2"] = struct{}{}
|
|
|
|
garbageFileIds["4"] = struct{}{}
|
|
|
|
removeGarbageChunks(section, garbageFileIds)
|
|
|
|
if len(section.chunks) != 2 {
|
|
|
|
t.Errorf("remove chunk 2 failed")
|
|
|
|
}
|
|
|
|
}
|