From c4f970bfa69c44808d3c8741c1a2d93bfd09fc23 Mon Sep 17 00:00:00 2001 From: chrislu Date: Mon, 27 Oct 2025 20:58:20 -0700 Subject: [PATCH] refactor: move MaxShardCount constant to ec_encoder.go Moved MaxShardCount from ec_volume_info.go to ec_encoder.go to group it with other shard count constants (DataShardsCount, ParityShardsCount, TotalShardsCount). This improves code organization and makes it easier to understand the relationship between these constants. Location: ec_encoder.go line 22, between TotalShardsCount and MinTotalDisks --- weed/storage/erasure_coding/ec_encoder.go | 5 +++-- weed/storage/erasure_coding/ec_volume_info.go | 4 ---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/weed/storage/erasure_coding/ec_encoder.go b/weed/storage/erasure_coding/ec_encoder.go index e0886b60d..81ebffdcb 100644 --- a/weed/storage/erasure_coding/ec_encoder.go +++ b/weed/storage/erasure_coding/ec_encoder.go @@ -19,6 +19,7 @@ const ( DataShardsCount = 10 ParityShardsCount = 4 TotalShardsCount = DataShardsCount + ParityShardsCount + MaxShardCount = 32 // Maximum number of shards since ShardBits is uint32 (bits 0-31) MinTotalDisks = TotalShardsCount/ParityShardsCount + 1 ErasureCodingLargeBlockSize = 1024 * 1024 * 1024 // 1GB ErasureCodingSmallBlockSize = 1024 * 1024 // 1MB @@ -72,7 +73,7 @@ func RebuildEcFiles(baseFileName string) ([]uint32, error) { if volumeInfo, _, found, _ := volume_info.MaybeLoadVolumeInfo(baseFileName + ".vif"); found && volumeInfo.EcShardConfig != nil { ds := int(volumeInfo.EcShardConfig.DataShards) ps := int(volumeInfo.EcShardConfig.ParityShards) - + // Validate EC config before using it if ds > 0 && ps > 0 && ds+ps <= MaxShardCount { ctx = &ECContext{ @@ -88,7 +89,7 @@ func RebuildEcFiles(baseFileName string) ([]uint32, error) { glog.V(0).Infof("Rebuilding EC files for %s with default config", baseFileName) ctx = NewDefaultECContext("", 0) } - + return RebuildEcFilesWithContext(baseFileName, ctx) } diff --git a/weed/storage/erasure_coding/ec_volume_info.go b/weed/storage/erasure_coding/ec_volume_info.go index c2f51c112..81891fd6c 100644 --- a/weed/storage/erasure_coding/ec_volume_info.go +++ b/weed/storage/erasure_coding/ec_volume_info.go @@ -118,10 +118,6 @@ func (ecInfo *EcVolumeInfo) ToVolumeEcShardInformationMessage() (ret *master_pb. type ShardBits uint32 // use bits to indicate the shard id, use 32 bits just for possible future extension -const ( - MaxShardCount = 32 // Maximum number of shards since ShardBits is uint32 (bits 0-31) -) - func (b ShardBits) AddShardId(id ShardId) ShardBits { return b | (1 << id) }