From 8d77ca5b569359e9d2a20bc12eaf02fda472e2e1 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 2 May 2026 21:33:06 -0700 Subject: [PATCH] G9F: split node data and control addresses --- .../core/host/master/lifecycle_test.go | 6 ++-- .../core/lifecycle/node_inventory.go | 12 ++++--- .../core/lifecycle/verified_placement.go | 14 ++++++-- .../core/lifecycle/verified_placement_test.go | 36 +++++++++++++++++-- 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/seaweed-block/core/host/master/lifecycle_test.go b/seaweed-block/core/host/master/lifecycle_test.go index 06b424448d..48798e7d5a 100644 --- a/seaweed-block/core/host/master/lifecycle_test.go +++ b/seaweed-block/core/host/master/lifecycle_test.go @@ -36,7 +36,8 @@ func TestMasterLifecycleStore_OpensRegistrationStoresWithoutAuthority(t *testing } if _, err := stores.Nodes.RegisterNode(lifecycle.NodeRegistration{ ServerID: "node-a", - Addr: "127.0.0.1:9101", + DataAddr: "127.0.0.1:9201", + CtrlAddr: "127.0.0.1:9101", Pools: []lifecycle.StoragePool{{ PoolID: "pool-a", TotalBytes: 1 << 30, @@ -48,7 +49,8 @@ func TestMasterLifecycleStore_OpensRegistrationStoresWithoutAuthority(t *testing } if _, err := stores.Nodes.RegisterNode(lifecycle.NodeRegistration{ ServerID: "node-b", - Addr: "127.0.0.1:9102", + DataAddr: "127.0.0.1:9202", + CtrlAddr: "127.0.0.1:9102", Pools: []lifecycle.StoragePool{{ PoolID: "pool-b", TotalBytes: 1 << 30, diff --git a/seaweed-block/core/lifecycle/node_inventory.go b/seaweed-block/core/lifecycle/node_inventory.go index d290c97ec9..c6209b19a4 100644 --- a/seaweed-block/core/lifecycle/node_inventory.go +++ b/seaweed-block/core/lifecycle/node_inventory.go @@ -41,8 +41,12 @@ type ReplicaInventory struct { // registration or heartbeat ingestion. It deliberately has no authority // fields. type NodeRegistration struct { - ServerID string `json:"server_id"` - Addr string `json:"addr"` + ServerID string `json:"server_id"` + // Addr is legacy node-level address. DataAddr/CtrlAddr are the + // explicit block data/control endpoints used by G9F verification. + Addr string `json:"addr,omitempty"` + DataAddr string `json:"data_addr,omitempty"` + CtrlAddr string `json:"ctrl_addr,omitempty"` Labels map[string]string `json:"labels,omitempty"` Pools []StoragePool `json:"pools,omitempty"` Replicas []ReplicaInventory `json:"replicas,omitempty"` @@ -198,8 +202,8 @@ func validateNodeRegistration(reg NodeRegistration) error { if err := validateServerID(reg.ServerID); err != nil { return err } - if reg.Addr == "" { - return fmt.Errorf("%w: empty addr", ErrInvalidNodeRegistration) + if reg.Addr == "" && (reg.DataAddr == "" || reg.CtrlAddr == "") { + return fmt.Errorf("%w: empty address; provide addr or data_addr+ctrl_addr", ErrInvalidNodeRegistration) } for _, pool := range reg.Pools { if pool.PoolID == "" { diff --git a/seaweed-block/core/lifecycle/verified_placement.go b/seaweed-block/core/lifecycle/verified_placement.go index 0e6436622b..287fc9ca1f 100644 --- a/seaweed-block/core/lifecycle/verified_placement.go +++ b/seaweed-block/core/lifecycle/verified_placement.go @@ -71,7 +71,8 @@ func VerifyPlacementIntent(intent PlacementIntent, nodes []NodeRegistration, cfg out.Reason = VerifyReasonStaleObservation return out } - if node.Addr == "" { + dataAddr, ctrlAddr := nodePlacementAddrs(node) + if dataAddr == "" || ctrlAddr == "" { out.Reason = VerifyReasonMissingAddress return out } @@ -80,8 +81,8 @@ func VerifyPlacementIntent(intent PlacementIntent, nodes []NodeRegistration, cfg PoolID: slot.PoolID, ReplicaID: slot.ReplicaID, Source: slot.Source, - DataAddr: node.Addr, - CtrlAddr: node.Addr, + DataAddr: dataAddr, + CtrlAddr: ctrlAddr, VerifiedBy: VerifiedByNodeRegistration, } if slot.Source == PlacementSourceExistingReplica { @@ -96,3 +97,10 @@ func VerifyPlacementIntent(intent PlacementIntent, nodes []NodeRegistration, cfg out.Verified = true return out } + +func nodePlacementAddrs(node NodeRegistration) (dataAddr, ctrlAddr string) { + if node.DataAddr != "" || node.CtrlAddr != "" { + return node.DataAddr, node.CtrlAddr + } + return node.Addr, node.Addr +} diff --git a/seaweed-block/core/lifecycle/verified_placement_test.go b/seaweed-block/core/lifecycle/verified_placement_test.go index cbf49172e4..ac4413d806 100644 --- a/seaweed-block/core/lifecycle/verified_placement_test.go +++ b/seaweed-block/core/lifecycle/verified_placement_test.go @@ -37,7 +37,8 @@ func TestG9F_PlacementIntentWithStaleObservation_DoesNotVerify(t *testing.T) { } got := VerifyPlacementIntent(intent, []NodeRegistration{{ ServerID: "node-a", - Addr: "127.0.0.1:9101", + DataAddr: "127.0.0.1:9201", + CtrlAddr: "127.0.0.1:9101", SeenAt: now.Add(-2 * time.Minute), }}, VerificationConfig{Now: now, FreshnessWindow: time.Minute}) if got.Verified { @@ -72,7 +73,8 @@ func TestG9F_BlankPoolIntentWithFreshObservation_VerifiesCreateNeededSlot(t *tes } got := VerifyPlacementIntent(intent, []NodeRegistration{{ ServerID: "node-a", - Addr: "127.0.0.1:9101", + DataAddr: "127.0.0.1:9201", + CtrlAddr: "127.0.0.1:9101", SeenAt: now, }}, VerificationConfig{Now: now, FreshnessWindow: time.Minute}) if !got.Verified { @@ -88,6 +90,33 @@ func TestG9F_BlankPoolIntentWithFreshObservation_VerifiesCreateNeededSlot(t *tes if slot.DataAddr == "" || slot.CtrlAddr == "" { t.Fatalf("verified slot missing addresses: %+v", slot) } + if slot.DataAddr != "127.0.0.1:9201" || slot.CtrlAddr != "127.0.0.1:9101" { + t.Fatalf("verified slot addresses=%s/%s want explicit data/control addrs", slot.DataAddr, slot.CtrlAddr) + } +} + +func TestG9F_FreshObservationMissingControlAddress_DoesNotVerify(t *testing.T) { + now := time.Date(2026, 5, 2, 12, 0, 0, 0, time.UTC) + intent := PlacementIntent{ + VolumeID: "vol-a", + DesiredRF: 1, + Slots: []PlacementSlotIntent{{ + ServerID: "node-a", + PoolID: "pool-a", + Source: PlacementSourceBlankPool, + }}, + } + got := VerifyPlacementIntent(intent, []NodeRegistration{{ + ServerID: "node-a", + DataAddr: "127.0.0.1:9201", + SeenAt: now, + }}, VerificationConfig{Now: now, FreshnessWindow: time.Minute}) + if got.Verified { + t.Fatalf("missing control address verified: %+v", got) + } + if got.Reason != VerifyReasonMissingAddress { + t.Fatalf("reason=%q want %q", got.Reason, VerifyReasonMissingAddress) + } } func TestG9F_ExistingReplicaIntentWithWrongInventory_DoesNotVerify(t *testing.T) { @@ -103,7 +132,8 @@ func TestG9F_ExistingReplicaIntentWithWrongInventory_DoesNotVerify(t *testing.T) } got := VerifyPlacementIntent(intent, []NodeRegistration{{ ServerID: "node-a", - Addr: "127.0.0.1:9101", + DataAddr: "127.0.0.1:9201", + CtrlAddr: "127.0.0.1:9101", SeenAt: now, Replicas: []ReplicaInventory{{ VolumeID: "vol-a",