Commit 1ae0d7c
fix: async branch cleanup - fix test races, deadlock, and SQL bug
- Add BackgroundCleanupTracker interface so CleanDbTestListener can wait
for in-flight async cleanup workers before truncating tables, preventing
the PostgreSQL deadlock between BranchCleanupWorker's DELETE row locks
and CleanDbTestListener's ALTER TABLE DISABLE TRIGGER ALL.
- Refactor BranchCleanupWorker: scheduleCleanup() is now a plain method
(called within the active transaction) that registers the tracker and
hooks TransactionSynchronization to dispatch the @async executeCleanup()
after commit (and deregisters on rollback). BranchServiceImpl.deleteBranch
is reduced to a single branchCleanupWorker.scheduleCleanup() call with no
transaction sync boilerplate. Self-injection via @lazy enables the
afterCommit callback to go through the Spring proxy for @async dispatch.
- Fix SQL bug: ScreenshotRepository.findOrphanFilenamesByBranchId used
native SQL selecting s.filename, but Screenshot.filename is a Kotlin
computed property (not a DB column). Changed to JPQL returning Screenshot
entities; updated ScreenshotService.deleteFilesByBranch accordingly.
- Update BranchControllerTest and BranchCopyIntegrationTest to use
branchCleanupWorker.waitForPendingCleanups() instead of waitForNotThrowing.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 6baf1bf commit 1ae0d7c
9 files changed
Lines changed: 419 additions & 107 deletions
File tree
- backend
- data/src/main/kotlin/io/tolgee
- component
- repository
- service/key
- testing/src/main/kotlin/io/tolgee
- ee/backend
- app/src/main/kotlin/io/tolgee/ee/service/branching
- tests/src/test/kotlin/io/tolgee/ee/api/v2/controllers/branching
Lines changed: 17 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 | + | |
Lines changed: 26 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 | | |
| |||
75 | 76 | | |
76 | 77 | | |
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 | + | |
78 | 104 | | |
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
354 | 365 | | |
355 | 366 | | |
356 | 367 | | |
| |||
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
39 | 47 | | |
40 | 48 | | |
41 | 49 | | |
| |||
54 | 62 | | |
55 | 63 | | |
56 | 64 | | |
57 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
58 | 68 | | |
59 | 69 | | |
60 | 70 | | |
| |||
0 commit comments