aboutsummaryrefslogtreecommitdiff
path: root/weed/topology/topology_ec.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/topology/topology_ec.go')
-rw-r--r--weed/topology/topology_ec.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/weed/topology/topology_ec.go b/weed/topology/topology_ec.go
index 844e92f55..c8b511338 100644
--- a/weed/topology/topology_ec.go
+++ b/weed/topology/topology_ec.go
@@ -10,7 +10,8 @@ import (
type EcShardLocations struct {
Collection string
- Locations [erasure_coding.TotalShardsCount][]*DataNode
+ // Use MaxShardCount (32) to support custom EC ratios
+ Locations [erasure_coding.MaxShardCount][]*DataNode
}
func (t *Topology) SyncDataNodeEcShards(shardInfos []*master_pb.VolumeEcShardInformationMessage, dn *DataNode) (newShards, deletedShards []*erasure_coding.EcVolumeInfo) {
@@ -90,6 +91,10 @@ func NewEcShardLocations(collection string) *EcShardLocations {
}
func (loc *EcShardLocations) AddShard(shardId erasure_coding.ShardId, dn *DataNode) (added bool) {
+ // Defensive bounds check to prevent panic with out-of-range shard IDs
+ if int(shardId) >= erasure_coding.MaxShardCount {
+ return false
+ }
dataNodes := loc.Locations[shardId]
for _, n := range dataNodes {
if n.Id() == dn.Id() {
@@ -101,6 +106,10 @@ func (loc *EcShardLocations) AddShard(shardId erasure_coding.ShardId, dn *DataNo
}
func (loc *EcShardLocations) DeleteShard(shardId erasure_coding.ShardId, dn *DataNode) (deleted bool) {
+ // Defensive bounds check to prevent panic with out-of-range shard IDs
+ if int(shardId) >= erasure_coding.MaxShardCount {
+ return false
+ }
dataNodes := loc.Locations[shardId]
foundIndex := -1
for index, n := range dataNodes {