diff --git a/seaweed-block/cmd/sw-block/chunk_loop.go b/seaweed-block/cmd/sw-block/chunk_loop.go index faaae35a72..8328ea6bec 100644 --- a/seaweed-block/cmd/sw-block/chunk_loop.go +++ b/seaweed-block/cmd/sw-block/chunk_loop.go @@ -66,6 +66,9 @@ func chunkReadBound() time.Duration { return min(2*time.Second, chunkRequestBoun // says so, and a repeat answers from the settled HEAD. A timeout within the // bound sends exactly one request, as before. func chunkPostLoop(name, statusAddr, route string, timeout time.Duration, body map[string]any, stdout, stderr io.Writer) int { + if timeout <= 0 { // INV-CLI-CHUNK-LOOP-001: a non-positive --timeout is refused, never sent as the server's default + return chunkFail(name, stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, "--timeout must be positive", false) + } if timeout <= chunkRequestBound { return chunkPost(name, statusAddr, route, timeout, body, stdout, stderr) } @@ -104,7 +107,9 @@ func chunkPostLoop(name, statusAddr, route string, timeout time.Duration, body m var out, errb bytes.Buffer code := chunkPostUntil(name, statusAddr, route, per, sent.Add(per+cushion), body, &out, &errb) var e chunkErrBody - retry := code != ops.VolumeStatusExitOK && json.Unmarshal(out.Bytes(), &e) == nil && e.Code != "" && e.Retryable + // repeated only after a retryable or outcome_unknown answer (INV-CLI-CHUNK-LOOP-001) + retry := code != ops.VolumeStatusExitOK && json.Unmarshal(out.Bytes(), &e) == nil && e.Code != "" && + (e.Retryable || e.Code == chunkstore.CodeOutcomeUnknown) if !retry { return relay(code, &out, &errb) // an answer, or a refusal a repeat cannot change } diff --git a/seaweed-block/cmd/sw-block/chunk_request_loop_test.go b/seaweed-block/cmd/sw-block/chunk_request_loop_test.go index 4773a21295..3277e78f18 100644 --- a/seaweed-block/cmd/sw-block/chunk_request_loop_test.go +++ b/seaweed-block/cmd/sw-block/chunk_request_loop_test.go @@ -405,6 +405,39 @@ func TestChunkDetachStillUnknownAtTheTimeoutSaysTheVolumeIsStopped(t *testing.T) } } +// INV-CLI-CHUNK-LOOP-001: an outcome_unknown answer is repeated even when it is not marked retryable. +func TestChunkLoopRepeatsAnOutcomeUnknownNotMarkedRetryable(t *testing.T) { + shortLoop(t, 200*time.Millisecond, 10*time.Millisecond, 10*time.Millisecond) + unknown := `{"code":"outcome_unknown","message":"storage: chunk HEAD CAS outcome unknown","retryable":false}` + s := &scripted{replies: []scriptedReply{{503, unknown}, {200, published}}} + srv := s.start(t) + code, out, errs := runChunk("snapshot", "--volume", "v1", "--status-addr", srv.URL, "--name", "s1", "--request-id", "rid-1", "--timeout", "5s") + if code != 0 || out != published || len(s.recorded()) != 2 { + t.Fatalf("exit %d stdout %q stderr %q, %d requests: want the unknown answer repeated and the second answer relayed", code, out, errs, len(s.recorded())) + } +} + +// INV-CLI-CHUNK-LOOP-001: a non-positive --timeout is refused before any request, for snapshot, cut and detach. +func TestChunkNonPositiveTimeoutIsRefused(t *testing.T) { + s := &scripted{replies: []scriptedReply{{200, published}}} + srv := s.start(t) + for _, cmd := range [][]string{ + {"snapshot", "--volume", "v1", "--status-addr", srv.URL, "--name", "s1", "--request-id", "rid-1"}, + {"cut", "--volume", "v1", "--status-addr", srv.URL}, + {"detach", "--volume", "v1", "--status-addr", srv.URL}, + } { + for _, tmo := range []string{"0s", "-1s"} { + code, out, _ := runChunk(append(cmd, "--timeout", tmo)...) + if code == 0 || !strings.Contains(out, `"code":"bad_request"`) { + t.Fatalf("%s --timeout %s: exit %d stdout %q, want a bad_request refusal", cmd[0], tmo, code, out) + } + } + } + if n := len(s.recorded()); n != 0 { + t.Fatalf("%d requests sent for a non-positive --timeout, want none", n) + } +} + // The detach's --timeout help says a long bound can mean a long guest stop. func TestChunkDetachTimeoutHelpNamesTheGuestStop(t *testing.T) { _, _, errs := runChunk("detach", "-h") diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index d60d7f1b99..215e98eaa0 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -913,6 +913,10 @@ Notes: | `INV-CUT-TIMER-RESTART-001` | A successful cut of any kind restarts the periodic timer, which runs on in-process monotonic time (a restart starts a fresh schedule; wall-clock steps move nothing). | M5 periodic trigger (before Admit) | `core/frontend/durable/provider_chunk.go` `chunkLoop` | `TestWALStoreChunk_ExplicitCutRestartsTheTimer`, `TestWALStoreChunk_ExplicitCutOverlappingTheTimerRestartsIt` (`core/frontend/durable/provider_chunk_sched_test.go`); `TestCutPolicy_TimerRunsOnObservationTime`, `TestCutPolicy_StaggerPreservesExplicitTimerReset` (`core/frontend/durable/cut_policy_test.go`) | — | ACTIVE | | `INV-CUT-TIMER-SKIP-001` | A periodic cut decided from an older last cut is skipped under the capture lock: no automatic cut follows another within the interval. | M5 periodic trigger (before Admit) | `core/storage/chunk_periodic_cut.go` `CutUnlessCutSince`; `core/frontend/durable/provider_chunk.go` `chunkLoop` | `TestChunkPeriodicCut_SkipsAfterANewerCut`, `TestChunkPeriodicCut_SkipsANewerCutWithAnOlderStamp` (`core/storage/chunk_periodic_cut_test.go`); `TestWALStoreChunk_ExplicitCutOverlappingTheTimerRestartsIt` (`core/frontend/durable/provider_chunk_sched_test.go`) | — | ACTIVE | | `INV-CUT-TIMER-SLOT-WAIT-001` | A periodic cut refused because every host cut slot is held is a wait, not a failure: no backoff or minimum spacing; it retries after a random delay under 200 ms that shrinks with lateness, and status reports the wait until any later cut succeeds. Other errors keep the backoff. | M5 periodic trigger (before Admit) | `core/frontend/durable/provider_chunk.go` `cutPolicy.after`, `chunkLoop`; `core/hostlimit/limiter.go` `ErrSlotsHeld` | `TestCutPolicy_HostSlotBusyIsAWaitNotAFailure`, `TestCutPolicy_SuccessDuringSlotWaitDropsTheSlotRetry`, `TestCutWaitSlot_StatusEndsTheWaitAfterALaterCut`, `TestNewSlotDelay_ShrinksWithLateness`, `TestCutPolicy_OneSlotWaitBound` (`core/frontend/durable/cut_policy_test.go`); `TestTimerCutRunsSoonAfterHostSlotFrees`, `TestSlotWaitEndsWithASuccessfulDetachSeal` (`core/frontend/durable/host_slot_wait_test.go`); `TestAdmitClosedDuringPoolAcquisitionIsRevoked` (`core/hostlimit/limiter_test.go`) | — | ACTIVE | +| `INV-CLI-CHUNK-LOOP-001` | Above the per-request bound, sw-block ops chunk snapshot\|cut\|detach repeats the SAME request (same name and request id) only after a retryable or outcome_unknown answer. | client (no state machine): the CLI side of M5 cut requests | `cmd/sw-block/chunk_loop.go` `chunkPostLoop`; `cmd/sw-block/chunk.go` `chunkPostUntil` | `TestChunkSnapshotRepeatsTimedOutRequestsWithTheSameBody`, `TestChunkSnapshotLoopReusesTheGeneratedRequestID`, `TestChunkLoopRepeatsAnOutcomeUnknownNotMarkedRetryable` (`cmd/sw-block`) | — | ACTIVE | +| `INV-CLI-CHUNK-LOOP-002` | Above the per-request bound, sw-block ops chunk snapshot\|cut\|detach stops at the first definite answer (success or non-retryable refusal). | client (no state machine): the CLI side of M5 cut requests | `cmd/sw-block/chunk_loop.go` `chunkPostLoop` | `TestChunkLoopStopsOnANonRetryableRefusal`, `TestChunkDetachOutcomeUnknownSettles` (`cmd/sw-block`) | — | ACTIVE | +| `INV-CLI-CHUNK-LOOP-003` | Above the per-request bound, sw-block ops chunk snapshot\|cut\|detach never starts a request once --timeout has passed and refuses a non-positive --timeout. | client (no state machine): the CLI side of M5 cut requests | `cmd/sw-block/chunk_loop.go` `chunkPostLoop`; `cmd/sw-block/chunk.go` `chunkPostUntil` | `TestChunkLoopEndsAtTheTimeout`, `TestChunkLoopHeldProgressReadSendsNoRequestAfterTheTimeout`, `TestChunkLoopSlowAnswersAreBoundedByTheTimeout`, `TestChunkNonPositiveTimeoutIsRefused` (`cmd/sw-block`) | — | ACTIVE | +| `INV-CLI-CHUNK-LOOP-004` | Above the per-request bound, a sw-block ops chunk snapshot\|cut\|detach request that ended before its own deadline is repeated only after a backoff (no hot loop). | client (no state machine): the CLI side of M5 cut requests | `cmd/sw-block/chunk_loop.go` `chunkPostLoop` | `TestChunkLoopPauseDoublesToItsCap`, `TestChunkLoopEndsAtTheTimeout` (`cmd/sw-block`) | — | ACTIVE | A guest read has a cooperative arrival budget; internal contextless readers keep the owned fill timeout (default 30 s). With five immediate host retries, cold fills slower than roughly 20–24 s can still end in guest EIO despite shared work; retry-delay advertisement remains separate. A changed generation replaces its promise without abandoning the old worker. `AllBlocks` returns an error and no partial image on a failed read; the rebuild sender propagates it before sending blocks.