Commit 960712b
WorkerCallEvents/WorkerCdr crash-loop with PDOException "no such table:
cdr" (Sentry #27651, 2600+ events on 3 servers) when the CDR database
file is recreated empty after corruption or a storage remount. Adds
runtime recovery via DatabaseProviderBase::ensureCdrTables() called at
both worker startups, serialised through MutexProvider so the parallel
WorkerSafeScripts Fiber restarts cannot race on
createUpdateDbTableByAnnotations(). Wraps the known crash points
(InsertDataToDB::execute, UpdateDataInDB::execute, ActionHangupChan::execute,
CallDetailRecordsTmp::afterSave move-to-cdr_general, and
WorkerCallEvents::deleteOldRecords) in try/catch so a missing table no
longer takes the whole worker down. deleteOldRecords also
parameterises its DELETE and short-circuits via tableExists() to avoid
spamming Sentry every minute when recovery failed.
Closes #1019: PRAGMA journal_mode=WAL, busy_timeout=5000,
synchronous=NORMAL, cache_size and temp_store now apply to
CDRDatabaseProvider and RecordingStorageDatabaseProvider in addition
to MainDatabaseProvider. With WAL, REST API readers
(WorkerApiCommands x3, AGI CdrDb.php, voicemail-sender) no longer
block the WorkerCallEvents writer. WAL is gated on
isWalSafeFilesystem() which reads /proc/mounts and falls back to
rollback journal on NFS/CIFS/SSHFS/davfs/glusterfs/ceph/lustre/gpfs
(WAL shared-memory mmap is unsafe on network filesystems).
DeleteRecordAction now dispatches deletion through a new
WorkerCdr::DELETE_CDR_TUBE Beanstalk queue handled by DeleteCDR inside
WorkerCallEvents, restoring the single-writer contract on cdr.db and
preventing parallel writes between WorkerApiCommands and the call
event worker. The action keeps its input validation in the REST
context, checks BeanstalkClient::isConnected() (the constructor
swallows connect errors), uses a 60s worker timeout for cascade
deletes on slow USB storage, and forwards the request as a single
sendRequest. DeleteCDR carries the previously-private deletion
helpers, JSON-encodes the audit context to prevent log injection,
uses JSON_THROW_ON_ERROR | JSON_INVALID_UTF8_SUBSTITUTE for replies,
and refuses to unlink recording files outside
Directories::AST_MONITOR_DIR via realpath + base prefix check.
Verification on a live mikopbx container:
- DROP TABLE cdr; cdr_general → SIGUSR1 → WorkerSafeScripts restart
rebuilds both tables via annotations and only one of the two
parallel workers logs "CDR tables missing" (mutex confirmed).
- cdr.db PRAGMA journal_mode = wal after recovery; -wal/-shm files
present.
- DELETE /cdr/<id> single, DELETE /cdr/mikopbx-* cascade (3 records),
404 on missing id, 400 on invalid format, 400 on empty id all
return correct httpCode and JSON shape.
- No PDOException, "no such table", or "Refused to delete" entries
in syslog after the cycle.
1 parent e26e6b9 commit 960712b
9 files changed
Lines changed: 647 additions & 282 deletions
File tree
- src
- Common
- Models
- Providers
- Core/Workers
- Libs/WorkerCallEvents
- PBXCoreREST/Lib/Cdr
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
100 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
101 | 108 | | |
102 | | - | |
103 | 109 | | |
104 | 110 | | |
105 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
25 | 28 | | |
| 29 | + | |
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
| 36 | + | |
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
| |||
99 | 104 | | |
100 | 105 | | |
101 | 106 | | |
102 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
103 | 113 | | |
104 | 114 | | |
105 | 115 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
110 | 132 | | |
111 | 133 | | |
112 | 134 | | |
113 | | - | |
| 135 | + | |
114 | 136 | | |
115 | 137 | | |
116 | | - | |
| 138 | + | |
117 | 139 | | |
118 | 140 | | |
119 | 141 | | |
| |||
168 | 190 | | |
169 | 191 | | |
170 | 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 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 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 | + | |
| 327 | + | |
| 328 | + | |
171 | 329 | | |
172 | 330 | | |
173 | 331 | | |
| |||
Lines changed: 16 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
52 | | - | |
53 | | - | |
54 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
55 | 58 | | |
56 | | - | |
57 | | - | |
| 59 | + | |
| 60 | + | |
58 | 61 | | |
59 | | - | |
60 | | - | |
| 62 | + | |
| 63 | + | |
61 | 64 | | |
62 | | - | |
63 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
64 | 71 | | |
65 | 72 | | |
66 | 73 | | |
| |||
0 commit comments