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.
This commit is contained in:
Chris Lu committed 2026-12-06 00:40:39 -08:00
1 parent f81b0e3a49
commit 29ca7f3fe3
4 files changed
+18 -12

No files matched your search

+7 -7
View File
@@ -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)
}
}
}
@@ -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
@@ -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},
@@ -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)<<erasure_coding.TotalShardsCount - 1,