Files
seaweedfs/seaweed-block/docs/spec/cutwindow/CutWindow.tla
T
Ping QiuandClaude Opus 5.5 a5686e7fa7 Sync seaweed-block v1.1.1 into seaweed-block/ (#13411)
Brings seaweed-block main (v1.1.1 plus the docs and a test fix after it)
into seaweed-block/ as one commit. Only files under seaweed-block/ change,
and the subtree equals seaweed-block main exactly. The module's full
history stays in the seaweed-block repository.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-04 19:04:53 -08:00

106 lines
6.4 KiB
Plaintext

------------------------------ MODULE CutWindow ------------------------------
(***************************************************************************)
(* The cut as a no-progress window (2026-12-02; the V3 *)
(* time contract: no fixed total bound around work that grows). A cut *)
(* uploads U objects, one request at a time, then publishes. Each request *)
(* has a per-call deadline P: a request that does not answer is cancelled *)
(* and retried, never left running. The attempt's window W is renewed by *)
(* each COMPLETED upload; W steps with none fail the attempt (no_progress) *)
(* and the next attempt continues with the uploads already done (progress *)
(* kept). There is no total bound: a long cut that keeps completing *)
(* uploads never fails. The per-call deadline is also the bound the *)
(* resweep window derives from: no request of a cut lands later than P *)
(* after it was sent. *)
(* *)
(* Break = "none", or ONE of: *)
(* "total_cap" a fixed total bound fails even a progressing *)
(* cut (today's defaultChunkCutTimeout) *)
(* "window_not_reset" a completed upload does not renew the window *)
(* "timeout_renews" a cancelled request renews the window, so a *)
(* hung store keeps the cut alive forever *)
(* "no_call_deadline" a request that does not answer stays in *)
(* flight *)
(* "retry_loses_progress" a new attempt starts the uploads over *)
(* *)
(* Bounded by construction: done and ever subsets of 1..U, inflight 0..U, *)
(* age 0..P+1, since 0..W, real 0..W+1, total 0..TCap, attempts 0..MaxAtt. *)
(***************************************************************************)
EXTENDS Integers, FiniteSets
CONSTANTS U, W, P, CapT, TCap, MaxAtt, Break
Ups == 1..U
VARIABLES phase, done, ever, inflight, hung, age, since, real, total, attempts, early, timedOutOnce, failedOnce
vars == <<phase, done, ever, inflight, hung, age, since, real, total, attempts, early, timedOutOnce, failedOnce>>
Min2(a, b) == IF a < b THEN a ELSE b
Init == /\ phase = "uploading" /\ done = {} /\ ever = {} /\ inflight = 0 /\ hung = FALSE /\ age = 0
/\ since = 0 /\ real = 0 /\ total = 0 /\ attempts = 1
/\ early = FALSE /\ timedOutOnce = FALSE /\ failedOnce = FALSE
\* a request for upload u is sent; it may hang (no answer)
Start(u) == /\ phase = "uploading" /\ inflight = 0 /\ u \notin done
/\ inflight' = u /\ age' = 0 /\ hung' \in BOOLEAN
/\ UNCHANGED <<phase, done, ever, since, real, total, attempts, early, timedOutOnce, failedOnce>>
\* the request answers: the upload is done and kept (staged), the window renewed
Complete == /\ phase = "uploading" /\ inflight # 0 /\ ~hung
/\ done' = done \cup {inflight} /\ ever' = ever \cup {inflight} /\ inflight' = 0 /\ age' = 0
/\ since' = (IF Break = "window_not_reset" THEN since ELSE 0)
/\ real' = 0
/\ UNCHANGED <<phase, hung, total, attempts, early, timedOutOnce, failedOnce>>
\* the per-call deadline cancels a request that has not answered; it is retried later
CallTimeout == /\ phase = "uploading" /\ inflight # 0 /\ age >= P /\ Break # "no_call_deadline"
/\ inflight' = 0 /\ age' = 0 /\ hung' = FALSE /\ timedOutOnce' = TRUE
/\ since' = (IF Break = "timeout_renews" THEN 0 ELSE since)
/\ UNCHANGED <<phase, done, ever, real, total, attempts, early, failedOnce>>
\* every upload done: the HEAD write publishes the cut
Publish == /\ phase = "uploading" /\ inflight = 0 /\ done = Ups /\ phase' = "published"
/\ UNCHANGED <<done, ever, inflight, hung, age, since, real, total, attempts, early, timedOutOnce, failedOnce>>
CapDue == Break = "total_cap" /\ total >= CapT
\* time passes; the code answers its deadlines first
Tick == /\ phase = "uploading"
/\ since < W /\ ~CapDue
/\ inflight = 0 \/ age < P \/ Break = "no_call_deadline"
/\ since' = since + 1
/\ real' = Min2(real + 1, W + 1)
/\ total' = Min2(total + 1, TCap)
/\ age' = (IF inflight # 0 THEN Min2(age + 1, P + 1) ELSE age)
/\ UNCHANGED <<phase, done, ever, inflight, hung, attempts, early, timedOutOnce, failedOnce>>
\* W steps with no completed upload (or, in the mutant, the total cap): the attempt fails no_progress
Fail == /\ phase = "uploading" /\ (since >= W \/ CapDue)
/\ phase' = "failed" /\ inflight' = 0 /\ age' = 0 /\ hung' = FALSE /\ failedOnce' = TRUE
/\ early' = (early \/ real < W)
/\ UNCHANGED <<done, ever, since, real, total, attempts, timedOutOnce>>
\* the next attempt continues with the uploads already done
Retry == /\ phase = "failed" /\ attempts < MaxAtt /\ attempts' = attempts + 1
/\ phase' = "uploading" /\ since' = 0 /\ real' = 0
/\ done' = (IF Break = "retry_loses_progress" THEN {} ELSE done)
/\ UNCHANGED <<ever, inflight, hung, age, total, early, timedOutOnce, failedOnce>>
Next == \/ \E u \in Ups : Start(u)
\/ Complete \/ CallTimeout \/ Publish \/ Tick \/ Fail \/ Retry
Spec == Init /\ [][Next]_vars
\* ---- rules ----
\* an attempt fails no_progress only after W steps with no completed upload (never on a total bound)
NoEarlyFail == ~early
\* no attempt stays silent past W steps without a completed upload (a cancelled request is not progress)
NoSilentStall == phase = "uploading" => real <= W
\* no request outlives its per-call deadline: the bound the resweep window derives from
NoLongCall == inflight # 0 => age <= P
\* uploads done are never lost to a retry
ProgressKept == ever \subseteq done
\* ---- witnesses ----
WitSlowNoFail == ~(phase = "published" /\ total >= TCap /\ ~failedOnce) \* a long cut, still progressing: published, no failure
WitTimedOutThenPub == ~(phase = "published" /\ timedOutOnce) \* a hung request cancelled, the cut still published
WitFailRetryPub == ~(phase = "published" /\ failedOnce) \* a no-progress failure, a retry with progress kept, published
=============================================================================