mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
fix: iSCSI CSI paths bind IQN and LUN; live-renewal held-registration control; lease diagram guard
codex01 review of #416 3439d278 (INV-AUTH-HOLDER-IDENTITY-001, INV-WS-RENEW-NONBLOCKING-001): - P1: primaryOwnedFrontends keys an iSCSI target by IQN AND LUN, so a supporting q/LUN2 never becomes a multipath path of the primary's q/LUN1 (mismatch and nonzero-match controls). - P2: TestLiveRenewalDoesNotWaitForAHeldRegistrationWrite renews through holderMatches over gRPC while a registration write is held (NodeInventoryStore.HoldWritesForTest), and shows the hold is real. - Standards: the workspace lease diagram's holder edges name the registered-host guard; the snapshot test's control reader has a bounded, owned join. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e7d0114b1d
commit
8d103b2c85
6 files changed
+93
-7
No files matched your search
@@ -256,7 +256,7 @@ func publishTargetFromStatus(resp *control.StatusResponse, enableMultipath bool,
|
||||
|
||||
// primaryOwnedFrontends applies INV-AUTH-HOLDER-IDENTITY-001 when the master tags each frontend with its replica: the
|
||||
// usable frontends of the primary replica come first, and another replica's frontend is kept only as an extra path to a
|
||||
// target the primary itself serves (same IQN, or same NQN/NSID/transport). No usable primary frontend: none at all, so
|
||||
// target the primary itself serves (same IQN and LUN, or same NQN/NSID/transport). No usable primary frontend: none at all, so
|
||||
// a supporting replica is never published under the primary identity. An untagged (older) response is returned as is.
|
||||
func primaryOwnedFrontends(resp *control.StatusResponse, rejectLoopback bool) ([]*control.FrontendTarget, bool) {
|
||||
tagged := false
|
||||
@@ -273,7 +273,7 @@ func primaryOwnedFrontends(resp *control.StatusResponse, rejectLoopback bool) ([
|
||||
case ft.GetAddr() == "" || rejectFrontendAddr(ft.GetAddr(), rejectLoopback):
|
||||
return "", false
|
||||
case ft.GetProtocol() == string(ProtocolISCSI) && ft.GetIqn() != "":
|
||||
return "iscsi\x00" + ft.GetIqn(), true
|
||||
return "iscsi\x00" + ft.GetIqn() + "\x00" + strconv.FormatUint(uint64(ft.GetLun()), 10), true // IQN AND LUN
|
||||
case ft.GetProtocol() == string(ProtocolNVMe) && ft.GetNqn() != "":
|
||||
return "nvme\x00" + ft.GetNqn() + "\x00" + strconv.FormatUint(uint64(ft.GetNsid()), 10) + "\x00" +
|
||||
string(normalizeFrontendTransport(ProtocolNVMe, FrontendTransport(ft.GetTransport()))), true
|
||||
|
||||
@@ -33,6 +33,18 @@ func TestPublishTargetIsPrimaryOwned(t *testing.T) {
|
||||
if !ok || got.ISCSIAddr != "192.0.2.1:3260" || got.Multipath || got.IQN != "iqn.v1" {
|
||||
t.Fatalf("foreign target: %+v ok=%v, want only the primary's", got, ok)
|
||||
}
|
||||
// iSCSI paths match on IQN AND LUN (codex01): a supporting q/LUN2 is another target, never a path to the primary's q/LUN1
|
||||
lun := func(replica, addr string, n uint32) *control.FrontendTarget {
|
||||
return &control.FrontendTarget{Protocol: string(ProtocolISCSI), Addr: addr, Iqn: "iqn.q", Lun: n, ReplicaId: replica}
|
||||
}
|
||||
got, ok = publishTargetFromStatus(status(lun("r1", "192.0.2.1:3260", 1), lun("r2", "192.0.2.2:3260", 2)), true, false)
|
||||
if !ok || got.ISCSIAddr != "192.0.2.1:3260" || got.LUN != 1 || got.Multipath || len(got.ISCSIAddrs) != 0 {
|
||||
t.Fatalf("LUN mismatch: %+v ok=%v, want only the primary's q/LUN1 (no multipath)", got, ok)
|
||||
}
|
||||
got, ok = publishTargetFromStatus(status(lun("r1", "192.0.2.1:3260", 1), lun("r2", "192.0.2.2:3260", 1)), true, false)
|
||||
if !ok || got.LUN != 1 || !got.Multipath || len(got.ISCSIAddrs) != 2 || got.ISCSIAddrs[0] != "192.0.2.1:3260" {
|
||||
t.Fatalf("nonzero LUN match: %+v ok=%v, want multipath primary-first at LUN 1", got, ok)
|
||||
}
|
||||
// no primary frontend at all, supporting present: no target
|
||||
if got, ok := publishTargetFromStatus(status(ft("r2", "192.0.2.2:3260", "iqn.v1")), false, false); ok {
|
||||
t.Fatalf("no primary frontend: published %+v, want no target", got)
|
||||
|
||||
@@ -397,3 +397,57 @@ func TestDeletionReservedWorkspaceVolumeKeepsTheStreamHostCheck(t *testing.T) {
|
||||
t.Fatalf("deletion-reserved workspace volume, stream from another host: %v, want the host refusal", err)
|
||||
}
|
||||
}
|
||||
|
||||
// codex01 #416 P2 (INV-WS-RENEW-NONBLOCKING-001): a LIVE lease renewal through holderMatches, whose host check reads the
|
||||
// node registry, completes while a registration write is held (the store mutex RegisterNode keeps across file I/O). The
|
||||
// hold is proven real: a concurrent RegisterNode does not finish until it is released.
|
||||
func TestLiveRenewalDoesNotWaitForAHeldRegistrationWrite(t *testing.T) {
|
||||
r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) // node-a registered on 127.0.0.1
|
||||
r.createVolume(t, "w3")
|
||||
if _, err := r.m.Lifecycle().Placements.ApplyPlan(lifecycle.PlacementPlan{VolumeID: "w3", DesiredRF: 1,
|
||||
Candidates: []lifecycle.PlacementCandidate{{VolumeID: "w3", ServerID: "node-a", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := r.obs.ReportHeartbeat(r.ctx, &control.HeartbeatReport{ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true,
|
||||
Slots: []*control.HeartbeatSlot{{VolumeId: "w3", ReplicaId: "r1", DataAddr: "127.0.0.1:19131", CtrlAddr: "127.0.0.1:19132"}}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := r.m.RunLifecycleProductTick(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
line := waitAuthorityLine(t, r.m.Publisher(), "w3")
|
||||
id := &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "w3", ReplicaId: "r1", Epoch: line.Epoch}
|
||||
if _, err := r.ws.RenewWorkspaceLease(r.ctx, id); err != nil {
|
||||
t.Fatalf("first grant: %v", err)
|
||||
}
|
||||
release := r.m.Lifecycle().Nodes.HoldWritesForTest()
|
||||
writer := make(chan struct{})
|
||||
t.Cleanup(func() {
|
||||
release()
|
||||
select {
|
||||
case <-writer:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Error("held registration writer did not join")
|
||||
}
|
||||
})
|
||||
go func() {
|
||||
defer close(writer)
|
||||
_, _ = r.m.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: "node-c", DataAddr: "127.0.0.1:19501", CtrlAddr: "127.0.0.1:19502"})
|
||||
}()
|
||||
ctx, cancel := context.WithTimeout(r.ctx, time.Second)
|
||||
defer cancel()
|
||||
if _, err := r.ws.RenewWorkspaceLease(ctx, id); err != nil {
|
||||
t.Fatalf("live renewal during a held registration write: %v (it must not wait on the registry store)", err)
|
||||
}
|
||||
select {
|
||||
case <-writer:
|
||||
t.Fatal("control: the registration write was not actually held")
|
||||
default:
|
||||
}
|
||||
release()
|
||||
select {
|
||||
case <-writer:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("registration write did not finish after the release")
|
||||
}
|
||||
}
|
||||
@@ -102,6 +102,14 @@ func (s *NodeInventoryStore) GetNodeSnapshot(serverID string) (NodeRegistration,
|
||||
return copyNodeRegistration(v.(NodeRegistration)), true
|
||||
}
|
||||
|
||||
// HoldWritesForTest takes the mutex a registration write holds across file I/O and returns its release (idempotent):
|
||||
// a held registration write, for controls that a reader (the holder host check) never waits on it. Tests only.
|
||||
func (s *NodeInventoryStore) HoldWritesForTest() (release func()) {
|
||||
s.mu.Lock()
|
||||
var once sync.Once
|
||||
return func() { once.Do(s.mu.Unlock) }
|
||||
}
|
||||
|
||||
// RegisterNode records the latest observed inventory for a server.
|
||||
// Repeating registration replaces observation fields, but still does not
|
||||
// publish authority or readiness.
|
||||
|
||||
@@ -41,13 +41,25 @@ func TestNodeSnapshotDoesNotWaitForARegistrationWrite(t *testing.T) {
|
||||
// control: the mutex-taking read does wait while the write is held
|
||||
blocked := make(chan struct{})
|
||||
go func() { _, _ = s.GetNode("node-a"); close(blocked) }()
|
||||
t.Cleanup(func() {
|
||||
release()
|
||||
select {
|
||||
case <-blocked:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Error("control reader did not join")
|
||||
}
|
||||
})
|
||||
select {
|
||||
case <-blocked:
|
||||
t.Fatal("control: GetNode did not wait for the held registration write")
|
||||
case <-time.After(200 * time.Millisecond):
|
||||
}
|
||||
release()
|
||||
<-blocked
|
||||
select {
|
||||
case <-blocked:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("control reader did not finish after the release")
|
||||
}
|
||||
if got.DataAddr != "127.0.0.1:19101" {
|
||||
t.Fatalf("wrong committed registration: %+v", got)
|
||||
}
|
||||
|
||||
@@ -354,14 +354,14 @@ Lease states:
|
||||
```mermaid
|
||||
stateDiagram-v2
|
||||
state "Lease (blockmaster)" as L {
|
||||
[*] --> Granted: first Renew after bind
|
||||
[*] --> Granted: first Renew after bind (registered server id, from its registered host)
|
||||
[*] --> Granted: move issue starts the new holder's lease
|
||||
Granted --> Granted: Renew before horizon and deadline (from memory)
|
||||
Granted --> Granted: Renew before horizon and deadline (from memory; registered server id, from its registered host)
|
||||
Granted --> Revoking: BeginWorkspaceRevocation
|
||||
Revoking --> Acked: host acks detached HEAD gen while the lease is valid
|
||||
Revoking --> Acked: host acks detached HEAD gen while the lease is valid (from its registered host)
|
||||
Acked --> Moved: CLEAN move, including same host, new epoch
|
||||
Granted --> Expired: horizon or deadline passes
|
||||
Expired --> Granted: unchanged holder, no move/revocation, MAX expiry + skew passed; durable re-grant
|
||||
Expired --> Granted: unchanged holder from its registered host, no move/revocation, MAX expiry + skew passed; durable re-grant
|
||||
Expired --> Moved: FORCED move after expiry + skew bound, then HEAD read (an older-epoch HEAD is accepted)
|
||||
}
|
||||
```
|
||||
|
||||
Reference in new issue
Block a user