From 0d76cd13fb8e414cdfaffb2bec708306e4166ced Mon Sep 17 00:00:00 2001 From: chrislu Date: Mon, 27 Oct 2025 17:55:09 -0700 Subject: [PATCH] refactor: update VolumeEcShardsGenerate to use ECContext - Create ECContext with default configuration in VolumeEcShardsGenerate - Use ecCtx.TotalShards and ecCtx.ToExt() in cleanup - Call WriteEcFilesWithContext() instead of WriteEcFiles() - Save EC configuration (DataShardsCount, ParityShardsCount) to VolumeInfo - Log EC context being used - Phase 1: Always uses default 10+4 configuration - No behavior change --- weed/server/volume_grpc_erasure_coding.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/weed/server/volume_grpc_erasure_coding.go b/weed/server/volume_grpc_erasure_coding.go index 88e94115d..12ec301b6 100644 --- a/weed/server/volume_grpc_erasure_coding.go +++ b/weed/server/volume_grpc_erasure_coding.go @@ -50,20 +50,24 @@ func (vs *VolumeServer) VolumeEcShardsGenerate(ctx context.Context, req *volume_ return nil, fmt.Errorf("existing collection:%v unexpected input: %v", v.Collection, req.Collection) } + // Create EC context (Phase 1: always uses default 10+4) + ecCtx := erasure_coding.NewDefaultECContext(req.Collection, needle.VolumeId(req.VolumeId)) + glog.V(0).Infof("Using EC context for volume %d: %s", req.VolumeId, ecCtx.String()) + shouldCleanup := true defer func() { if !shouldCleanup { return } - for i := 0; i < erasure_coding.TotalShardsCount; i++ { - os.Remove(fmt.Sprintf("%s.ec%2d", baseFileName, i)) + for i := 0; i < ecCtx.TotalShards; i++ { + os.Remove(baseFileName + ecCtx.ToExt(i)) } os.Remove(v.IndexFileName() + ".ecx") }() - // write .ec00 ~ .ec13 files - if err := erasure_coding.WriteEcFiles(baseFileName); err != nil { - return nil, fmt.Errorf("WriteEcFiles %s: %v", baseFileName, err) + // write .ec00 ~ .ec[TotalShards-1] files using context + if err := erasure_coding.WriteEcFilesWithContext(baseFileName, ecCtx); err != nil { + return nil, fmt.Errorf("WriteEcFilesWithContext %s: %v", baseFileName, err) } // write .ecx file @@ -84,6 +88,11 @@ func (vs *VolumeServer) VolumeEcShardsGenerate(ctx context.Context, req *volume_ datSize, _, _ := v.FileStat() volumeInfo.DatFileSize = int64(datSize) + + // Save EC configuration to VolumeInfo + volumeInfo.DataShardsCount = uint32(ecCtx.DataShards) + volumeInfo.ParityShardsCount = uint32(ecCtx.ParityShards) + if err := volume_info.SaveVolumeInfo(baseFileName+".vif", volumeInfo); err != nil { return nil, fmt.Errorf("SaveVolumeInfo %s: %v", baseFileName, err) }