Commit d12cd98
committed
[unfinished] card locking for safe sidecar updates
- created a locking mechanism to ensure cards are locked to individual subprocesses.
- introduced `LockableCardDict` which helps lock cards per subprocess
- introduced `CardStateManager` to save the state of components/data updates during task execution
## life-cycle of cards
1. Pre-task execution :
- @card decorator instantiates a CardComponentCollector with a LockableCardDict set to `pre_task_startup=True` and empty dictionary for it's `card_component_store`
- This ensures that new CardComponentManagers can be trivially added by the main process.
- Once main process is done adding all cards, we run `finalize` method :
- it will set `pre_task_startup=False` and set post_task_startup=True
- it will instantiate the locks. Won't check if they are already possessed by others since the code is being run in the main process and
task execution has not started yet; (All lock alteration happens once user code starts executing).
- Upon finishing finalize `current.card` will also dump the state of `current.card` for being available to any outside subprocesses.
2. Task Execution:
- Main process :
- Which ever cards the main thread update's will be locked by the main thread.
- The cards which are not accessed / updated by the main thread, can be locked by other processes.
- Locked cards will provide the same type of object back to the user, but the `card_proc` method will be replaced with a
method that will warn the user that the card is locked.
- Subprocesses:
- calls the `get_runtime_card` method to get the `current.card` object
- the method will seek out the `current.card`'s state location and load the state.
- the state of the card specifies what ever task spec's component collector's state
- will be able to call render_runtime and refresh from the cli
- `refresh` will also dump the state of the components to disk.
- [todo] when finished will call `current.card.done()` which will dump the state of the components/data-updates to disk
- [todo] no other processes will also be able to lock "done" cards
- [todo] If a subprocess is gracefully shutdown, then:
- [todo] the card manager will call `current.card.done()` which will avoid writes from other processes
3. Post Task Execution:
- sub processes:
- Should have **ideally** ended and released all locks and ran the finalize method.
- If not then what ever is the last component state dumped in the subprocess will be the components loaded for the card.
- Main process:
- For each card,
- call the render method.
- [todo] If the card was locked by an outside process then seek it's component state and load it.
- if the card1 parent 17ec166 commit d12cd98
File tree
5 files changed
+363
-47
lines changed- metaflow/plugins/cards
5 files changed
+363
-47
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
12 | 18 | | |
13 | 19 | | |
14 | 20 | | |
| |||
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
47 | 56 | | |
48 | 57 | | |
49 | | - | |
| 58 | + | |
50 | 59 | | |
51 | 60 | | |
52 | 61 | | |
53 | | - | |
| 62 | + | |
54 | 63 | | |
55 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
56 | 69 | | |
57 | 70 | | |
58 | | - | |
| 71 | + | |
59 | 72 | | |
60 | 73 | | |
61 | 74 | | |
| |||
124 | 137 | | |
125 | 138 | | |
126 | 139 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
133 | 147 | | |
134 | 148 | | |
135 | 149 | | |
| |||
169 | 183 | | |
170 | 184 | | |
171 | 185 | | |
| 186 | + | |
172 | 187 | | |
173 | 188 | | |
174 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | 86 | | |
91 | 87 | | |
92 | 88 | | |
| |||
186 | 182 | | |
187 | 183 | | |
188 | 184 | | |
189 | | - | |
| 185 | + | |
190 | 186 | | |
191 | 187 | | |
192 | 188 | | |
| |||
230 | 226 | | |
231 | 227 | | |
232 | 228 | | |
233 | | - | |
| 229 | + | |
| 230 | + | |
234 | 231 | | |
235 | 232 | | |
236 | 233 | | |
| |||
250 | 247 | | |
251 | 248 | | |
252 | 249 | | |
| 250 | + | |
253 | 251 | | |
254 | 252 | | |
255 | 253 | | |
| |||
264 | 262 | | |
265 | 263 | | |
266 | 264 | | |
267 | | - | |
| 265 | + | |
268 | 266 | | |
269 | 267 | | |
270 | 268 | | |
| |||
277 | 275 | | |
278 | 276 | | |
279 | 277 | | |
280 | | - | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
0 commit comments