From 970d925fce2463314aa13408a14f92b7857ead4f Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 1 Dec 2026 10:26:01 -0800 Subject: [PATCH] durable: a requeued turn stays at the back until a cut succeeds requeue is set by an admitted attempt that fails and cleared only by a success: a wait, a refusal or a dropped ticket (a reconcile, a pause) leaves it set, so every later ticket of the turn is taken at the host's now. INV-HOST-TICKET-REENTRY-001 states it and names the test. Co-Authored-By: Claude Opus 5.5 --- .../core/frontend/durable/provider_chunk.go | 15 +++++++++++---- seaweed-block/docs/design/invariants.md | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/seaweed-block/core/frontend/durable/provider_chunk.go b/seaweed-block/core/frontend/durable/provider_chunk.go index c7c949dcf9..6bc826195b 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk.go +++ b/seaweed-block/core/frontend/durable/provider_chunk.go @@ -968,9 +968,11 @@ func (p *DurableProvider) chunkLoop(ctx context.Context, volumeID string, layer TakeTicket(dueHostNs int64) (*hostlimit.Ticket, error) }) var ticket *hostlimit.Ticket - // requeue: the last attempt was admitted on its ticket and then failed, - // so its next ticket goes to the back of the queue (the host's now), - // never back to the schedule's due time ahead of the cuts that waited. + // requeue: an attempt of this turn was admitted on its ticket and then + // failed, so every later ticket of the turn goes to the back of the queue + // (the host's now), never back to the schedule's due time ahead of the + // cuts that waited. Only a success ends the turn; a wait, a refusal or a + // dropped ticket leaves it set. requeue := false dropTicket := func(reason string) { if ticket != nil { @@ -1062,7 +1064,12 @@ func (p *DurableProvider) chunkLoop(ctx context.Context, volumeID string, layer if consumed { ticket = nil // admitted: the limiter consumed it, whatever the cut did after } - requeue = consumed && err != nil + switch { + case err == nil: + requeue = false + case consumed: + requeue = true + } switch { case err == nil: dropTicket("") // admitted: the limiter consumed it diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index c26afd075f..d1ee250300 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -1012,7 +1012,7 @@ Notes: | `INV-LOCAL-HEADROOM-001` | blockvolume refuses to create a volume when the durable root's free space is below the volume size plus its WAL, naming both numbers, before it creates the store, WAL or fresh marker, and warns at start when an existing volume's remaining sparse growth plus the WAL exceed the free space. | M1 open/create (durable provider start) | `core/frontend/durable/headroom.go`; `core/frontend/durable/provider.go` `createFresh`, `openExisting` | `TestCreateRefusesWithoutLocalHeadroom`, `TestOpenWarnsWithoutLocalHeadroom` (`core/frontend/durable/headroom_test.go`) | A lab build (tag `swblock_lab_bigvol`, scale rehearsals only) warns instead of refusing (`TestLabBuildCreatesWithoutLocalHeadroom`); CI keeps the tag out of every image and release build (`.github/scripts/lab-tag-check.sh`) | ACTIVE | | `INV-CREATE-MAX-SIZE-001` | blockmaster refuses a new volume above `geometry.MaxNewVolumeBytes` at CreateVolume (InvalidArgument) and at a `--cluster-spec` start, with `ErrVolumeTooLarge` naming the size and the maximum, before any record or store exists. An existing volume keeps opening under `MaxVolumeBytes`. | create admission (CreateVolume, cluster-spec import) | `core/geometry/volume_size.go` `ValidateNewVolumeSize`; `core/lifecycle/store.go` `CreateVolume`; `cmd/blockmaster/cluster_spec.go` `loadClusterSpec`; `core/host/master/services.go` `CreateVolume` (restore geometry) | `TestCreateVolumeRefusesAVolumeAboveTheMaximum` (`core/host/master`), `TestClusterSpecRefusesAVolumeAboveTheMaximum` (`cmd/blockmaster`), `TestValidateNewVolumeSizeAtAndAboveTheMaximum` (`core/geometry`), `TestCreateVolumeRejectsBeyondUint32LBACap` (`core/lifecycle`) | In a lab build (tag `swblock_lab_bigvol`, scale rehearsals only) `MaxNewVolumeBytes` is `MaxVolumeBytes` (`TestLabBuildLiftsTheCreateCap`); a release build keeps 256 GiB (`TestReleaseBuildKeepsTheCreateCap`), and CI keeps the tag out of every image (`.github/scripts/lab-tag-check.sh`, `scripts/refuse-lab-binary.sh`) | ACTIVE | | `INV-HOST-TICKET-ORDER-001` | A waiting timer cut is admitted only when no earlier ticket on the host is live and not stalled; dead tickets are removed, stalled ones (head free for 2 s) skipped. A volume waits at most (V-1) x T_cut,max plus the window's urgent work plus one poll per hand-off. | M7 waiting → admitted (reason: under random retry, 9 of 20 volumes on one host made zero cuts in 720 s) | `core/hostlimit/tickets.go` `TakeTicket`, `headCheck`, `reap`; `core/hostlimit/limiter.go` `pool`, `Admit`; `core/frontend/durable/provider_chunk.go` `chunkLoop` | `TestTicketsAdmitInDueOrder`, `TestDeadEarlierTicketIsRemoved`, `TestStalledEarlierTicketIsSkipped`, `TestNoSkipWhileTheSlotIsHeld`, `TestTicketRemovedBeforeItsLockIsRetaken`, `TestOneStalledTicketCostsOneSkipNotEveryHandoff`, `TestConfigurationLockHeldPastTheBoundIsAWait`, `TestTakeTicketDoesNotRecreateARemovedPool` (`core/hostlimit/tickets_test.go`); `TestCutPolicy_TicketOrderWaitBound` (`core/frontend/durable/cut_policy_test.go`); `TestChunkLoop_TicketKeptForAWaitDroppedOtherwise` (`core/frontend/durable/cut_loop_fence_test.go`) | `HostTickets` OrderedAdmission, BoundedWait, NoLostTicket, SingleHolder | ACTIVE | -| `INV-HOST-TICKET-REENTRY-001` | A timer cut never cuts without a ticket (a failed ticket creation waits for the next poll), and an attempt admitted on its ticket that then fails retries on a fresh ticket at the back of the queue, never at its schedule's earlier due time. | M7 waiting → admitted | `core/frontend/durable/provider_chunk.go` `chunkLoop` | `TestChunkLoop_AConsumedAttemptRetriesAtTheBack`, `TestChunkLoop_NoTicketNoCut` (`core/frontend/durable/cut_loop_ticket_order_test.go`) | SlotShareN (a cut that yields or retries takes a new ticket at the back) | ACTIVE | +| `INV-HOST-TICKET-REENTRY-001` | A timer cut never cuts without a ticket (a failed ticket creation waits for the next poll), and once an attempt of a turn was admitted and failed, every later ticket of that turn is at the back of the queue, never at the schedule's earlier due time. | M7 waiting → admitted | `core/frontend/durable/provider_chunk.go` `chunkLoop` | `TestChunkLoop_AConsumedAttemptRetriesAtTheBack`, `TestChunkLoop_NoTicketNoCut`, `TestChunkLoop_ARequeuedTurnStaysAtTheBackAcrossAWaitAndADrop` (`core/frontend/durable/cut_loop_ticket_order_test.go`) | SlotShareN (a cut that yields or retries takes a new ticket at the back) | ACTIVE | | `INV-HOST-CUT-PACING-HOST-001` | Coordinated cut transfers on one host upload at most the budget in total, plus at most H x PayloadBytes once per change of H (H = held normal and urgent slots); a lone transfer may use the whole budget. Fallback leases are excluded. | M7 admitted (upload pacing) | `core/hostlimit/limiter.go` `WaitUpload`, `heldCodedSlots` | `TestPacingUsesTheBudgetOverHeldSlots` (`core/hostlimit/tickets_test.go`); `TestPacingDebtSurvivesOwnLeaseTurnover` (`core/hostlimit/limiter_test.go`) | — | ACTIVE | | `INV-HOST-SLOT-HOLD-VISIBLE-001` | M7 cannot break a lock held by a live process: a stalled slot holder keeps its slot, a stalled urgent-pending holder keeps Normal admissions refused. A slot holder records its pid and take time in the slot file, and status reports them, so the supervisor can find and remove it. | M7 admitted | `core/hostlimit/limiter.go` `Snapshot`, `slotFilesHeld`, `writeHolder` | `TestSnapshotShowsSlotsHeldSince`, `TestSnapshotHeldSinceFollowsTheHolderAcrossAHandOff`, `TestSnapshotShowsUrgentPendingHeldSince` (`core/hostlimit/tickets_test.go`) | — | ACTIVE | | `INV-HOST-URGENT-NOT-BLOCKED-001` | Urgent work (a seal, a detach, a snapshot, a cut with a minimum LSN) is never refused for a waiter: it waits at most 200 ms for its urgent-pending hold and 50 ms for the configuration lock, then proceeds without the hold (counted) or answers ErrSlotsHeld (retryable). | M7 idle → admitted (Urgent) | `core/hostlimit/pending.go` `holdSharedBounded`, `HoldUrgentPending`; `core/hostlimit/limiter.go` `Admit` | `TestUrgentProceedsPastAStalledProbe`, `TestUrgentWaitsBrieflyForTheConfigurationLock`, `TestConfigurationLockHeldPastTheBoundIsAWait` (`core/hostlimit/tickets_test.go`); `TestRefusedUrgentAdmissionReleasesItsPendingHold` (`core/hostlimit/urgent_refusal_test.go`) | `HostTickets` UrgentNotBlocked, UrgentNotRefused | ACTIVE |