mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
fix, transport: attest without activating an unsent WAL sender
This commit is contained in:
1 parent
cc5941598a
commit
76c857bd74
2 files changed
+57
-5
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
"github.com/seaweedfs/seaweed-block/core/storage/memorywal"
|
||||
)
|
||||
|
||||
// No other goroutine uses the write mutex in this fixture, so a successful
|
||||
@@ -16,6 +17,44 @@ type barrierWriteOwnerConn struct {
|
||||
owner *sync.Mutex
|
||||
}
|
||||
|
||||
func TestAnAttestationBarrierDoesNotConsumeUnsentWAL(t *testing.T) {
|
||||
_, _, listener := setupPrimaryReplica(t)
|
||||
primary := memorywal.NewStore(64, 4096)
|
||||
e := NewBlockExecutor(primary, listener.Addr())
|
||||
defer e.Stop()
|
||||
lineage := shipTestLineage()
|
||||
if err := e.registerShipSessionForTest(lineage); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := e.Barrier("r1", lineage, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data := make([]byte, 4096)
|
||||
data[0] = 0x5a
|
||||
lsn, err := primary.Write(0, data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Force the timer's causal drain opportunity before the first Ship
|
||||
// installs an emit connection. A barrier must not start such a sender.
|
||||
e.walShipperMu.Lock()
|
||||
entry := e.walShippers["r1"]
|
||||
e.walShipperMu.Unlock()
|
||||
if entry != nil {
|
||||
entry.shipper.drainOpportunity()
|
||||
}
|
||||
if err := e.Ship("r1", lineage, 0, lsn, data); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ack, err := e.Barrier("r1", lineage, lsn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ack.AchievedLSN < lsn {
|
||||
t.Fatalf("barrier-created sender consumed unsent WAL: replica end %d, wanted %d", ack.AchievedLSN, lsn)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *barrierWriteOwnerConn) Write(p []byte) (int, error) {
|
||||
if c.owner.TryLock() {
|
||||
c.owner.Unlock()
|
||||
|
||||
@@ -577,11 +577,7 @@ func (e *BlockExecutor) Barrier(replicaID string, lineage RecoveryLineage, front
|
||||
// emitConn. Its timer can write outside the peer worker, so the request
|
||||
// uses the existing frame writer shared with emit/recovery. The peer
|
||||
// queue remains the owner of the request/response exchange.
|
||||
e.WalShipperFor(replicaID)
|
||||
writeMu := e.WalShipperWriteMu(replicaID)
|
||||
writeMu.Lock()
|
||||
sendErr := sendBarrierReq(conn, lineage, recoveryConnTimeout)
|
||||
writeMu.Unlock()
|
||||
sendErr := e.sendSessionBarrier(replicaID, conn, lineage)
|
||||
if err := sendErr; err != nil {
|
||||
e.detachConn(session, conn)
|
||||
_ = conn.Close()
|
||||
@@ -613,6 +609,23 @@ func (e *BlockExecutor) Barrier(replicaID string, lineage RecoveryLineage, front
|
||||
}, nil
|
||||
}
|
||||
|
||||
// sendSessionBarrier shares the existing emitter's frame writer without
|
||||
// constructing/activating a sender just to attest a store. Before any emitter
|
||||
// exists, its registry lock excludes creation until the request frame is sent.
|
||||
// Lock order is registry -> frame writer, never the reverse.
|
||||
func (e *BlockExecutor) sendSessionBarrier(replicaID string, conn net.Conn, lineage RecoveryLineage) error {
|
||||
e.walShipperMu.Lock()
|
||||
entry := e.walShippers[replicaID]
|
||||
if entry == nil {
|
||||
defer e.walShipperMu.Unlock()
|
||||
return sendBarrierReq(conn, lineage, recoveryConnTimeout)
|
||||
}
|
||||
entry.writeMu.Lock()
|
||||
e.walShipperMu.Unlock()
|
||||
defer entry.writeMu.Unlock()
|
||||
return sendBarrierReq(conn, lineage, recoveryConnTimeout)
|
||||
}
|
||||
|
||||
func (e *BlockExecutor) fireFenceComplete(result adapter.FenceResult) {
|
||||
e.mu.Lock()
|
||||
if e.stopped {
|
||||
|
||||
Reference in new issue
Block a user