Commit 934d496
authored
Fix concurrent applySchedules invocation (#450)
Port of dbos-inc/dbos-transact-py#741 to Java.
# Problem
SchedulesDAO.applySchedules implemented "create or replace" as DELETE
followed by INSERT (with a freshly generated schedule_id every time).
Two concurrent applySchedules calls for the same schedule name could
interleave their delete/insert pairs and collide on the schedule_name
unique constraint. The new schedule_id on every apply also meant a
schedule's identity churned on every edit.
# Fix
- SchedulesDAO: replaced delete+insert with a single INSERT ... ON
CONFLICT (schedule_name) DO UPDATE, making applySchedules idempotent and
race-free. On conflict, schedule_id, status, and last_fired_at are
preserved from the existing row; only the definition fields (workflow
name/class, cron, context, backfill flag, timezone, queue) are updated.
- SchedulerService: since schedule_id no longer changes on re-apply, the
poller can no longer rely on a new ID to detect an edited schedule.
Added RunningSchedule, a record snapshotting each running schedule's
definition fields (excluding identity/status/runtime state) plus its
current ScheduledFuture, keyed by schedule id in a single map
(runningSchedules). Each poll compares the live schedule against the
snapshot via RunningSchedule.matches(...); on a mismatch, the schedule's
future is cancelled and restarted with the new definition (no backfill
on restart — only on first start).1 parent b036914 commit 934d496
6 files changed
Lines changed: 474 additions & 157 deletions
File tree
- transact/src
- main/java/dev/dbos/transact
- database
- dao
- execution
- test/java/dev/dbos/transact
- client
- scheduled
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
612 | 613 | | |
613 | 614 | | |
614 | 615 | | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
615 | 629 | | |
616 | 630 | | |
617 | 631 | | |
| |||
Lines changed: 53 additions & 0 deletions
| 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 | + | |
Lines changed: 76 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
90 | 104 | | |
91 | | - | |
92 | 105 | | |
93 | 106 | | |
94 | 107 | | |
| |||
135 | 148 | | |
136 | 149 | | |
137 | 150 | | |
138 | | - | |
| 151 | + | |
139 | 152 | | |
140 | | - | |
| 153 | + | |
141 | 154 | | |
142 | 155 | | |
143 | 156 | | |
| |||
151 | 164 | | |
152 | 165 | | |
153 | 166 | | |
154 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
155 | 173 | | |
156 | 174 | | |
157 | 175 | | |
| |||
167 | 185 | | |
168 | 186 | | |
169 | 187 | | |
170 | | - | |
| 188 | + | |
171 | 189 | | |
172 | 190 | | |
173 | 191 | | |
| |||
239 | 257 | | |
240 | 258 | | |
241 | 259 | | |
242 | | - | |
243 | | - | |
| 260 | + | |
244 | 261 | | |
245 | 262 | | |
246 | 263 | | |
| |||
257 | 274 | | |
258 | 275 | | |
259 | 276 | | |
260 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
261 | 283 | | |
262 | | - | |
263 | | - | |
264 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
265 | 327 | | |
266 | 328 | | |
267 | 329 | | |
268 | | - | |
| 330 | + | |
269 | 331 | | |
270 | 332 | | |
271 | 333 | | |
272 | 334 | | |
273 | 335 | | |
274 | 336 | | |
275 | | - | |
| 337 | + | |
276 | 338 | | |
277 | 339 | | |
278 | 340 | | |
| |||
0 commit comments