Commit 613336d
committed
feat(API): reject writes when disk space drops below 512 MiB
SQLite returns SQLITE_FULL mid-transaction when the underlying
filesystem runs out of space, which can corrupt the WAL and leave the
V1/V2 databases inconsistent. Add a defensive guard that periodically
inspects free space on the cadt/v1 and cadt/v2 data directories and:
- rejects POST/PUT/PATCH writes with HTTP 507 Insufficient Storage when
free space drops below 512 MiB (sized for the existing 100 MB
filestore upload limit + typical WAL growth during batch operations)
- emits a debounced log warning when free space drops below 1 GiB so
operators have advance notice before writes are rejected
- always permits GET reads and DELETE so operators can free space
without restarting the service
Status (severity, freeBytes, threshold) is exposed under the diskSpace
field on /health, /v1/health, and /v2/health for monitoring. /health
uses a non-blocking peek of the cached statfs result so liveness probes
never wait on a slow filesystem (a synchronous statfs round trip can
trip the default k8s livenessProbe timeout precisely when /health most
needs to respond).
Severity transitions (ok->warn, warn->block, etc.) drive a single log
line each. The earlier time-windowed debounce was vulnerable to /health
scrape traffic refreshing the timestamp and silencing the
operator-facing block alert when a real write first hit the threshold.
Mirrors the frsize ?? bsize byte math used by the existing /diagnostics
endpoint so the two views agree on free space.
Thresholds are intentionally not user-configurable; the values are
sized to the existing upload limits and lowering them risks the
SQLITE_FULL the guard is designed to prevent.1 parent 6e1636c commit 613336d
6 files changed
Lines changed: 668 additions & 0 deletions
File tree
- src
- routes
- v1
- v2
- utils
- tests/v2/integration
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
47 | 56 | | |
48 | 57 | | |
49 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
24 | 32 | | |
25 | 33 | | |
26 | 34 | | |
| |||
183 | 191 | | |
184 | 192 | | |
185 | 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 | + | |
186 | 223 | | |
187 | 224 | | |
188 | 225 | | |
| |||
507 | 544 | | |
508 | 545 | | |
509 | 546 | | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
510 | 571 | | |
511 | 572 | | |
512 | 573 | | |
| 574 | + | |
513 | 575 | | |
514 | 576 | | |
515 | 577 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
6 | 12 | | |
7 | 13 | | |
8 | 14 | | |
| |||
19 | 25 | | |
20 | 26 | | |
21 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
22 | 48 | | |
23 | 49 | | |
24 | 50 | | |
| 51 | + | |
25 | 52 | | |
26 | 53 | | |
27 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
31 | 37 | | |
32 | 38 | | |
33 | 39 | | |
34 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
35 | 61 | | |
36 | 62 | | |
37 | 63 | | |
| 64 | + | |
38 | 65 | | |
39 | 66 | | |
40 | 67 | | |
| |||
0 commit comments