Browse Source

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
pull/7396/head
chrislu 1 month ago
parent
commit
f13e4da77a
  1. 28
      weed/server/volume_grpc_erasure_coding.go

28
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 {

Loading…
Cancel
Save