|
| 1 | +---- MODULE TaskDelegation ---- |
| 2 | +EXTENDS Naturals, TLC |
| 3 | + |
| 4 | +CONSTANTS ParentProfile, ChildProfile |
| 5 | + |
| 6 | +Profiles == { ParentProfile, ChildProfile } |
| 7 | +FocusValues == { "parent", "child", "none" } |
| 8 | +Phases == { |
| 9 | + "parent-running", |
| 10 | + "parent-suspended", |
| 11 | + "permit-reserved", |
| 12 | + "child-profile-selected", |
| 13 | + "child-created", |
| 14 | + "delegation-persisted", |
| 15 | + "child-running", |
| 16 | + "child-completed", |
| 17 | + "failed" |
| 18 | +} |
| 19 | +HistoryStatuses == { "active", "delegated", "completed" } |
| 20 | + |
| 21 | +VARIABLES |
| 22 | + phase, |
| 23 | + maxConcurrency, |
| 24 | + permitsHeld, |
| 25 | + reservedPermit, |
| 26 | + focus, |
| 27 | + globalProfile, |
| 28 | + parentLive, |
| 29 | + parentLocalProfile, |
| 30 | + parentHistoryStatus, |
| 31 | + childLive, |
| 32 | + childLocalProfile, |
| 33 | + childHistoryStatus |
| 34 | + |
| 35 | +vars == << |
| 36 | + phase, |
| 37 | + maxConcurrency, |
| 38 | + permitsHeld, |
| 39 | + reservedPermit, |
| 40 | + focus, |
| 41 | + globalProfile, |
| 42 | + parentLive, |
| 43 | + parentLocalProfile, |
| 44 | + parentHistoryStatus, |
| 45 | + childLive, |
| 46 | + childLocalProfile, |
| 47 | + childHistoryStatus |
| 48 | +>> |
| 49 | + |
| 50 | +Init == |
| 51 | + /\ phase = "parent-running" |
| 52 | + /\ maxConcurrency \in { 1, 2 } |
| 53 | + /\ permitsHeld = IF maxConcurrency = 2 THEN 1 ELSE 0 |
| 54 | + /\ reservedPermit = FALSE |
| 55 | + /\ focus = "parent" |
| 56 | + /\ globalProfile = ParentProfile |
| 57 | + /\ parentLive = TRUE |
| 58 | + /\ parentLocalProfile = ParentProfile |
| 59 | + /\ parentHistoryStatus = "active" |
| 60 | + /\ childLive = FALSE |
| 61 | + /\ childLocalProfile = ChildProfile |
| 62 | + /\ childHistoryStatus = "active" |
| 63 | + |
| 64 | +ActivePermits == permitsHeld + IF reservedPermit THEN 1 ELSE 0 |
| 65 | + |
| 66 | +ReserveFanOutPermit == |
| 67 | + /\ phase = "parent-running" |
| 68 | + /\ maxConcurrency > 1 |
| 69 | + /\ ActivePermits < maxConcurrency |
| 70 | + /\ phase' = "permit-reserved" |
| 71 | + /\ reservedPermit' = TRUE |
| 72 | + /\ UNCHANGED << maxConcurrency, permitsHeld, focus, globalProfile, parentLive, parentLocalProfile, parentHistoryStatus, |
| 73 | + childLive, childLocalProfile, childHistoryStatus >> |
| 74 | + |
| 75 | +SuspendParentForSerialDelegation == |
| 76 | + /\ phase = "parent-running" |
| 77 | + /\ maxConcurrency = 1 |
| 78 | + /\ phase' = "parent-suspended" |
| 79 | + /\ parentLive' = FALSE |
| 80 | + /\ focus' = "none" |
| 81 | + /\ UNCHANGED << maxConcurrency, permitsHeld, reservedPermit, globalProfile, parentLocalProfile, parentHistoryStatus, |
| 82 | + childLive, childLocalProfile, childHistoryStatus >> |
| 83 | + |
| 84 | +CreateChildAfterSuspendSucceeds == |
| 85 | + /\ phase = "parent-suspended" |
| 86 | + /\ phase' = "child-created" |
| 87 | + /\ focus' = "child" |
| 88 | + /\ globalProfile' = ChildProfile |
| 89 | + /\ childLive' = TRUE |
| 90 | + /\ childLocalProfile' = ChildProfile |
| 91 | + /\ childHistoryStatus' = "active" |
| 92 | + /\ UNCHANGED << maxConcurrency, permitsHeld, reservedPermit, parentLive, parentLocalProfile, parentHistoryStatus >> |
| 93 | + |
| 94 | +CreateChildAfterSuspendFails == |
| 95 | + /\ phase = "parent-suspended" |
| 96 | + /\ phase' = "failed" |
| 97 | + /\ parentLive' = TRUE |
| 98 | + /\ focus' = "parent" |
| 99 | + /\ UNCHANGED << maxConcurrency, permitsHeld, reservedPermit, globalProfile, parentLocalProfile, parentHistoryStatus, |
| 100 | + childLive, childLocalProfile, childHistoryStatus >> |
| 101 | + |
| 102 | +SelectChildProfile == |
| 103 | + /\ phase = "permit-reserved" |
| 104 | + /\ phase' = "child-profile-selected" |
| 105 | + /\ globalProfile' = ChildProfile |
| 106 | + /\ UNCHANGED << maxConcurrency, permitsHeld, reservedPermit, focus, parentLive, parentLocalProfile, parentHistoryStatus, |
| 107 | + childLive, childLocalProfile, childHistoryStatus >> |
| 108 | + |
| 109 | +CreateChildSucceeds == |
| 110 | + /\ phase = "child-profile-selected" |
| 111 | + /\ phase' = "child-created" |
| 112 | + /\ focus' = "child" |
| 113 | + /\ childLive' = TRUE |
| 114 | + /\ childLocalProfile' = globalProfile |
| 115 | + /\ childHistoryStatus' = "active" |
| 116 | + /\ UNCHANGED << maxConcurrency, permitsHeld, reservedPermit, globalProfile, parentLive, parentLocalProfile, parentHistoryStatus >> |
| 117 | + |
| 118 | +CreateChildFails == |
| 119 | + /\ phase = "child-profile-selected" |
| 120 | + /\ phase' = "failed" |
| 121 | + /\ reservedPermit' = FALSE |
| 122 | + /\ focus' = "parent" |
| 123 | + /\ globalProfile' = ParentProfile |
| 124 | + /\ childLive' = FALSE |
| 125 | + /\ childLocalProfile' = ChildProfile |
| 126 | + /\ childHistoryStatus' = "active" |
| 127 | + /\ UNCHANGED << maxConcurrency, permitsHeld, parentLive, parentLocalProfile, parentHistoryStatus >> |
| 128 | + |
| 129 | +PersistDelegationSucceeds == |
| 130 | + /\ phase = "child-created" |
| 131 | + /\ phase' = "delegation-persisted" |
| 132 | + /\ parentHistoryStatus' = "delegated" |
| 133 | + /\ UNCHANGED << maxConcurrency, permitsHeld, reservedPermit, focus, globalProfile, parentLive, parentLocalProfile, |
| 134 | + childLive, childLocalProfile, childHistoryStatus >> |
| 135 | + |
| 136 | +PersistDelegationFails == |
| 137 | + /\ phase = "child-created" |
| 138 | + /\ phase' = "failed" |
| 139 | + /\ reservedPermit' = FALSE |
| 140 | + /\ focus' = "parent" |
| 141 | + /\ globalProfile' = ParentProfile |
| 142 | + /\ parentLive' = TRUE |
| 143 | + /\ childLive' = FALSE |
| 144 | + /\ childLocalProfile' = ChildProfile |
| 145 | + /\ childHistoryStatus' = "active" |
| 146 | + /\ UNCHANGED << maxConcurrency, permitsHeld, parentLocalProfile, parentHistoryStatus >> |
| 147 | + |
| 148 | +StartChildWithReservation == |
| 149 | + /\ phase = "delegation-persisted" |
| 150 | + /\ reservedPermit = TRUE |
| 151 | + /\ phase' = "child-running" |
| 152 | + /\ reservedPermit' = FALSE |
| 153 | + /\ permitsHeld' = permitsHeld + 1 |
| 154 | + /\ UNCHANGED << maxConcurrency, focus, globalProfile, parentLive, parentLocalProfile, parentHistoryStatus, |
| 155 | + childLive, childLocalProfile, childHistoryStatus >> |
| 156 | + |
| 157 | +ParentContinues == |
| 158 | + /\ phase = "child-running" |
| 159 | + /\ UNCHANGED vars |
| 160 | + |
| 161 | +ChildUsesScopedProfile == |
| 162 | + /\ phase = "child-running" |
| 163 | + /\ UNCHANGED vars |
| 164 | + |
| 165 | +ChildCompletes == |
| 166 | + /\ phase = "child-running" |
| 167 | + /\ phase' = "child-completed" |
| 168 | + /\ permitsHeld' = permitsHeld - 1 |
| 169 | + /\ focus' = "parent" |
| 170 | + /\ childLive' = FALSE |
| 171 | + /\ childHistoryStatus' = "completed" |
| 172 | + /\ UNCHANGED << maxConcurrency, reservedPermit, globalProfile, parentLive, parentLocalProfile, parentHistoryStatus, |
| 173 | + childLocalProfile >> |
| 174 | + |
| 175 | +Next == |
| 176 | + \/ ReserveFanOutPermit |
| 177 | + \/ SuspendParentForSerialDelegation |
| 178 | + \/ CreateChildAfterSuspendSucceeds |
| 179 | + \/ CreateChildAfterSuspendFails |
| 180 | + \/ SelectChildProfile |
| 181 | + \/ CreateChildSucceeds |
| 182 | + \/ CreateChildFails |
| 183 | + \/ PersistDelegationSucceeds |
| 184 | + \/ PersistDelegationFails |
| 185 | + \/ StartChildWithReservation |
| 186 | + \/ ParentContinues |
| 187 | + \/ ChildUsesScopedProfile |
| 188 | + \/ ChildCompletes |
| 189 | + |
| 190 | +Spec == Init /\ [][Next]_vars |
| 191 | + |
| 192 | +PermitBound == ActivePermits <= maxConcurrency |
| 193 | +NonNegativePermits == permitsHeld >= 0 |
| 194 | +ParentProfileIsolation == parentLive => parentLocalProfile = ParentProfile |
| 195 | +ChildProfileIsolation == childLive => childLocalProfile = ChildProfile |
| 196 | +RollbackRestoresParent == |
| 197 | + phase = "failed" => /\ reservedPermit = FALSE |
| 198 | + /\ parentLive = TRUE |
| 199 | + /\ focus = "parent" |
| 200 | +RunningChildHasDelegatedParent == |
| 201 | + phase = "child-running" => /\ childLive = TRUE |
| 202 | + /\ parentHistoryStatus = "delegated" |
| 203 | +FocusReferencesLiveTask == |
| 204 | + /\ focus \in FocusValues |
| 205 | + /\ (focus = "parent" => parentLive) |
| 206 | + /\ (focus = "child" => childLive) |
| 207 | + |
| 208 | +==== |
0 commit comments