From 29ca7f3fe32bca7548b4a4c4c2fd7384871d924f Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 6 Dec 2026 00:40:39 -0800 Subject: [PATCH] ec: return EC shard holders by their advertised address LargestEcGenerationHolders returned the data node id, which drops a holder's Address and custom gRPC port, so reading its .ecx dialed the wrong endpoint. Build each holder address from the data node instead. --- weed/ec/ec_common.go | 14 +++++++------- weed/worker/tasks/erasure_coding/detection.go | 4 ++-- .../erasure_coding/detection_ec_generation_test.go | 3 ++- .../erasure_coding/ec_task_orphan_cleanup_test.go | 9 +++++++-- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/weed/ec/ec_common.go b/weed/ec/ec_common.go index 0c50a16669..c6379591bc 100644 --- a/weed/ec/ec_common.go +++ b/weed/ec/ec_common.go @@ -1472,10 +1472,10 @@ func CountExistingEcShardsForVolume(topologyInfo *master_pb.TopologyInfo, volume return best } -// LargestEcGenerationHolders returns the nodes holding shards of the -// generation CountExistingEcShardsForVolume counts, or nil when no generation -// is strictly largest and so none can be named the EC volume. -func LargestEcGenerationHolders(topologyInfo *master_pb.TopologyInfo, volumeID uint32, collection string) []string { +// LargestEcGenerationHolders returns the addresses of the nodes holding shards +// of the generation CountExistingEcShardsForVolume counts, or nil when no +// generation is strictly largest and so none can be named the EC volume. +func LargestEcGenerationHolders(topologyInfo *master_pb.TopologyInfo, volumeID uint32, collection string) []pb.ServerAddress { var largest *ecShardGeneration tied := false for _, gen := range ecShardGenerations(topologyInfo, volumeID, collection) { @@ -1494,7 +1494,7 @@ func LargestEcGenerationHolders(topologyInfo *master_pb.TopologyInfo, volumeID u type ecShardGeneration struct { bits erasure_coding.ShardBits - holders []string + holders []pb.ServerAddress } // ecShardGenerations groups the (volumeID, collection) shards in the topology @@ -1525,8 +1525,8 @@ func ecShardGenerations(topologyInfo *master_pb.TopologyInfo, volumeID uint32, c } bits := erasure_coding.ShardBits(ecShardInfo.EcIndexBits) gen.bits |= bits - if bits.Count() > 0 && !slices.Contains(gen.holders, node.Id) { - gen.holders = append(gen.holders, node.Id) + if holder := pb.NewServerAddressFromDataNode(node); bits.Count() > 0 && !slices.Contains(gen.holders, holder) { + gen.holders = append(gen.holders, holder) } } } diff --git a/weed/worker/tasks/erasure_coding/detection.go b/weed/worker/tasks/erasure_coding/detection.go index ceb828f84a..e336d91df4 100644 --- a/weed/worker/tasks/erasure_coding/detection.go +++ b/weed/worker/tasks/erasure_coding/detection.go @@ -910,7 +910,7 @@ func needlesMissingFromEc(ctx context.Context, client volume_server_pb.VolumeSer // ecxReader fetches the EC volume's .ecx from one of its shard holders, once. type ecxReader struct { - holders []string + holders []pb.ServerAddress volumeID uint32 collection string dialOption grpc.DialOption @@ -927,7 +927,7 @@ func (r *ecxReader) read(ctx context.Context) ([]byte, error) { } var errs []string for _, holder := range r.holders { - err := operation.WithVolumeServerClient(false, pb.ServerAddress(holder), r.dialOption, + err := operation.WithVolumeServerClient(false, holder, r.dialOption, func(client volume_server_pb.VolumeServerClient) error { content, readErr := readVolumeFile(ctx, client, r.volumeID, r.collection, ".ecx", true) r.content = content diff --git a/weed/worker/tasks/erasure_coding/detection_ec_generation_test.go b/weed/worker/tasks/erasure_coding/detection_ec_generation_test.go index de81dbcff2..cd54e61fb8 100644 --- a/weed/worker/tasks/erasure_coding/detection_ec_generation_test.go +++ b/weed/worker/tasks/erasure_coding/detection_ec_generation_test.go @@ -6,6 +6,7 @@ import ( "github.com/seaweedfs/seaweedfs/weed/admin/topology" "github.com/seaweedfs/seaweedfs/weed/ec" + "github.com/seaweedfs/seaweedfs/weed/pb" "github.com/seaweedfs/seaweedfs/weed/pb/master_pb" "github.com/stretchr/testify/require" ) @@ -102,7 +103,7 @@ func TestLargestEcGenerationHolders(t *testing.T) { {bits: ecBits(0, 1, 2, 3, 4, 5, 6), encodeTsNs: 2}, {bits: ecBits(7, 8, 9, 10, 11, 12, 13), encodeTsNs: 2}, }) - require.Equal(t, []string{"10.0.0.2:8080", "10.0.0.3:8080"}, ec.LargestEcGenerationHolders(at.GetTopologyInfo(), vid, "")) + require.Equal(t, []pb.ServerAddress{"10.0.0.2:8080", "10.0.0.3:8080"}, ec.LargestEcGenerationHolders(at.GetTopologyInfo(), vid, "")) tied := buildEcTopology(t, vid, "", []ecShardSet{ {bits: ecBits(0, 1, 2), encodeTsNs: 1}, diff --git a/weed/worker/tasks/erasure_coding/ec_task_orphan_cleanup_test.go b/weed/worker/tasks/erasure_coding/ec_task_orphan_cleanup_test.go index 86c3985109..1921418917 100644 --- a/weed/worker/tasks/erasure_coding/ec_task_orphan_cleanup_test.go +++ b/weed/worker/tasks/erasure_coding/ec_task_orphan_cleanup_test.go @@ -5,6 +5,8 @@ import ( "context" "fmt" "net" + "strconv" + "strings" "sync" "testing" "time" @@ -175,9 +177,12 @@ func indexBytes(entries ...indexEntry) []byte { } // buildOrphanTopology places the regular replica on replicaAddr and the full -// EC shard set on holderAddr. +// EC shard set on holderAddr. The holder reports its gRPC port in GrpcPort +// rather than in its id, so it is reachable only through that port. func buildOrphanTopology(t *testing.T, replicaAddr, holderAddr string, volumeID uint32) *topology.ActiveTopology { t.Helper() + grpcPort, err := strconv.Atoi(holderAddr[strings.LastIndex(holderAddr, ".")+1:]) + require.NoError(t, err) at := topology.NewActiveTopology(10) require.NoError(t, at.UpdateTopology(&master_pb.TopologyInfo{ DataCenterInfos: []*master_pb.DataCenterInfo{{ @@ -188,7 +193,7 @@ func buildOrphanTopology(t *testing.T, replicaAddr, holderAddr string, volumeID {Id: replicaAddr, DiskInfos: map[string]*master_pb.DiskInfo{"hdd": { VolumeInfos: []*master_pb.VolumeInformationMessage{{Id: volumeID}}, }}}, - {Id: holderAddr, DiskInfos: map[string]*master_pb.DiskInfo{"hdd": { + {Id: "ec-holder", Address: "127.0.0.1:1", GrpcPort: uint32(grpcPort), DiskInfos: map[string]*master_pb.DiskInfo{"hdd": { EcShardInfos: []*master_pb.VolumeEcShardInformationMessage{{ Id: volumeID, EcIndexBits: uint32(1)<