mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-05-14 05:41:29 +00:00
Ping previously dialled whatever host:port the caller asked for. Gate each server's Ping handler on cluster membership: masters check the topology, registered cluster nodes, and configured master peers; volume servers only accept their seed/current masters; filers accept tracked peer filers, the master-learned volume server set, and configured masters. Use address-indexed peer lookups to keep Ping target validation O(1): - topology maintains a pb.ServerAddress -> *DataNode index alongside the dc/rack/node tree, kept in sync from doLinkChildNode and UnlinkChildNode plus the ip/port-rewrite branch in GetOrCreateDataNode. GetTopology now returns nil on a detached subtree instead of panicking, so the linkage hooks can no-op safely. - vid_map tracks a refcount per volume-server address so hasVolumeServer answers without scanning every vid location. The add path skips empty-address entries the same way the delete path already does, so a zero-value Location cannot leak a permanent serverRefCount[""] bucket. - masters reuse a cached master-address set from MasterClient instead of walking the configured peer slice on every request. - volume servers compare against a pre-built seed-master set and protect currentMaster reads/writes with an RWMutex, fixing the data race with the heartbeat goroutine. The seed slice is copied on construction so external mutation cannot desync it from the frozen lookup set. - cluster.check drops the direct volume-to-volume sweep; volume servers no longer carry a peer-volume list, and the note next to the dropped probe is reworded to make clear that direct volume-to-volume reachability is intentionally not validated by this command. Update the volume-server integration tests that drove Ping through the new admission gate: success-path coverage now targets the master peer (the only type a volume server tracks), and the unknown/unreachable path asserts the InvalidArgument the gate now returns instead of the old downstream dial error. Mirror the same admission gate in the Rust volume server crate: a seed-master HashSet built once at startup plus a tokio RwLock over the heartbeat-tracked current master, both consulted in is_known_ping_target on every Ping, with InvalidArgument returned for any target that isn't a recognised master.
98 lines
3.1 KiB
Go
98 lines
3.1 KiB
Go
package weed_server
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/cluster"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/sequence"
|
|
"github.com/seaweedfs/seaweedfs/weed/topology"
|
|
)
|
|
|
|
func TestMasterIsKnownPingTarget(t *testing.T) {
|
|
topo := topology.NewTopology("test", sequence.NewMemorySequencer(), 32*1024, 5, false)
|
|
dc := topology.NewDataCenter("dc1")
|
|
topo.LinkChildNode(dc)
|
|
rack := topology.NewRack("rack1")
|
|
dc.LinkChildNode(rack)
|
|
|
|
dn := topology.NewDataNode("vol1")
|
|
dn.Ip = "10.0.0.10"
|
|
dn.Port = 8080
|
|
dn.GrpcPort = 18080
|
|
rack.LinkChildNode(dn)
|
|
|
|
c := cluster.NewCluster()
|
|
filerAddr := pb.ServerAddress("10.0.0.20:8888")
|
|
c.AddClusterNode("", cluster.FilerType, "dc1", "rack1", filerAddr, "test")
|
|
|
|
ms := &MasterServer{
|
|
option: &MasterOption{Master: pb.ServerAddress("10.0.0.1:9333")},
|
|
Topo: topo,
|
|
Cluster: c,
|
|
}
|
|
|
|
ctx := context.Background()
|
|
cases := []struct {
|
|
name string
|
|
target string
|
|
targetType string
|
|
want bool
|
|
}{
|
|
{"known filer", string(filerAddr), cluster.FilerType, true},
|
|
{"known volume server", "10.0.0.10:8080.18080", cluster.VolumeServerType, true},
|
|
{"known volume server http addr", "10.0.0.10:8080", cluster.VolumeServerType, true},
|
|
{"known self master", "10.0.0.1:9333", cluster.MasterType, true},
|
|
{"unknown localhost low port", "127.0.0.1:1", cluster.VolumeServerType, false},
|
|
{"unknown localhost high port", "127.0.0.1:65000", cluster.FilerType, false},
|
|
{"unrelated host", "example.com:443", cluster.MasterType, false},
|
|
{"unknown target type", string(filerAddr), "garbage", false},
|
|
{"filer address checked as volume server", string(filerAddr), cluster.VolumeServerType, false},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
tc := tc
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := ms.isKnownPingTarget(ctx, tc.target, tc.targetType)
|
|
if got != tc.want {
|
|
t.Fatalf("isKnownPingTarget(%q,%q) = %v, want %v", tc.target, tc.targetType, got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestVolumeServerIsKnownPingTarget(t *testing.T) {
|
|
seed := pb.ServerAddress("10.0.0.1:9333")
|
|
vs := &VolumeServer{
|
|
SeedMasterNodes: []pb.ServerAddress{seed},
|
|
seedMasterSet: map[string]struct{}{seed.ToHttpAddress(): {}},
|
|
}
|
|
vs.setCurrentMaster(pb.ServerAddress("10.0.0.2:9333"))
|
|
|
|
cases := []struct {
|
|
name string
|
|
target string
|
|
targetType string
|
|
want bool
|
|
}{
|
|
{"seed master", string(seed), cluster.MasterType, true},
|
|
{"current master", "10.0.0.2:9333", cluster.MasterType, true},
|
|
{"other volume server", "10.0.0.5:8080", cluster.VolumeServerType, false},
|
|
{"random filer", "10.0.0.6:8888", cluster.FilerType, false},
|
|
{"unknown low port", "127.0.0.1:1", cluster.MasterType, false},
|
|
{"unknown high port", "127.0.0.1:65000", cluster.MasterType, false},
|
|
{"unrelated host", "example.com:443", cluster.MasterType, false},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
tc := tc
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := vs.isKnownPingTarget(tc.target, tc.targetType)
|
|
if got != tc.want {
|
|
t.Fatalf("isKnownPingTarget(%q,%q) = %v, want %v", tc.target, tc.targetType, got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|