Commit 3a23ab8
authored
@TransactionalStep (#400)
Adds `transact-spring-txstep-starter`, a new Spring Boot
auto-configuration module that brings `@TransactionalStep` to Spring
applications.
**What it does:**
- Introduces `@TransactionalStep`, a method annotation that marks a
Spring-managed method as an idempotent DBOS step. The method body runs
inside a `REQUIRES_NEW` Spring transaction; the return value is written
to `tx_step_outputs` **atomically** with the user's database work. On
workflow retry, the recorded output is replayed without re-executing the
method body.
- `TransactionalStepAspect` intercepts annotated methods and delegates
to `TransactionalStepFactory`, which calls `DBOS.runStep()` and uses
`DataSourceUtils.getConnection()` to write step output on the same
transaction-bound connection.
- `TransactionalStepAutoConfiguration` wires up the factory and aspect
as Spring beans, auto-configured via `AutoConfiguration.imports`.
- `TransactionalStepRegistrar` scans the Spring context post-startup and
calls `factory.initialize()` (creates `tx_step_outputs`) only when
annotated methods are found — no DB contact for apps that don't use the
annotation.
- JPA support: `TransactionalStepFactory` auto-detects
`JpaTransactionManager` and sets its `dataSource` property to bridge JPA
transactions to `DataSourceUtils`.
**Supported stacks (all covered by integration tests):**
- Spring JDBC / `JdbcTemplate`
- JDBI (`jdbi3-spring` transaction binding)
- jOOQ (`spring-boot-starter-jooq`)
- JPA / Hibernate (`spring-boot-starter-data-jpa`)
This PR also fixes previously implemented step factory's handling of
concurrent updates. If two executors race to run the same step, both may
pass the initial `checkExecution` read before either has committed.
Previously, both executors transactions would commit, with the 2nd
`recordOutput` INSERT being ignored. This has been fixed so the race
loser's `recordOutput` INSERT into `tx_step_outputs` hits the
`(workflow_id, step_id)` unique constraint. The factory catches the
resulting `23505` violation and converts it to a
`StepConflictException`. The calling code catches
`StepConflictException`, rolls back the REQUIRES_NEW transaction
(discarding the loser's database work), then re-reads tx_step_outputs to
return the winner's committed result:
The outcome is idempotent from the caller's perspective: both executors
return the same winner result, and only the winner's database write is
committed.
Also includes minor refactors to `JdbcStepFactory`, `JdbiStepFactory`,
and `JooqStepFactory` to extract shared SQL into `TxStepSchema` helpers,
and expands their test suites.
fixes #3851 parent 35ad670 commit 3a23ab8
24 files changed
Lines changed: 3553 additions & 101 deletions
File tree
- gradle
- transact-jdbi-step-factory/src
- main/java/dev/dbos/transact/jdbi
- test/java/dev/dbos/transact/jdbi
- transact-jooq-step-factory/src
- main/java/dev/dbos/transact/jooq
- test/java/dev/dbos/transact/jooq
- transact-spring-txstep-starter
- src
- main
- java/dev/dbos/transact/spring/txstep
- resources/META-INF/spring
- test/java/dev/dbos/transact/spring/txstep
- transact/src
- main/java/dev/dbos/transact/txstep
- test/java/dev/dbos/transact/txstep
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| 67 | + | |
65 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
66 | 72 | | |
67 | 73 | | |
68 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
Lines changed: 38 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
110 | | - | |
111 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
112 | 115 | | |
113 | 116 | | |
114 | 117 | | |
115 | 118 | | |
116 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
117 | 131 | | |
118 | 132 | | |
119 | 133 | | |
| |||
144 | 158 | | |
145 | 159 | | |
146 | 160 | | |
147 | | - | |
| 161 | + | |
148 | 162 | | |
149 | 163 | | |
150 | 164 | | |
| |||
168 | 182 | | |
169 | 183 | | |
170 | 184 | | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
175 | 192 | | |
176 | 193 | | |
177 | 194 | | |
| |||
181 | 198 | | |
182 | 199 | | |
183 | 200 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
192 | 214 | | |
193 | 215 | | |
Lines changed: 72 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| 22 | + | |
| 23 | + | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
| |||
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
| 41 | + | |
| 42 | + | |
38 | 43 | | |
39 | 44 | | |
40 | 45 | | |
41 | 46 | | |
42 | 47 | | |
| 48 | + | |
| 49 | + | |
43 | 50 | | |
44 | | - | |
| 51 | + | |
45 | 52 | | |
| 53 | + | |
| 54 | + | |
46 | 55 | | |
47 | 56 | | |
48 | 57 | | |
| |||
106 | 115 | | |
107 | 116 | | |
108 | 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 | + | |
109 | 150 | | |
110 | 151 | | |
111 | 152 | | |
| |||
134 | 175 | | |
135 | 176 | | |
136 | 177 | | |
137 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
138 | 181 | | |
139 | 182 | | |
140 | 183 | | |
| |||
376 | 419 | | |
377 | 420 | | |
378 | 421 | | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
379 | 449 | | |
380 | 450 | | |
381 | 451 | | |
| |||
Lines changed: 36 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
89 | | - | |
90 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
91 | 94 | | |
92 | 95 | | |
93 | 96 | | |
94 | 97 | | |
95 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
96 | 110 | | |
97 | 111 | | |
98 | 112 | | |
| |||
119 | 133 | | |
120 | 134 | | |
121 | 135 | | |
122 | | - | |
| 136 | + | |
123 | 137 | | |
124 | 138 | | |
125 | 139 | | |
| |||
141 | 155 | | |
142 | 156 | | |
143 | 157 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
153 | 170 | | |
154 | 171 | | |
155 | 172 | | |
| |||
159 | 176 | | |
160 | 177 | | |
161 | 178 | | |
162 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
163 | 185 | | |
164 | 186 | | |
0 commit comments