SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
fix ec.encode skipping volumes when one replica is on a full disk (#8227)
Chris Lu30812b85f3b5
diff --git a/weed/shell/command_ec_encode.go b/weed/shell/command_ec_encode.goindex b4b12963c8..138c977a5a 100644--- a/weed/shell/command_ec_encode.go+++ b/weed/shell/command_ec_encode.go@@ -192,7 +192,7 @@ func (c *commandEcEncode) Do(args []string, commandEnv *CommandEnv, writer io.Wr}// encode all requested volumes...- if err = doEcEncode(commandEnv, writer, volumeIdToCollection, volumeIds, *maxParallelization); err != nil {+ if err = doEcEncode(commandEnv, writer, volumeIdToCollection, volumeIds, *maxParallelization, topologyInfo); err != nil {return fmt.Errorf("ec encode for volumes %v: %w", volumeIds, err)}// ...re-balance ec shards...@@ -222,7 +222,7 @@ func volumeLocations(commandEnv *CommandEnv, volumeIds []needle.VolumeId) (map[nreturn res, nil}-func doEcEncode(commandEnv *CommandEnv, writer io.Writer, volumeIdToCollection map[needle.VolumeId]string, volumeIds []needle.VolumeId, maxParallelization int) error {+func doEcEncode(commandEnv *CommandEnv, writer io.Writer, volumeIdToCollection map[needle.VolumeId]string, volumeIds []needle.VolumeId, maxParallelization int, topologyInfo *master_pb.TopologyInfo) error {if !commandEnv.isLocked() {return fmt.Errorf("lock is lost")}@@ -231,6 +231,17 @@ func doEcEncode(commandEnv *CommandEnv, writer io.Writer, volumeIdToCollection mreturn fmt.Errorf("failed to get volume locations for EC encoding: %w", err)}+ // build a map of (volumeId, serverAddress) -> freeVolumeCount+ freeVolumeCountMap := make(map[string]int) // key: volumeId-serverAddress+ eachDataNode(topologyInfo, func(dc DataCenterId, rack RackId, dn *master_pb.DataNodeInfo) {+ for _, diskInfo := range dn.DiskInfos {+ for _, v := range diskInfo.VolumeInfos {+ key := fmt.Sprintf("%d-%s", v.Id, dn.Id)+ freeVolumeCountMap[key] = int(diskInfo.FreeVolumeCount)+ }+ }+ })+// mark volumes as readonlyewg := NewErrorWaitGroup(maxParallelization)for _, vid := range volumeIds {@@ -254,8 +265,22 @@ func doEcEncode(commandEnv *CommandEnv, writer io.Writer, volumeIdToCollection mfor _, vid := range volumeIds {locs := locations[vid]collection := volumeIdToCollection[vid]++ // Filter locations to only include those on healthy disks (FreeVolumeCount >= 2)+ var filteredLocs []wdclient.Location+ for _, l := range locs {+ key := fmt.Sprintf("%d-%s", vid, l.Url)+ if freeCount, found := freeVolumeCountMap[key]; found && freeCount >= 2 {+ filteredLocs = append(filteredLocs, l)+ }+ }++ if len(filteredLocs) == 0 {+ return fmt.Errorf("no healthy replicas (FreeVolumeCount >= 2) found for volume %d to use as source for EC encoding", vid)+ }+// Sync missing entries between replicas, then select the best one- bestLoc, selectErr := syncAndSelectBestReplica(commandEnv.option.GrpcDialOption, vid, collection, locs, "", writer)+ bestLoc, selectErr := syncAndSelectBestReplica(commandEnv.option.GrpcDialOption, vid, collection, filteredLocs, "", writer)if selectErr != nil {return fmt.Errorf("failed to sync and select replica for volume %d: %v", vid, selectErr)}@@ -444,36 +469,23 @@ func selectVolumeIdsFromTopology(topologyInfo *master_pb.TopologyInfo, volumeSiz}// check free disk space- if good, found := vidMap[v.Id]; found {- if good {- if diskInfo.FreeVolumeCount < 2 {- glog.V(0).Infof("skip %s %d on %s, no free disk", v.Collection, v.Id, dn.Id)- if verbose {- fmt.Printf("skip volume %d on %s: insufficient free disk space (free volumes: %d, required: 2)\n",- v.Id, dn.Id, diskInfo.FreeVolumeCount)- }- vidMap[v.Id] = false- noFreeDisk++- }+ if diskInfo.FreeVolumeCount < 2 {+ glog.V(0).Infof("replica %s %d on %s has no free disk", v.Collection, v.Id, dn.Id)+ if verbose {+ fmt.Printf("skip replica of volume %d on %s: insufficient free disk space (free volumes: %d, required: 2)\n",+ v.Id, dn.Id, diskInfo.FreeVolumeCount)}- } else {- if diskInfo.FreeVolumeCount < 2 {- glog.V(0).Infof("skip %s %d on %s, no free disk", v.Collection, v.Id, dn.Id)- if verbose {- fmt.Printf("skip volume %d on %s: insufficient free disk space (free volumes: %d, required: 2)\n",- v.Id, dn.Id, diskInfo.FreeVolumeCount)- }+ if _, found := vidMap[v.Id]; !found {vidMap[v.Id] = false- noFreeDisk++- } else {- if verbose {- fmt.Printf("selected volume %d on %s: size %.1f MB (%.1f%% full), last modified %d seconds ago, free volumes: %d\n",- v.Id, dn.Id, float64(v.Size)/(1024*1024),- float64(v.Size)*100/(float64(volumeSizeLimitMb)*1024*1024),- nowUnixSeconds-v.ModifiedAtSecond, diskInfo.FreeVolumeCount)- }- vidMap[v.Id] = true}+ } else {+ if verbose {+ fmt.Printf("selected volume %d on %s: size %.1f MB (%.1f%% full), last modified %d seconds ago, free volumes: %d\n",+ v.Id, dn.Id, float64(v.Size)/(1024*1024),+ float64(v.Size)*100/(float64(volumeSizeLimitMb)*1024*1024),+ nowUnixSeconds-v.ModifiedAtSecond, diskInfo.FreeVolumeCount)+ }+ vidMap[v.Id] = true}}}@@ -482,6 +494,8 @@ func selectVolumeIdsFromTopology(topologyInfo *master_pb.TopologyInfo, volumeSizfor vid, good := range vidMap {if good {vids = append(vids, needle.VolumeId(vid))+ } else {+ noFreeDisk++}}