G9F: split node data and control addresses

This commit is contained in:
pingqiu committed 2026-05-02 21:33:06 -07:00
1 parent 0b1f278083
commit 8d77ca5b56
4 files changed
+56 -12

No files matched your search

@@ -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,
@@ -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 == "" {
@@ -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
}
@@ -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",