From 57556041c822e48dd1be0fd4545ced3ed53031ba Mon Sep 17 00:00:00 2001 From: chrislu Date: Mon, 27 Oct 2025 19:46:54 -0700 Subject: [PATCH] refactor: rename MaxShardId to MaxShardCount for clarity - Change from MaxShardId=31 to MaxShardCount=32 - Eliminates confusing +1 arithmetic (MaxShardId+1) - More intuitive: MaxShardCount directly represents the limit fix: support custom EC ratios beyond 14 shards in VolumeEcShardsToVolume - Add MaxShardId constant (31, since ShardBits is uint32) - Use MaxShardId+1 (32) instead of TotalShardsCount (14) for tempShards buffer - Prevents panic when slicing for volumes with >14 total shards - Critical fix for custom EC configurations like 20+10 --- weed/server/volume_grpc_erasure_coding.go | 3 ++- weed/storage/erasure_coding/ec_volume_info.go | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/weed/server/volume_grpc_erasure_coding.go b/weed/server/volume_grpc_erasure_coding.go index e929351f6..522432dde 100644 --- a/weed/server/volume_grpc_erasure_coding.go +++ b/weed/server/volume_grpc_erasure_coding.go @@ -454,7 +454,8 @@ func (vs *VolumeServer) VolumeEcShardsToVolume(ctx context.Context, req *volume_ glog.V(0).Infof("VolumeEcShardsToVolume: %v", req) // Collect all EC shards (NewEcVolume will load EC config from .vif into v.ECContext) - tempShards := make([]string, erasure_coding.TotalShardsCount) + // Use MaxShardCount (32) to support custom EC ratios up to 32 total shards + tempShards := make([]string, erasure_coding.MaxShardCount) v, found := vs.store.CollectEcShards(needle.VolumeId(req.VolumeId), tempShards) if !found { return nil, fmt.Errorf("ec volume %d not found", req.VolumeId) diff --git a/weed/storage/erasure_coding/ec_volume_info.go b/weed/storage/erasure_coding/ec_volume_info.go index 53b352168..cd196084a 100644 --- a/weed/storage/erasure_coding/ec_volume_info.go +++ b/weed/storage/erasure_coding/ec_volume_info.go @@ -118,6 +118,10 @@ 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) }