mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
durable: a refused observer rebase never leaves I/O open; seed and install serialized
SetWriteObserver published the observer first and only logged a refused ship-LSN rebase, so the volume kept serving writes its observer would mis-order. Now: - SetWriteObserver rebases an LSN-ordering observer to the store's next LSN before installing it. If the rebase is refused, the observer is not installed and the error is returned. The backend also records the fault and refuses every I/O until an install succeeds, so a later attach that marks the volume operational cannot reopen it. blockvolume reports the error. - The frontier seed and its observer rebase run in one critical section with observer installs (observerMu). Whichever runs second sees the other's result; a seed landing between an install's rebase and its publication can no longer leave the observer on the old LSN. A refused rebase after the seed records the same fault. - RebaseShipLSN documents that it moves only the ordering cursor: entries already dispatched to peer queues carry lower LSNs and are untouched. The composition test checks the install error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ea4f986b67
commit
273ca809d8
5 files changed
+71
-26
No files matched your search
@@ -805,7 +805,10 @@ func run(f flags) int {
|
||||
// for primary-role frontend bind). Without this hook, primary
|
||||
// writes would land locally but never ship to peers.
|
||||
if sb := durableProv.Backend(f.volumeID); sb != nil {
|
||||
sb.SetWriteObserver(replVolume)
|
||||
if err := sb.SetWriteObserver(replVolume); err != nil {
|
||||
// The backend now refuses all I/O; the volume cannot serve.
|
||||
fmt.Fprintln(os.Stderr, "blockvolume: write-observer wire:", err)
|
||||
}
|
||||
sb.SetWriteAckPolicy(writeAck)
|
||||
} else {
|
||||
fmt.Fprintln(os.Stderr, "blockvolume: write-observer wire: Backend(", f.volumeID, ") returned nil; replication fan-out disabled")
|
||||
|
||||
@@ -294,15 +294,11 @@ func (p *DurableProvider) newChunkLayer(ctx context.Context, volumeID string, h
|
||||
cfg.FreshFromHead = false
|
||||
return nil
|
||||
}
|
||||
if err := ws.SeedChunkFrontier(head.RemoteLSN); err != nil {
|
||||
return err
|
||||
}
|
||||
// Every component that cached the next LSN learns the seeded
|
||||
// one before the takeover CAS and before the volume serves I/O.
|
||||
if err := h.backend.rebaseShipLSN(); err != nil {
|
||||
return fmt.Errorf("durable: rebase ship LSN after the frontier seed: %w", err)
|
||||
}
|
||||
return nil
|
||||
// one before the takeover CAS and before the volume serves I/O,
|
||||
// serialized with observer installs. A refused rebase fails the
|
||||
// restore here, so HEAD is never claimed for a mis-ordered ship.
|
||||
return h.backend.seedAndRebase(func() error { return ws.SeedChunkFrontier(head.RemoteLSN) })
|
||||
}
|
||||
head, err := storage.ClaimChunkHead(ctx, remote, cfg)
|
||||
if err != nil {
|
||||
|
||||
@@ -169,9 +169,18 @@ type StorageBackend struct {
|
||||
drainMu sync.Mutex
|
||||
drain chan struct{}
|
||||
|
||||
mu sync.Mutex
|
||||
closed bool
|
||||
chunkFenced func() bool // installed under mu; called only after releasing mu
|
||||
mu sync.Mutex
|
||||
closed bool
|
||||
chunkFenced func() bool // installed under mu; called only after releasing mu
|
||||
// observerErr is a refused write-observer install (its ship order
|
||||
// could not follow the store's next LSN). While set, every I/O is
|
||||
// refused, so a volume never serves without its observer. Under mu.
|
||||
observerErr error
|
||||
// observerMu serializes moving the store's next LSN (the frontier
|
||||
// seed) together with rebasing the observer, against installing an
|
||||
// observer together with its rebase: whichever runs second sees the
|
||||
// other's result. Lock order: observerMu, then mu.
|
||||
observerMu sync.Mutex
|
||||
observer WriteObserver // optional; nil = no replication fan-out
|
||||
writeAck WriteAckPolicy
|
||||
profile writeProfile
|
||||
@@ -333,19 +342,39 @@ func (b *StorageBackend) Close() error {
|
||||
// Owns: observer pointer under b.mu.
|
||||
// Borrows: the observer — caller retains ownership; StorageBackend
|
||||
// does not close or otherwise tear down the observer.
|
||||
func (b *StorageBackend) SetWriteObserver(obs WriteObserver) {
|
||||
b.mu.Lock()
|
||||
b.observer = obs
|
||||
b.mu.Unlock()
|
||||
// The store's frontier may have been seeded before the observer was
|
||||
// installed: start its ship order at the store's next LSN.
|
||||
if err := b.rebaseShipLSN(); err != nil {
|
||||
log.Printf("durable: write observer ship LSN: %v", err)
|
||||
//
|
||||
// An observer that orders writes by LSN (ShipLSNRebaser) is first rebased
|
||||
// to the store's next LSN: the frontier may have been seeded before the
|
||||
// install. If that rebase is refused, the observer is NOT installed, the
|
||||
// error is returned, and the backend refuses all I/O until an install
|
||||
// succeeds: a volume never serves writes its observer would mis-order.
|
||||
func (b *StorageBackend) SetWriteObserver(obs WriteObserver) error {
|
||||
b.observerMu.Lock()
|
||||
defer b.observerMu.Unlock()
|
||||
if r, ok := obs.(ShipLSNRebaser); ok {
|
||||
if err := r.RebaseShipLSN(b.storage.NextLSN()); err != nil {
|
||||
err = fmt.Errorf("durable: write observer not installed: ship LSN: %w", err)
|
||||
b.mu.Lock()
|
||||
b.observerErr = err
|
||||
b.mu.Unlock()
|
||||
return err
|
||||
}
|
||||
}
|
||||
b.mu.Lock()
|
||||
b.observer, b.observerErr = obs, nil
|
||||
b.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
// rebaseShipLSN moves an LSN-ordering observer to the store's next LSN.
|
||||
func (b *StorageBackend) rebaseShipLSN() error {
|
||||
// seedAndRebase moves the store's next LSN with seed and, in the same
|
||||
// critical section as observer installs, rebases the installed observer
|
||||
// to it. A refused rebase also closes I/O (as a refused install does).
|
||||
func (b *StorageBackend) seedAndRebase(seed func() error) error {
|
||||
b.observerMu.Lock()
|
||||
defer b.observerMu.Unlock()
|
||||
if err := seed(); err != nil {
|
||||
return err
|
||||
}
|
||||
b.mu.Lock()
|
||||
obs := b.observer
|
||||
b.mu.Unlock()
|
||||
@@ -353,7 +382,14 @@ func (b *StorageBackend) rebaseShipLSN() error {
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return r.RebaseShipLSN(b.storage.NextLSN())
|
||||
if err := r.RebaseShipLSN(b.storage.NextLSN()); err != nil {
|
||||
err = fmt.Errorf("durable: write observer ship LSN after the frontier seed: %w", err)
|
||||
b.mu.Lock()
|
||||
b.observerErr = err
|
||||
b.mu.Unlock()
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetWriteAckPolicy configures whether observer acknowledgement participates
|
||||
@@ -553,10 +589,14 @@ func (b *StorageBackend) readyCheck() error {
|
||||
b.mu.Lock()
|
||||
closed := b.closed
|
||||
chunkFenced := b.chunkFenced
|
||||
observerErr := b.observerErr
|
||||
b.mu.Unlock()
|
||||
if closed {
|
||||
return frontend.ErrBackendClosed
|
||||
}
|
||||
if observerErr != nil {
|
||||
return fmt.Errorf("%w: %v", frontend.ErrNotReady, observerErr)
|
||||
}
|
||||
if chunkFenced != nil && chunkFenced() {
|
||||
return frontend.ErrStalePrimary
|
||||
}
|
||||
|
||||
@@ -99,7 +99,9 @@ func restoredHostWrites(t *testing.T, inheritedLSN uint64, observerAfterSeed boo
|
||||
t.Fatal("no durable backend for v1")
|
||||
}
|
||||
if !observerAfterSeed {
|
||||
sb.SetWriteObserver(rv)
|
||||
if err := sb.SetWriteObserver(rv); err != nil {
|
||||
t.Fatalf("install the write observer: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
openCtx, openCancel := context.WithTimeout(ctx, 10*time.Second)
|
||||
@@ -119,7 +121,9 @@ func restoredHostWrites(t *testing.T, inheritedLSN uint64, observerAfterSeed boo
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
}
|
||||
if observerAfterSeed {
|
||||
sb.SetWriteObserver(rv)
|
||||
if err := sb.SetWriteObserver(rv); err != nil {
|
||||
t.Fatalf("install the write observer: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// A frontend write and flush must complete (bounded here so a hang
|
||||
|
||||
@@ -674,7 +674,9 @@ func (v *ReplicationVolume) enqueueLocalWrite(w LocalWrite) (*orderedLocalWrite,
|
||||
// restored host's frontier seed (its WAL continues at HEAD.remote_lsn+1)
|
||||
// moves that LSN later, and whoever moves it calls this before the volume
|
||||
// serves I/O. It is refused while any write is pending or in flight, never
|
||||
// dropping one, and lsn never moves backwards; equal is a no-op.
|
||||
// dropping one, and lsn never moves backwards; equal is a no-op. It moves
|
||||
// only the ordering cursor: entries already dispatched to peer queues
|
||||
// carry LSNs below it and are untouched (an RF=1 volume has no peers).
|
||||
func (v *ReplicationVolume) RebaseShipLSN(lsn uint64) error {
|
||||
v.orderMu.Lock()
|
||||
defer v.orderMu.Unlock()
|
||||
|
||||
Reference in new issue
Block a user