SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
filer: stop isSameChunks from sorting caller-owned chunk slices (#11584)
Chris Lu2b5fdc639f1c
diff --git a/weed/filer/stream.go b/weed/filer/stream.goindex 6ac2a73756..47fccbb876 100644--- a/weed/filer/stream.go+++ b/weed/filer/stream.go@@ -85,14 +85,16 @@ func isSameChunks(a, b []*filer_pb.FileChunk) bool {if len(a) != len(b) {return false}- slices.SortFunc(a, func(i, j *filer_pb.FileChunk) int {+ sortedA := slices.Clone(a)+ sortedB := slices.Clone(b)+ slices.SortFunc(sortedA, func(i, j *filer_pb.FileChunk) int {return strings.Compare(i.ETag, j.ETag)})- slices.SortFunc(b, func(i, j *filer_pb.FileChunk) int {+ slices.SortFunc(sortedB, func(i, j *filer_pb.FileChunk) int {return strings.Compare(i.ETag, j.ETag)})- for i := 0; i < len(a); i++ {- if a[i].ETag != b[i].ETag {+ for i := 0; i < len(sortedA); i++ {+ if sortedA[i].ETag != sortedB[i].ETag {return false}}diff --git a/weed/filer/stream_test.go b/weed/filer/stream_test.gonew file mode 100644index 0000000000..ec3aba337e--- /dev/null+++ b/weed/filer/stream_test.go@@ -0,0 +1,28 @@+package filer++import (+ "testing"++ "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"+ "github.com/stretchr/testify/assert"+)++// IsSameData must not reorder the caller's chunk slices: filer.remote.sync+// stamps the filer entry an event described under an IF_ENTRY_EQUAL guard,+// and an in-place sort leaves the event entry ordered differently from the+// stored one, so the stamp never matches.+func TestIsSameDataLeavesChunkOrderAlone(t *testing.T) {+ chunkA := &filer_pb.FileChunk{FileId: "1,aaa", ETag: "zzzz", Size: 4}+ chunkB := &filer_pb.FileChunk{FileId: "2,bbb", ETag: "aaaa", Size: 2}+ a := &filer_pb.Entry{Chunks: []*filer_pb.FileChunk{chunkA, chunkB}}+ b := &filer_pb.Entry{Chunks: []*filer_pb.FileChunk{+ {FileId: "3,ccc", ETag: "zzzz", Size: 4},+ {FileId: "4,ddd", ETag: "aaaa", Size: 2},+ }}++ assert.True(t, IsSameData(a, b))+ assert.Equal(t, "1,aaa", a.Chunks[0].FileId)+ assert.Equal(t, "2,bbb", a.Chunks[1].FileId)+ assert.Equal(t, "3,ccc", b.Chunks[0].FileId)+ assert.Equal(t, "4,ddd", b.Chunks[1].FileId)+}