From c6bace4e794ffe95d913b390b9538e839b23ea57 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 27 Apr 2026 00:59:33 -0700 Subject: [PATCH] G5-5 upstream instrumentation: observer + OnLocalWrite + ship gates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QA round 8: ALL 6 ship/dial/barrier lines from 7a3996d are missing. The replication outer loop is not running at all. Need to walk upstream to find where the fan-out chain breaks. Add 4 INFO log lines at the upstream surfaces: durable/storage_adapter.go (writeBytes observer dispatch): - obs nil: 'write observer NIL — replication fan-out skipped' (means SetWriteObserver wasn't called before write hit) - obs ok: 'write observer dispatch lba=N lsn=N' replication/volume.go (OnLocalWrite entry): - 'OnLocalWrite volume=v1 lba=N lsn=N peers=K' (lets us see if peers map is empty even though UpdateReplicaSet returned ok) replication/peer.go (ShipEntry early-exit gates): - 'ship gate-close peer=r2 lba=N lsn=N (peer closed)' - 'ship gate-degraded peer=r2 lba=N lsn=N (peer degraded)' (the existing logs are AFTER these gates, so silent early-exit was indistinguishable from no-call) These 4 lines + the existing 7a3996d 6 lines = 10 total. With the next re-run we should see exactly which hop fails: Expected per iSCSI WRITE on primary: durable: write observer dispatch lba=0 lsn=1 replication: OnLocalWrite volume=v1 lba=0 lsn=1 peers=1 transport: ship lazy-dial replica=r2 ... replication: ship ok peer=r2 ... If 'observer NIL' appears: SetWriteObserver wiring race — observer not set when iSCSI starts writing. If OnLocalWrite shows peers=0: UpdateReplicaSet ok but peers map became empty (race with stale-gen replay tearing down peers?). If 'ship gate-close' / 'ship gate-degraded' appears: peer state transitioned bad before any ship attempt. If none of the above + ship lines silent: Backend.writeBytes itself is bypassed (iSCSI handler not going through StorageBackend). Tests still green. Refs: QA round 8 — 7a3996d logs all silent on ship path. --- .../core/frontend/durable/storage_adapter.go | 11 ++++++++++- seaweed-block/core/replication/peer.go | 4 ++++ seaweed-block/core/replication/volume.go | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/seaweed-block/core/frontend/durable/storage_adapter.go b/seaweed-block/core/frontend/durable/storage_adapter.go index 2aa5a1c40c..af5db9c674 100644 --- a/seaweed-block/core/frontend/durable/storage_adapter.go +++ b/seaweed-block/core/frontend/durable/storage_adapter.go @@ -379,7 +379,16 @@ func (b *StorageBackend) writeBytes(ctx context.Context, offset int64, p []byte) b.mu.Lock() obs := b.observer b.mu.Unlock() - if obs != nil { + // G5-5 instrumentation: log every write hit to the observer + // hook so we can disambiguate "WriteObserver never wired" from + // "wired but fan-out fails downstream". obs==nil at write time + // indicates SetWriteObserver wasn't called BEFORE the iSCSI + // initiator started writing — a timing race in main.go. + if obs == nil { + log.Printf("durable: write observer NIL — replication fan-out skipped (lba=%d lsn=%d) — SetWriteObserver not yet wired", + lba, lsn) + } else { + log.Printf("durable: write observer dispatch lba=%d lsn=%d", lba, lsn) if werr := obs.Observe(ctx, lba, lsn, block); werr != nil { log.Printf("durable: replication fan-out failed lba=%d lsn=%d: %v", lba, lsn, werr) diff --git a/seaweed-block/core/replication/peer.go b/seaweed-block/core/replication/peer.go index 72fbd05b8c..34a6abe1a4 100644 --- a/seaweed-block/core/replication/peer.go +++ b/seaweed-block/core/replication/peer.go @@ -187,10 +187,14 @@ func (p *ReplicaPeer) ShipEntry(ctx context.Context, lineage transport.RecoveryL p.mu.Lock() if p.closed { p.mu.Unlock() + log.Printf("replication: ship gate-close peer=%s lba=%d lsn=%d (peer closed)", + p.target.ReplicaID, lba, lsn) return fmt.Errorf("replication: ShipEntry: peer %s closed", p.target.ReplicaID) } if p.state == ReplicaDegraded { p.mu.Unlock() + log.Printf("replication: ship gate-degraded peer=%s lba=%d lsn=%d (peer degraded)", + p.target.ReplicaID, lba, lsn) return fmt.Errorf("replication: ShipEntry: peer %s degraded", p.target.ReplicaID) } peerLineage := p.lineage diff --git a/seaweed-block/core/replication/volume.go b/seaweed-block/core/replication/volume.go index 7658e808bf..424bff732e 100644 --- a/seaweed-block/core/replication/volume.go +++ b/seaweed-block/core/replication/volume.go @@ -336,6 +336,11 @@ func (v *ReplicationVolume) OnLocalWrite(ctx context.Context, w LocalWrite) erro if v.closed { return fmt.Errorf("replication: OnLocalWrite: volume %s closed", v.volumeID) } + // G5-5 instrumentation: log entry with peer count so we can + // disambiguate "OnLocalWrite never called" vs "called but + // peers map is empty" vs "called and fans out". + log.Printf("replication: OnLocalWrite volume=%s lba=%d lsn=%d peers=%d", + v.volumeID, w.LBA, w.LSN, len(v.peers)) // Fan out under the mutex — LSN-order invariant (Condition A). // Lineage is informational; each peer uses its own registered