diff --git a/seaweed-block/core/frontend/durable/precopy_wait_test.go b/seaweed-block/core/frontend/durable/precopy_wait_test.go index 1704615260..549506474f 100644 --- a/seaweed-block/core/frontend/durable/precopy_wait_test.go +++ b/seaweed-block/core/frontend/durable/precopy_wait_test.go @@ -102,3 +102,59 @@ func TestPrecopyFreezeCallerDeadlineIsRetryable(t *testing.T) { t.Fatalf("deadline lost retryable admission status: %v", err) } } + +func TestPrecopyFreezeTerminalStopWakesQueuedIO(t *testing.T) { + for _, terminal := range []string{"close", "stop"} { + t.Run(terminal, func(t *testing.T) { + p := precopyProvider(t, storage.NewMemChunkRemote(), &parkView{stubView: v1View()}) + openRecovered(t, p) + b, err := p.Open(context.Background(), "v1") + if err != nil { + t.Fatal(err) + } + gate := b.(interface { + TryStopIO(string) bool + SetOperational(bool, string) + }) + if !gate.TryStopIO("pre-copy final cut") { + t.Fatal("freeze failed") + } + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + started, done := make(chan struct{}), make(chan struct{}) + var result error + t.Cleanup(func() { + cancel() + gate.SetOperational(false, "cleanup") + select { + case <-done: + case <-time.After(3 * time.Second): + t.Error("queued command did not join") + } + }) + go func() { defer close(done); close(started); _, result = b.Write(ctx, 4096, block(9)) }() + <-started + select { + case <-done: + t.Fatalf("command escaped freeze: %v", result) + case <-time.After(30 * time.Millisecond): + } + want := frontend.ErrNotReady + if terminal == "close" { + want = frontend.ErrBackendClosed + if err := b.Close(); err != nil { + t.Fatal(err) + } + } else { + gate.SetOperational(false, "workspace lease self-fence") + } + select { + case <-done: + if !errors.Is(result, want) || errors.Is(result, frontend.ErrBackendBusy) { + t.Fatalf("terminal gate masked: %v", result) + } + case <-time.After(time.Second): + t.Fatal("terminal stop did not wake command") + } + }) + } +} diff --git a/seaweed-block/core/frontend/durable/storage_adapter.go b/seaweed-block/core/frontend/durable/storage_adapter.go index 52ddfa13b4..62ff9d0184 100644 --- a/seaweed-block/core/frontend/durable/storage_adapter.go +++ b/seaweed-block/core/frontend/durable/storage_adapter.go @@ -162,8 +162,8 @@ type StorageBackend struct { // false; provider flips true after Recover() succeeds (T3b). // opEvidence is the reason reported when operational=false // (e.g., "awaiting recovery", "local epoch ahead of assignment"). - // Only a successfully recovered chunk volume awaiting attachment may wait. - // waitAttachReady and readyChanged are protected by mu. + // Readiness waits cover pending chunk attachment and temporary pre-copy freezes. + // Readiness flags and readyChanged are protected by mu. waitAttachReady bool waitPrecopyReady bool // temporary pre-copy freeze; queued I/O has not reached storage readyChanged chan struct{}