From f13e4da77a08aee53e540e9f846c8f5eb061c63b Mon Sep 17 00:00:00 2001 From: chrislu Date: Mon, 27 Oct 2025 19:38:34 -0700 Subject: [PATCH] optimize: simplify VolumeEcShardsToVolume to use existing EC context - Remove redundant CollectEcShards call - Remove redundant .vif file loading - Use v.ECContext.DataShards directly (already loaded by NewEcVolume) - Slice tempShards instead of collecting again --- weed/server/volume_grpc_erasure_coding.go | 28 ++++++++--------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/weed/server/volume_grpc_erasure_coding.go b/weed/server/volume_grpc_erasure_coding.go index f62ae1885..e929351f6 100644 --- a/weed/server/volume_grpc_erasure_coding.go +++ b/weed/server/volume_grpc_erasure_coding.go @@ -453,40 +453,30 @@ func (vs *VolumeServer) VolumeEcShardsToVolume(ctx context.Context, req *volume_ glog.V(0).Infof("VolumeEcShardsToVolume: %v", req) - // collect data shard files; derive shard count from .vif if present - dataShards := erasure_coding.DataShardsCount - - // Try to get the volume first to determine data base filename + // Collect all EC shards (NewEcVolume will load EC config from .vif into v.ECContext) tempShards := make([]string, erasure_coding.TotalShardsCount) v, found := vs.store.CollectEcShards(needle.VolumeId(req.VolumeId), tempShards) if !found { return nil, fmt.Errorf("ec volume %d not found", req.VolumeId) } - - dataBaseFileName, indexBaseFileName := v.DataBaseFileName(), v.IndexBaseFileName() - - // Read EC config from .vif if available - if vi, _, found, _ := volume_info.MaybeLoadVolumeInfo(dataBaseFileName + ".vif"); found && vi.EcShardConfig != nil { - dataShards = int(vi.EcShardConfig.DataShards) - glog.V(1).Infof("Using EC config from VolumeInfo: %d data shards", dataShards) - } - - // Collect only the data shards needed - shardFileNames := make([]string, dataShards) - v, found = vs.store.CollectEcShards(needle.VolumeId(req.VolumeId), shardFileNames) - if !found { - return nil, fmt.Errorf("ec volume %d not found", req.VolumeId) - } if v.Collection != req.Collection { return nil, fmt.Errorf("existing collection:%v unexpected input: %v", v.Collection, req.Collection) } + // Use EC context (already loaded from .vif) to determine data shard count + dataShards := v.ECContext.DataShards + shardFileNames := tempShards[:dataShards] + glog.V(1).Infof("Using EC config from volume %d: %d data shards", req.VolumeId, dataShards) + + // Verify all data shards are present for shardId := 0; shardId < dataShards; shardId++ { if shardFileNames[shardId] == "" { return nil, fmt.Errorf("ec volume %d missing shard %d", req.VolumeId, shardId) } } + + dataBaseFileName, indexBaseFileName := v.DataBaseFileName(), v.IndexBaseFileName() // calculate .dat file size datFileSize, err := erasure_coding.FindDatFileSize(dataBaseFileName, indexBaseFileName) if err != nil {