Skip to content

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.

ec: avoid redundant needle.GetActualSize call in LocateEcShardNeedle (#11629)

mortezad0f3fad13391
diff --git a/weed/storage/erasure_coding/ec_volume.go b/weed/storage/erasure_coding/ec_volume.go
index fb65f97327..d3607c6f20 100644
--- a/weed/storage/erasure_coding/ec_volume.go
+++ b/weed/storage/erasure_coding/ec_volume.go
@@ -982,7 +982,7 @@ func (ev *EcVolume) LocateEcShardNeedle(needleId types.NeedleId, version needle.
return types.Offset{}, 0, nil, fmt.Errorf("FindNeedleFromEcx: %w", err)
}
- intervals = ev.LocateEcShardNeedleInterval(version, offset.ToActualOffset(), types.Size(needle.GetActualSize(size, version)))
+ intervals = ev.LocateEcShardNeedleInterval(version, offset.ToActualOffset(), size)
return
}
diff --git a/weed/storage/erasure_coding/ec_volume_test.go b/weed/storage/erasure_coding/ec_volume_test.go
index b87a662cf6..556fc1abab 100644
--- a/weed/storage/erasure_coding/ec_volume_test.go
+++ b/weed/storage/erasure_coding/ec_volume_test.go
@@ -256,3 +256,30 @@ func TestEcVolumeDestroySweepsBothDirs(t *testing.T) {
}
}
}
+
+func TestLocateEcShardNeedleMatchesInterval(t *testing.T) {
+ ecxFile, err := os.OpenFile("./test_files/389.ecx", os.O_RDONLY, 0)
+ assert.NoError(t, err)
+ defer ecxFile.Close()
+
+ stat, err := ecxFile.Stat()
+ assert.NoError(t, err)
+ fileSize := stat.Size()
+
+ ev := &EcVolume{
+ VolumeId: needle.VolumeId(389),
+ ecxFile: ecxFile,
+ ecxFileSize: fileSize,
+ Shards: []*EcVolumeShard{
+ {ecdFileSize: 1118830592},
+ },
+ ECContext: NewDefaultECContext("", 389),
+ }
+
+ needleId, _ := types.ParseNeedleId("0f0edb92")
+ offset, size, intervals, err := ev.LocateEcShardNeedle(needleId, needle.GetCurrentVersion())
+ assert.NoError(t, err)
+
+ expectedIntervals := ev.LocateEcShardNeedleInterval(needle.GetCurrentVersion(), offset.ToActualOffset(), size)
+ assert.Equal(t, expectedIntervals, intervals)
+}