shikibu 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +82 -0
- data/lib/shikibu/activity.rb +84 -48
- data/lib/shikibu/actors.rb +129 -0
- data/lib/shikibu/app.rb +33 -19
- data/lib/shikibu/blobs.rb +42 -0
- data/lib/shikibu/channels.rb +240 -64
- data/lib/shikibu/constants.rb +8 -0
- data/lib/shikibu/context.rb +184 -14
- data/lib/shikibu/errors.rb +56 -0
- data/lib/shikibu/fs.rb +93 -0
- data/lib/shikibu/integrations/sidekiq.rb +9 -13
- data/lib/shikibu/middleware/rack_app.rb +17 -1
- data/lib/shikibu/replay.rb +242 -107
- data/lib/shikibu/storage/actor_ops.rb +331 -0
- data/lib/shikibu/storage/channel_ops.rb +421 -0
- data/lib/shikibu/storage/cursor_ops.rb +37 -0
- data/lib/shikibu/storage/sequel_storage.rb +400 -324
- data/lib/shikibu/storage/sqlite_ops.rb +58 -0
- data/lib/shikibu/supervisor.rb +279 -0
- data/lib/shikibu/tasks.rb +193 -0
- data/lib/shikibu/version.rb +1 -1
- data/lib/shikibu/worker.rb +155 -73
- data/lib/shikibu/workflow.rb +106 -48
- data/lib/shikibu.rb +4 -0
- data/schema/SEMANTICS.md +351 -0
- data/schema/db/migrations/mysql/20261123000000_outbox_claimed_at.sql +5 -0
- data/schema/db/migrations/mysql/20261201000000_actor_registry.sql +24 -0
- data/schema/db/migrations/mysql/20261202000000_actor_capabilities.sql +15 -0
- data/schema/db/migrations/mysql/20261203000000_payload_blobs.sql +11 -0
- data/schema/db/migrations/mysql/20261204000000_actor_fs.sql +13 -0
- data/schema/db/migrations/mysql/20261205000000_actor_tasks.sql +15 -0
- data/schema/db/migrations/mysql/20261206000000_actor_tasks_claimed_at.sql +7 -0
- data/schema/db/migrations/mysql/20261207000000_add_sandboxed.sql +5 -0
- data/schema/db/migrations/mysql/20261208000000_widen_actor_owner_columns.sql +15 -0
- data/schema/db/migrations/postgresql/20261123000000_outbox_claimed_at.sql +5 -0
- data/schema/db/migrations/postgresql/20261201000000_actor_registry.sql +23 -0
- data/schema/db/migrations/postgresql/20261202000000_actor_capabilities.sql +15 -0
- data/schema/db/migrations/postgresql/20261203000000_payload_blobs.sql +11 -0
- data/schema/db/migrations/postgresql/20261204000000_actor_fs.sql +13 -0
- data/schema/db/migrations/postgresql/20261205000000_actor_tasks.sql +15 -0
- data/schema/db/migrations/postgresql/20261206000000_actor_tasks_claimed_at.sql +7 -0
- data/schema/db/migrations/postgresql/20261207000000_add_sandboxed.sql +5 -0
- data/schema/db/migrations/postgresql/20261208000000_widen_actor_owner_columns.sql +7 -0
- data/schema/db/migrations/sqlite/20261123000000_outbox_claimed_at.sql +5 -0
- data/schema/db/migrations/sqlite/20261201000000_actor_registry.sql +23 -0
- data/schema/db/migrations/sqlite/20261202000000_actor_capabilities.sql +15 -0
- data/schema/db/migrations/sqlite/20261203000000_payload_blobs.sql +11 -0
- data/schema/db/migrations/sqlite/20261204000000_actor_fs.sql +13 -0
- data/schema/db/migrations/sqlite/20261205000000_actor_tasks.sql +15 -0
- data/schema/db/migrations/sqlite/20261206000000_actor_tasks_claimed_at.sql +7 -0
- data/schema/db/migrations/sqlite/20261207000000_add_sandboxed.sql +5 -0
- data/schema/db/migrations/sqlite/20261208000000_widen_actor_owner_columns.sql +7 -0
- data/schema/docs/column-values.md +10 -0
- data/schema/spec/ActorFS.tla +117 -0
- data/schema/spec/ActorFS_lww_monotonic.cfg +7 -0
- data/schema/spec/ActorFS_new.cfg +8 -0
- data/schema/spec/ActorFS_old.cfg +7 -0
- data/schema/spec/CompetingMessageClaim.tla +127 -0
- data/schema/spec/CompetingMessageClaimSplit.tla +132 -0
- data/schema/spec/CompetingMessageClaimSplit_atomic_lost.cfg +7 -0
- data/schema/spec/CompetingMessageClaimSplit_atomic_once.cfg +7 -0
- data/schema/spec/CompetingMessageClaimSplit_fixed.cfg +7 -0
- data/schema/spec/CompetingMessageClaimSplit_split_lost.cfg +7 -0
- data/schema/spec/CompetingMessageClaimSplit_split_once.cfg +7 -0
- data/schema/spec/CompetingMessageClaimSplit_waitonly_lost.cfg +7 -0
- data/schema/spec/CompetingMessageClaimSplit_waitonly_once.cfg +7 -0
- data/schema/spec/CompetingMessageClaim_new.cfg +10 -0
- data/schema/spec/CompetingMessageClaim_old.cfg +11 -0
- data/schema/spec/EpochFencing.tla +87 -0
- data/schema/spec/EpochFencingRuns.tla +107 -0
- data/schema/spec/EpochFencingRuns_epoch.cfg +6 -0
- data/schema/spec/EpochFencingRuns_none.cfg +6 -0
- data/schema/spec/EpochFencingRuns_witness.cfg +6 -0
- data/schema/spec/EpochFencingRuns_worker.cfg +6 -0
- data/schema/spec/EpochFencingRuns_worker1.cfg +6 -0
- data/schema/spec/EpochFencing_new.cfg +8 -0
- data/schema/spec/EpochFencing_old.cfg +9 -0
- data/schema/spec/InstanceClaim.tla +196 -0
- data/schema/spec/InstanceClaimVerdict.tla +116 -0
- data/schema/spec/InstanceClaimVerdict_changedrows.cfg +6 -0
- data/schema/spec/InstanceClaimVerdict_changedrows_live.cfg +6 -0
- data/schema/spec/InstanceClaimVerdict_foundrows.cfg +6 -0
- data/schema/spec/InstanceClaimVerdict_foundrows_live.cfg +6 -0
- data/schema/spec/InstanceClaim_atomic_unfenced.cfg +9 -0
- data/schema/spec/InstanceClaim_live.cfg +9 -0
- data/schema/spec/InstanceClaim_new.cfg +9 -0
- data/schema/spec/InstanceClaim_old.cfg +11 -0
- data/schema/spec/InstanceClaim_racy_fenced.cfg +9 -0
- data/schema/spec/README.md +97 -0
- data/schema/spec/SupervisorRestart.tla +108 -0
- data/schema/spec/SupervisorRestartCAS.tla +84 -0
- data/schema/spec/SupervisorRestartCAS_nonsticky.cfg +6 -0
- data/schema/spec/SupervisorRestartCAS_snapshot.cfg +6 -0
- data/schema/spec/SupervisorRestartCAS_sticky.cfg +6 -0
- data/schema/spec/SupervisorRestart_racy.cfg +7 -0
- data/schema/spec/SupervisorRestart_strict.cfg +7 -0
- data/schema/spec/TaskClaim.tla +92 -0
- data/schema/spec/TaskClaimReadBack.tla +84 -0
- data/schema/spec/TaskClaimReadBack_byid.cfg +6 -0
- data/schema/spec/TaskClaimReadBack_order.cfg +6 -0
- data/schema/spec/TaskClaim_new.cfg +8 -0
- data/schema/spec/TaskClaim_old.cfg +9 -0
- data/schema/spec/TaskReclaim.tla +110 -0
- data/schema/spec/TaskReclaimAttempts.tla +73 -0
- data/schema/spec/TaskReclaimAttempts_attempt.cfg +6 -0
- data/schema/spec/TaskReclaimAttempts_claimant.cfg +6 -0
- data/schema/spec/TaskReclaim_new.cfg +8 -0
- data/schema/spec/TaskReclaim_old.cfg +8 -0
- data/schema/spec/WaitRegistration.tla +170 -0
- data/schema/spec/WaitRegistrationSub.tla +133 -0
- data/schema/spec/WaitRegistrationSub_fixed.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_fixed_guarded.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_guardonly_reg.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_guardonly_res.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_head_reg.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_head_res.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_noclear_reg.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_noclear_res.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_unfencedreg_reg.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_unfencedreg_res.cfg +6 -0
- data/schema/spec/WaitRegistration_new.cfg +10 -0
- data/schema/spec/WaitRegistration_old.cfg +11 -0
- data/schema/spec/WaitRegistration_residual.cfg +11 -0
- data/schema/spec/WaitRegistration_sweep.cfg +11 -0
- data/schema/spec/actorfs_check_test.go +165 -0
- data/schema/spec/claim_check_test.go +387 -0
- data/schema/spec/competing_claim_test.go +194 -0
- data/schema/spec/epoch_check_test.go +128 -0
- data/schema/spec/go.mod +3 -0
- data/schema/spec/supervisorrestart_check_test.go +131 -0
- data/schema/spec/taskclaim_check_test.go +135 -0
- data/schema/spec/taskreclaim_check_test.go +125 -0
- data/schema/spec/tlc-check.sh +45 -0
- data/schema/spec/tlc-matrix.txt +68 -0
- data/schema/spec/wait_check_test.go +256 -0
- metadata +121 -2
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
------------------------- MODULE WaitRegistration -------------------------
|
|
2
|
+
\* Model of romancy's channel-receive suspend protocol: the "register wait +
|
|
3
|
+
\* release lock" step in Receive must not miss a message published
|
|
4
|
+
\* concurrently (a missed wakeup leaves the instance waiting forever on a
|
|
5
|
+
\* message that already arrived).
|
|
6
|
+
\*
|
|
7
|
+
\* One receiver R suspends on a channel; one publisher P commits a message
|
|
8
|
+
\* and then scans waiting subscribers to deliver eagerly. Both designs live
|
|
9
|
+
\* in one model, selected by constants:
|
|
10
|
+
\*
|
|
11
|
+
\* AtomicReg = FALSE the pre-fix design:
|
|
12
|
+
\* Receive checked pending messages, then a separate step registered
|
|
13
|
+
\* the wait (and the storage method was itself three autocommit
|
|
14
|
+
\* statements). A publish committed between the check and the
|
|
15
|
+
\* registration sees no waiter and no pending check ever runs again:
|
|
16
|
+
\* the message sits in channel_messages while R waits forever.
|
|
17
|
+
\*
|
|
18
|
+
\* AtomicReg = TRUE the current design:
|
|
19
|
+
\* RegisterChannelReceiveAndReleaseLock is a single transaction that
|
|
20
|
+
\* re-checks pending inside it. A message visible at registration
|
|
21
|
+
\* aborts the wait (R stays running and drains it on resumption).
|
|
22
|
+
\*
|
|
23
|
+
\* ScanCanMiss = TRUE models the residual the transaction cannot cover:
|
|
24
|
+
\* under read-committed isolation a publisher's waiter scan may run
|
|
25
|
+
\* before R's registration commits, so eager delivery can miss even an
|
|
26
|
+
\* atomic registration.
|
|
27
|
+
\*
|
|
28
|
+
\* Sweep = TRUE models RequeueChannelWaitsWithPending, the periodic
|
|
29
|
+
\* backstop that flips waiting instances with pending messages back to
|
|
30
|
+
\* running. It turns any residual miss into bounded-latency healing.
|
|
31
|
+
\*
|
|
32
|
+
\* Check with TLC (see spec/*.cfg):
|
|
33
|
+
\* java -jar tla2tools.jar -deadlock -config WaitRegistration_old.cfg WaitRegistration.tla
|
|
34
|
+
\* -> verified: invariant violation, counterexample where the publish lands
|
|
35
|
+
\* in the check/register gap and R is stranded waiting on a committed
|
|
36
|
+
\* message (missed wakeup in the pre-fix design)
|
|
37
|
+
\* java -jar tla2tools.jar -deadlock -config WaitRegistration_new.cfg WaitRegistration.tla
|
|
38
|
+
\* -> verified: no errors; the atomic recheck closes the gap when the
|
|
39
|
+
\* publisher's scan is reliable
|
|
40
|
+
\* java -jar tla2tools.jar -deadlock -config WaitRegistration_residual.cfg WaitRegistration.tla
|
|
41
|
+
\* -> verified: invariant violation, the honest residual -- under
|
|
42
|
+
\* read-committed isolation a waiter scan can still miss an uncommitted
|
|
43
|
+
\* wait, so atomic registration alone is not sufficient
|
|
44
|
+
\* java -jar tla2tools.jar -deadlock -config WaitRegistration_sweep.cfg WaitRegistration.tla
|
|
45
|
+
\* -> verified: with the periodic requeue sweep the message is still
|
|
46
|
+
\* delivered (liveness under a fair sweep)
|
|
47
|
+
\* The same state machine is model-checked from Go in wait_check_test.go
|
|
48
|
+
\* so `go test ./spec` verifies the design without a Java toolchain.
|
|
49
|
+
|
|
50
|
+
EXTENDS Naturals
|
|
51
|
+
|
|
52
|
+
CONSTANTS AtomicReg, \* BOOLEAN: pending recheck inside the wait registration?
|
|
53
|
+
ScanCanMiss, \* BOOLEAN: may the publisher's waiter scan miss a wait?
|
|
54
|
+
Sweep \* BOOLEAN: periodic requeue of waiting+pending?
|
|
55
|
+
|
|
56
|
+
VARIABLES pending, \* a committed channel_message counts as undelivered for R
|
|
57
|
+
waiting, \* R's wait registration is visible to publishers
|
|
58
|
+
received, \* R got the message (0/1)
|
|
59
|
+
rpc, \* R's pc: "checking" -> "suspending" -> "done"
|
|
60
|
+
ppc \* P's pc: "publishing" -> "scanned" -> "done"
|
|
61
|
+
|
|
62
|
+
vars == <<pending, waiting, received, rpc, ppc>>
|
|
63
|
+
|
|
64
|
+
Init ==
|
|
65
|
+
/\ pending = 0
|
|
66
|
+
/\ waiting = 0
|
|
67
|
+
/\ received = 0
|
|
68
|
+
/\ rpc = "checking"
|
|
69
|
+
/\ ppc = "publishing"
|
|
70
|
+
|
|
71
|
+
\* ---- receiver --------------------------------------------------------
|
|
72
|
+
|
|
73
|
+
\* Old design step 1: the pending check in Receive. No message -> proceed to
|
|
74
|
+
\* the separate suspend step; a message -> consume it and finish.
|
|
75
|
+
R_CheckPending ==
|
|
76
|
+
/\ ~AtomicReg
|
|
77
|
+
/\ rpc = "checking"
|
|
78
|
+
/\ IF pending = 1
|
|
79
|
+
THEN /\ pending' = 0
|
|
80
|
+
/\ received' = 1
|
|
81
|
+
/\ rpc' = "done"
|
|
82
|
+
ELSE /\ rpc' = "suspending"
|
|
83
|
+
/\ UNCHANGED <<pending, received>>
|
|
84
|
+
/\ UNCHANGED <<waiting, ppc>>
|
|
85
|
+
|
|
86
|
+
\* Old design step 2: register the wait and release the lock -- far too late
|
|
87
|
+
\* to see a message published since the check.
|
|
88
|
+
R_RegisterWait ==
|
|
89
|
+
/\ ~AtomicReg
|
|
90
|
+
/\ rpc = "suspending"
|
|
91
|
+
/\ waiting' = 1
|
|
92
|
+
/\ rpc' = "done"
|
|
93
|
+
/\ UNCHANGED <<pending, received, ppc>>
|
|
94
|
+
|
|
95
|
+
\* New design: the registration transaction sees a message committed any time
|
|
96
|
+
\* before its own commit and refuses to wait on it.
|
|
97
|
+
R_RegisterAtomic ==
|
|
98
|
+
/\ AtomicReg
|
|
99
|
+
/\ rpc = "checking"
|
|
100
|
+
/\ IF pending = 1
|
|
101
|
+
THEN /\ pending' = 0
|
|
102
|
+
/\ received' = 1
|
|
103
|
+
/\ UNCHANGED <<waiting>>
|
|
104
|
+
ELSE /\ waiting' = 1
|
|
105
|
+
/\ UNCHANGED <<pending, received>>
|
|
106
|
+
/\ rpc' = "done"
|
|
107
|
+
/\ UNCHANGED <<ppc>>
|
|
108
|
+
|
|
109
|
+
\* ---- publisher --------------------------------------------------------
|
|
110
|
+
|
|
111
|
+
\* Commit the message row.
|
|
112
|
+
P_Insert ==
|
|
113
|
+
/\ ppc = "publishing"
|
|
114
|
+
/\ pending' = 1
|
|
115
|
+
/\ ppc' = "scanned"
|
|
116
|
+
/\ UNCHANGED <<waiting, received, rpc>>
|
|
117
|
+
|
|
118
|
+
\* Scan waiters and deliver to R if its wait is visible.
|
|
119
|
+
P_Deliver ==
|
|
120
|
+
/\ ppc = "scanned"
|
|
121
|
+
/\ waiting = 1
|
|
122
|
+
/\ pending' = 0
|
|
123
|
+
/\ waiting' = 0
|
|
124
|
+
/\ received' = 1
|
|
125
|
+
/\ ppc' = "done"
|
|
126
|
+
/\ UNCHANGED <<rpc>>
|
|
127
|
+
|
|
128
|
+
\* The scan finds no waiter -- either R genuinely is not waiting, or
|
|
129
|
+
\* (ScanCanMiss) its registration was still uncommitted when the scan ran.
|
|
130
|
+
P_ScanMiss ==
|
|
131
|
+
/\ ppc = "scanned"
|
|
132
|
+
/\ waiting = 0 \/ ScanCanMiss
|
|
133
|
+
/\ ppc' = "done"
|
|
134
|
+
/\ UNCHANGED <<pending, waiting, received, rpc>>
|
|
135
|
+
|
|
136
|
+
\* ---- environment ------------------------------------------------------
|
|
137
|
+
|
|
138
|
+
\* The periodic backstop: a waiting instance with a pending message is
|
|
139
|
+
\* flipped to running and drains it on resumption.
|
|
140
|
+
S_Requeue ==
|
|
141
|
+
/\ Sweep
|
|
142
|
+
/\ waiting = 1
|
|
143
|
+
/\ pending = 1
|
|
144
|
+
/\ waiting' = 0
|
|
145
|
+
/\ pending' = 0
|
|
146
|
+
/\ received' = 1
|
|
147
|
+
/\ UNCHANGED <<rpc, ppc>>
|
|
148
|
+
|
|
149
|
+
Next ==
|
|
150
|
+
\/ R_CheckPending \/ R_RegisterWait \/ R_RegisterAtomic
|
|
151
|
+
\/ P_Insert \/ P_Deliver \/ P_ScanMiss
|
|
152
|
+
\/ S_Requeue
|
|
153
|
+
|
|
154
|
+
Spec == Init /\ [][Next]_vars
|
|
155
|
+
|
|
156
|
+
\* ---- properties ------------------------------------------------------
|
|
157
|
+
|
|
158
|
+
\* SAFETY: no reachable state may be a terminal missed wakeup -- R done while
|
|
159
|
+
\* registered-waiting on a committed message, P done, and no sweep to heal.
|
|
160
|
+
NoMissedWakeup ==
|
|
161
|
+
~(waiting = 1 /\ pending = 1 /\ rpc = "done" /\ ppc = "done" /\ ~Sweep)
|
|
162
|
+
|
|
163
|
+
\* LIVENESS: a committed message is eventually received. WF on the whole
|
|
164
|
+
\* next relation rules out permanent stuttering while any action is
|
|
165
|
+
\* enabled; under ScanCanMiss delivery of a stranded wait relies on the
|
|
166
|
+
\* sweep being fair (covered by the same condition).
|
|
167
|
+
FairSpec == Spec /\ WF_vars(Next)
|
|
168
|
+
PendingLeadsToReceived == (pending = 1) ~> (received = 1)
|
|
169
|
+
|
|
170
|
+
==========================================================================
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
---- MODULE WaitRegistrationSub ----
|
|
2
|
+
EXTENDS Naturals
|
|
3
|
+
|
|
4
|
+
(***************************************************************************)
|
|
5
|
+
(* Review extension of WaitRegistration.tla. *)
|
|
6
|
+
(* *)
|
|
7
|
+
(* WaitRegistration.tla has one variable `waiting` that stands for BOTH *)
|
|
8
|
+
(* the instance status and the subscription's wait registration *)
|
|
9
|
+
(* (channel_subscriptions.activity_id / timeout_at), and its S_Requeue *)
|
|
10
|
+
(* clears it and delivers the message in one step. The implementations *)
|
|
11
|
+
(* keep the two apart, and the requeue sweep only flips the status. Here *)
|
|
12
|
+
(* they are separate variables, the sweep only flips status unless *)
|
|
13
|
+
(* ClearOnRequeue, there is a receive-timeout action, and an old run of *)
|
|
14
|
+
(* R that lost its lease may still perform its registration. *)
|
|
15
|
+
(* *)
|
|
16
|
+
(* FencedReg : registration writes are WHERE locked_by = <run> *)
|
|
17
|
+
(* (bug 3: the subscription UPDATE was not) *)
|
|
18
|
+
(* ClearOnRequeue : the sweep clears activity_id/timeout_at with the *)
|
|
19
|
+
(* status flip (bug 4: it did not) *)
|
|
20
|
+
(* GuardedResume : timeout / delivery flips only waiting -> running *)
|
|
21
|
+
(* (bug 6: unguarded UPDATE ... SET status='running') *)
|
|
22
|
+
(***************************************************************************)
|
|
23
|
+
|
|
24
|
+
CONSTANTS FencedReg, ClearOnRequeue, GuardedResume
|
|
25
|
+
|
|
26
|
+
VARIABLES status, \* "running" | "waiting" | "completed"
|
|
27
|
+
sub, \* "none" | "armed" (activity_id/timeout_at set)
|
|
28
|
+
pending, \* committed undelivered message (0/1)
|
|
29
|
+
rpc, \* live run: "checking" | "suspended" | "done"
|
|
30
|
+
ppc, \* publisher: "publishing" | "scanned" | "done"
|
|
31
|
+
staleRun, \* an old run of R that lost its lease: "pending" | "gone"
|
|
32
|
+
resurrected \* a completed instance was flipped back to running
|
|
33
|
+
|
|
34
|
+
vars == <<status, sub, pending, rpc, ppc, staleRun, resurrected>>
|
|
35
|
+
|
|
36
|
+
Init ==
|
|
37
|
+
/\ status = "running"
|
|
38
|
+
/\ sub = "none"
|
|
39
|
+
/\ pending = 0
|
|
40
|
+
/\ rpc = "checking"
|
|
41
|
+
/\ ppc = "publishing"
|
|
42
|
+
/\ staleRun = "pending"
|
|
43
|
+
/\ resurrected = FALSE
|
|
44
|
+
|
|
45
|
+
\* Live run: atomic registration with in-transaction pending re-check.
|
|
46
|
+
R_Register ==
|
|
47
|
+
/\ rpc = "checking"
|
|
48
|
+
/\ status = "running"
|
|
49
|
+
/\ IF pending = 1
|
|
50
|
+
THEN /\ pending' = 0 /\ rpc' = "done" /\ UNCHANGED <<sub, status>>
|
|
51
|
+
ELSE /\ sub' = "armed" /\ status' = "waiting" /\ rpc' = "suspended"
|
|
52
|
+
/\ UNCHANGED pending
|
|
53
|
+
/\ UNCHANGED <<ppc, staleRun, resurrected>>
|
|
54
|
+
|
|
55
|
+
\* Old run (lease lost) runs the same registration. Fenced: rejected.
|
|
56
|
+
\* Unfenced (bug 3): the subscription UPDATE lands, the fenced status
|
|
57
|
+
\* UPDATE matches no row, and nothing checks RowsAffected.
|
|
58
|
+
Stale_Register ==
|
|
59
|
+
/\ staleRun = "pending"
|
|
60
|
+
/\ staleRun' = "gone"
|
|
61
|
+
/\ IF FencedReg THEN UNCHANGED sub ELSE sub' = "armed"
|
|
62
|
+
/\ UNCHANGED <<status, pending, rpc, ppc, resurrected>>
|
|
63
|
+
|
|
64
|
+
\* Resumed live run: Receive drains the pending message, or the delivered
|
|
65
|
+
\* or timed-out slot; then the workflow completes.
|
|
66
|
+
R_Resume ==
|
|
67
|
+
/\ rpc = "suspended"
|
|
68
|
+
/\ status = "running"
|
|
69
|
+
/\ pending' = 0
|
|
70
|
+
/\ rpc' = "done"
|
|
71
|
+
/\ UNCHANGED <<status, sub, ppc, staleRun, resurrected>>
|
|
72
|
+
|
|
73
|
+
R_Complete ==
|
|
74
|
+
/\ rpc = "done"
|
|
75
|
+
/\ status = "running"
|
|
76
|
+
/\ status' = "completed"
|
|
77
|
+
/\ UNCHANGED <<sub, pending, rpc, ppc, staleRun, resurrected>>
|
|
78
|
+
|
|
79
|
+
P_Insert ==
|
|
80
|
+
/\ ppc = "publishing"
|
|
81
|
+
/\ pending' = 1
|
|
82
|
+
/\ ppc' = "scanned"
|
|
83
|
+
/\ UNCHANGED <<status, sub, rpc, staleRun, resurrected>>
|
|
84
|
+
|
|
85
|
+
\* Eager delivery to a visible wait registration.
|
|
86
|
+
P_Deliver ==
|
|
87
|
+
/\ ppc = "scanned"
|
|
88
|
+
/\ sub = "armed"
|
|
89
|
+
/\ GuardedResume => status = "waiting"
|
|
90
|
+
/\ pending' = 0
|
|
91
|
+
/\ sub' = "none"
|
|
92
|
+
/\ status' = IF GuardedResume /\ status /= "waiting" THEN status ELSE "running"
|
|
93
|
+
/\ resurrected' = (resurrected \/ status = "completed")
|
|
94
|
+
/\ ppc' = "done"
|
|
95
|
+
/\ UNCHANGED <<rpc, staleRun>>
|
|
96
|
+
|
|
97
|
+
\* The scan misses (no waiter, or a not-yet-committed registration).
|
|
98
|
+
P_ScanMiss ==
|
|
99
|
+
/\ ppc = "scanned"
|
|
100
|
+
/\ ppc' = "done"
|
|
101
|
+
/\ UNCHANGED <<status, sub, pending, rpc, staleRun, resurrected>>
|
|
102
|
+
|
|
103
|
+
\* RequeueChannelWaitsWithPending as implemented.
|
|
104
|
+
S_Requeue ==
|
|
105
|
+
/\ status = "waiting"
|
|
106
|
+
/\ pending = 1
|
|
107
|
+
/\ sub = "armed"
|
|
108
|
+
/\ status' = "running"
|
|
109
|
+
/\ IF ClearOnRequeue THEN sub' = "none" ELSE UNCHANGED sub
|
|
110
|
+
/\ UNCHANGED <<pending, rpc, ppc, staleRun, resurrected>>
|
|
111
|
+
|
|
112
|
+
\* The receive deadline passes for an armed registration.
|
|
113
|
+
T_Timeout ==
|
|
114
|
+
/\ sub = "armed"
|
|
115
|
+
/\ GuardedResume => status = "waiting"
|
|
116
|
+
/\ sub' = "none"
|
|
117
|
+
/\ status' = IF GuardedResume /\ status /= "waiting" THEN status ELSE "running"
|
|
118
|
+
/\ resurrected' = (resurrected \/ status = "completed")
|
|
119
|
+
/\ UNCHANGED <<pending, rpc, ppc, staleRun>>
|
|
120
|
+
|
|
121
|
+
Next ==
|
|
122
|
+
\/ R_Register \/ Stale_Register \/ R_Resume \/ R_Complete
|
|
123
|
+
\/ P_Insert \/ P_Deliver \/ P_ScanMiss
|
|
124
|
+
\/ S_Requeue \/ T_Timeout
|
|
125
|
+
|
|
126
|
+
Spec == Init /\ [][Next]_vars
|
|
127
|
+
|
|
128
|
+
\* A wait registration exists only while the instance is waiting.
|
|
129
|
+
RegConsistent == (sub = "armed") => (status = "waiting")
|
|
130
|
+
|
|
131
|
+
\* completed is terminal.
|
|
132
|
+
NoResurrection == ~resurrected
|
|
133
|
+
====
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
\* Current design: the wait registration transaction re-checks pending
|
|
2
|
+
\* inside itself, so the check/register gap is closed. With reliable
|
|
3
|
+
\* eager delivery (ScanCanMiss = FALSE) no sweep is needed.
|
|
4
|
+
\* Expected TLC result: no errors.
|
|
5
|
+
CONSTANTS
|
|
6
|
+
AtomicReg = TRUE
|
|
7
|
+
ScanCanMiss = FALSE
|
|
8
|
+
Sweep = FALSE
|
|
9
|
+
SPECIFICATION Spec
|
|
10
|
+
INVARIANTS NoMissedWakeup
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
\* Pre-fix design: pending check and wait registration are separate steps
|
|
2
|
+
\* (and the registration itself was three autocommit statements).
|
|
3
|
+
\* Expected TLC result: INVARIANT violation -- a publish lands in the
|
|
4
|
+
\* check/register gap; the scan sees no waiter and R is stranded waiting on
|
|
5
|
+
\* a committed message (missed wakeup).
|
|
6
|
+
CONSTANTS
|
|
7
|
+
AtomicReg = FALSE
|
|
8
|
+
ScanCanMiss = FALSE
|
|
9
|
+
Sweep = FALSE
|
|
10
|
+
SPECIFICATION Spec
|
|
11
|
+
INVARIANTS NoMissedWakeup
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
\* Honest residual: the atomic registration cannot prevent a publisher's
|
|
2
|
+
\* waiter scan from running before the registration commits under
|
|
3
|
+
\* read-committed isolation (ScanCanMiss = TRUE). Without a backstop the
|
|
4
|
+
\* stranded state is still reachable, just far narrower.
|
|
5
|
+
\* Expected TLC result: INVARIANT violation -- this is why the sweep exists.
|
|
6
|
+
CONSTANTS
|
|
7
|
+
AtomicReg = TRUE
|
|
8
|
+
ScanCanMiss = TRUE
|
|
9
|
+
Sweep = FALSE
|
|
10
|
+
SPECIFICATION Spec
|
|
11
|
+
INVARIANTS NoMissedWakeup
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
\* Full deployment: atomic registration plus the periodic
|
|
2
|
+
\* RequeueChannelWaitsWithPending sweep. Even when the publisher's scan
|
|
3
|
+
\* misses an uncommitted wait, a fair sweep still delivers the message.
|
|
4
|
+
\* Expected TLC result: liveness holds (the transient stranded state is
|
|
5
|
+
\* healed; NoMissedWakeup does not apply while a sweep exists).
|
|
6
|
+
CONSTANTS
|
|
7
|
+
AtomicReg = TRUE
|
|
8
|
+
ScanCanMiss = TRUE
|
|
9
|
+
Sweep = TRUE
|
|
10
|
+
SPECIFICATION FairSpec
|
|
11
|
+
PROPERTY PendingLeadsToReceived
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
package spec
|
|
2
|
+
|
|
3
|
+
// Exhaustive model checker for ActorFS.tla (2 writers, MaxVersion=2).
|
|
4
|
+
// Establishes the same results TLC would report:
|
|
5
|
+
//
|
|
6
|
+
// java -jar tla2tools.jar -deadlock -config ActorFS_new.cfg ActorFS.tla
|
|
7
|
+
//
|
|
8
|
+
// new (CAS=TRUE): NoLostUpdate holds over all reachable states.
|
|
9
|
+
// old (CAS=FALSE): a state with two winners at the same base version is
|
|
10
|
+
// reachable — the lost-update anomaly CAS exists to prevent.
|
|
11
|
+
|
|
12
|
+
import (
|
|
13
|
+
"fmt"
|
|
14
|
+
"testing"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
type fsState struct {
|
|
18
|
+
exists bool
|
|
19
|
+
version int // 0 when absent; 1..MaxVersion
|
|
20
|
+
storedBy string // "", w1, w2
|
|
21
|
+
readVer [2]int
|
|
22
|
+
hasRead [2]bool
|
|
23
|
+
outcome [2]string // "none", "ok", "conflict"
|
|
24
|
+
wins [3]int // bitmask of winners per base version (0..2)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
func (s fsState) key() string {
|
|
28
|
+
return fmt.Sprintf("%v|%d|%s|%d%d|%v%v|%s%s|%d%d%d",
|
|
29
|
+
s.exists, s.version, s.storedBy, s.readVer[0], s.readVer[1],
|
|
30
|
+
s.hasRead[0], s.hasRead[1], s.outcome[0], s.outcome[1],
|
|
31
|
+
s.wins[0], s.wins[1], s.wins[2])
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var fsWriters = [2]string{"w1", "w2"}
|
|
35
|
+
const fsMaxVersion = 2
|
|
36
|
+
|
|
37
|
+
func fsSuccessors(s fsState, cas bool) []fsState {
|
|
38
|
+
var out []fsState
|
|
39
|
+
add := func(n fsState) { out = append(out, n) }
|
|
40
|
+
for i, w := range fsWriters {
|
|
41
|
+
// WRead: observe current version.
|
|
42
|
+
n := s
|
|
43
|
+
n.readVer[i] = s.version
|
|
44
|
+
n.hasRead[i] = true
|
|
45
|
+
add(n)
|
|
46
|
+
|
|
47
|
+
// WCreate: expected 0 — CAS succeeds only when absent; LWW always.
|
|
48
|
+
n = s
|
|
49
|
+
if !cas || !s.exists {
|
|
50
|
+
n.outcome[i] = "ok"
|
|
51
|
+
} else {
|
|
52
|
+
n.outcome[i] = "conflict"
|
|
53
|
+
}
|
|
54
|
+
if n.outcome[i] == "ok" {
|
|
55
|
+
n.wins[0] |= 1 << i
|
|
56
|
+
n.exists = true
|
|
57
|
+
n.version = 1
|
|
58
|
+
n.storedBy = w
|
|
59
|
+
}
|
|
60
|
+
add(n)
|
|
61
|
+
|
|
62
|
+
// WUpdate: expected = observed — CAS requires match; LWW always wins.
|
|
63
|
+
n = s
|
|
64
|
+
if s.hasRead[i] && s.readVer[i] > 0 && s.outcome[i] != "ok" && s.version < fsMaxVersion {
|
|
65
|
+
base := s.readVer[i]
|
|
66
|
+
if !cas || s.version == base {
|
|
67
|
+
n.outcome[i] = "ok"
|
|
68
|
+
n.wins[base] |= 1 << i
|
|
69
|
+
n.version = s.version + 1
|
|
70
|
+
n.storedBy = w
|
|
71
|
+
n.exists = true
|
|
72
|
+
} else {
|
|
73
|
+
n.outcome[i] = "conflict"
|
|
74
|
+
}
|
|
75
|
+
add(n)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// WRetry: re-arm after conflict.
|
|
79
|
+
if s.outcome[i] == "conflict" {
|
|
80
|
+
n = s
|
|
81
|
+
n.outcome[i] = "none"
|
|
82
|
+
add(n)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return out
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
func fsInit() fsState {
|
|
89
|
+
return fsState{outcome: [2]string{"none", "none"}}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// fsReach explores all reachable states; visit returns false to stop early.
|
|
93
|
+
func fsReach(cas bool, visit func(fsState) bool) (visited int) {
|
|
94
|
+
seen := map[string]bool{fsInit().key(): true}
|
|
95
|
+
queue := []fsState{fsInit()}
|
|
96
|
+
for len(queue) > 0 {
|
|
97
|
+
s := queue[0]
|
|
98
|
+
queue = queue[1:]
|
|
99
|
+
visited++
|
|
100
|
+
if !visit(s) {
|
|
101
|
+
return visited
|
|
102
|
+
}
|
|
103
|
+
for _, n := range fsSuccessors(s, cas) {
|
|
104
|
+
k := n.key()
|
|
105
|
+
if !seen[k] {
|
|
106
|
+
seen[k] = true
|
|
107
|
+
queue = append(queue, n)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return visited
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
func fsNoLostUpdate(s fsState) bool {
|
|
115
|
+
for v := 0; v <= fsMaxVersion; v++ {
|
|
116
|
+
// at most one winner per base version
|
|
117
|
+
if s.wins[v] != 0 && s.wins[v] != 1 && s.wins[v] != 2 {
|
|
118
|
+
return false
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return true
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
func TestFS_CAS_NoLostUpdate(t *testing.T) {
|
|
125
|
+
var bad *fsState
|
|
126
|
+
n := fsReach(true, func(s fsState) bool {
|
|
127
|
+
if !fsNoLostUpdate(s) {
|
|
128
|
+
b := s
|
|
129
|
+
bad = &b
|
|
130
|
+
return false
|
|
131
|
+
}
|
|
132
|
+
return true
|
|
133
|
+
})
|
|
134
|
+
if bad != nil {
|
|
135
|
+
t.Fatalf("NoLostUpdate violated at state %+v", *bad)
|
|
136
|
+
}
|
|
137
|
+
t.Logf("CAS protocol: %d states explored, no violation", n)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
func TestFS_LWW_LostUpdateReachable(t *testing.T) {
|
|
141
|
+
var bad *fsState
|
|
142
|
+
n := fsReach(false, func(s fsState) bool {
|
|
143
|
+
if !fsNoLostUpdate(s) {
|
|
144
|
+
b := s
|
|
145
|
+
bad = &b
|
|
146
|
+
return false
|
|
147
|
+
}
|
|
148
|
+
return true
|
|
149
|
+
})
|
|
150
|
+
if bad == nil {
|
|
151
|
+
t.Fatal("expected a lost-update state under LWW")
|
|
152
|
+
}
|
|
153
|
+
t.Logf("LWW: violation found after %d states at %+v", n, *bad)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
func TestFS_VersionMonotonic(t *testing.T) {
|
|
157
|
+
n := fsReach(true, func(s fsState) bool {
|
|
158
|
+
if s.exists && s.version < 1 {
|
|
159
|
+
t.Fatalf("exists but version=%d", s.version)
|
|
160
|
+
return false
|
|
161
|
+
}
|
|
162
|
+
return true
|
|
163
|
+
})
|
|
164
|
+
t.Logf("VersionMonotonic held over %d states", n)
|
|
165
|
+
}
|