mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
* mount: merge each run of a sparse file's data, not just the run before its first hole The chunk stream reader ends at a hole, so the merge stopped there and replaced every chunk with ones covering only the data before the first hole. Read and save each contiguous run of visible data on its own, and leave the holes between runs unwritten. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: skip the small-chunk merge for a sparse file The merge reads the chunks through the stream reader to its end, which stops at a hole, and keeps only the chunks before its start offset, so an append to a sparse file lost the data past the first hole after it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
31 lines
890 B
Go
31 lines
890 B
Go
package weed_server
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/operation"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
)
|
|
|
|
func TestMaybeMergeChunksSkipsSparseFile(t *testing.T) {
|
|
fs := &FilerServer{option: &FilerOption{MaxMB: 4}}
|
|
var chunks []*filer_pb.FileChunk
|
|
offset := int64(0)
|
|
for i := 0; i < MergeChunkMinCount+1; i++ {
|
|
if i == MergeChunkMinCount/2 {
|
|
offset += 1 << 20
|
|
}
|
|
chunks = append(chunks, &filer_pb.FileChunk{Fid: &filer_pb.FileId{VolumeId: 1, FileKey: uint64(i + 1), Cookie: 1}, Offset: offset, Size: 1024, ModifiedTsNs: int64(i + 1)})
|
|
offset += 1024
|
|
}
|
|
|
|
merged, err := fs.maybeMergeChunks(context.Background(), &operation.StorageOption{}, chunks)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(merged) != len(chunks) {
|
|
t.Fatalf("merged a sparse file into %d chunks, want its %d chunks unchanged", len(merged), len(chunks))
|
|
}
|
|
}
|