Public: anyone can read this; the crew can change it.
The data volume has under 15% free #13594
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/13576-the-data-volume-has-under-15-free → main 1 commit fork 1 thread · 1 unresolved
3 files
changed +46
−4
docs/features/disk-free.md +5
| @@ -28,3 +28,8 @@ an open issue or pull that nothing has touched for a day and no live run holds | ||
| 28 | 28 | `runs/` held 15 GiB at the last count. `pruneRunFiles` (`src/runs/prune.ts`) now removes a run |
| 29 | 29 | log or vitals file seven days after its last write, not fourteen; the run pages already say "no |
| 30 | 30 | log" for a missing one. |
| 31 | ||
| 32 | ## Run logs have a size cap (#13576) | |
| 33 | ||
| 34 | `pruneRunFiles` also keeps `runs/` under 8 GiB (`RUN_FILES_MAX_BYTES`): after the age sweep, the | |
| 35 | oldest remaining files go until the total fits. |
src/runs/prune.ts +26 −4
| @@ -12,11 +12,18 @@ import { runsRoot } from "./log.ts"; | ||
| 12 | 12 | /** Logs and vitals are kept this long after their last write. */ |
| 13 | 13 | export const RUN_FILES_KEEP_MS = 7 * 86_400_000; |
| 14 | 14 | |
| 15 | /** Remove the regular files of `runs/` last written before `now - maxAgeMs`; how many went. */ | |
| 15 | /** The files of `runs/` together are kept under this many bytes: the oldest go first (#13576). */ | |
| 16 | export const RUN_FILES_MAX_BYTES = 8 * 1024 ** 3; | |
| 17 | ||
| 18 | /** | |
| 19 | * Remove the regular files of `runs/` last written before `now - maxAgeMs`, then the oldest | |
| 20 | * of the rest while the total is over `maxBytes`; how many went. | |
| 21 | */ | |
| 16 | 22 | export function pruneRunFiles( |
| 17 | 23 | dataDir: string, |
| 18 | 24 | now: number = Date.now(), |
| 19 | 25 | maxAgeMs: number = RUN_FILES_KEEP_MS, |
| 26 | maxBytes: number = RUN_FILES_MAX_BYTES, | |
| 20 | 27 | ): number { |
| 21 | 28 | const root = runsRoot(dataDir); |
| 22 | 29 | let removed = 0; |
| @@ -26,16 +33,31 @@ export function pruneRunFiles( | ||
| 26 | 33 | } catch { |
| 27 | 34 | return 0; |
| 28 | 35 | } |
| 36 | const kept: { path: string; mtime: number; size: number }[] = []; | |
| 29 | 37 | for (const name of names) { |
| 30 | 38 | const path = join(root, name); |
| 31 | 39 | try { |
| 32 | 40 | const st = statSync(path); |
| 33 | if (!st.isFile() || now - st.mtimeMs <= maxAgeMs) continue; | |
| 34 | rmSync(path, { force: true }); | |
| 35 | removed++; | |
| 41 | if (!st.isFile()) continue; | |
| 42 | if (now - st.mtimeMs > maxAgeMs) { | |
| 43 | rmSync(path, { force: true }); | |
| 44 | removed++; | |
| 45 | } else kept.push({ path, mtime: st.mtimeMs, size: st.size }); | |
| 36 | 46 | } catch { |
| 37 | 47 | // gone already, or busy: the next sweep looks again |
| 38 | 48 | } |
| 39 | 49 | } |
| 50 | let total = kept.reduce((sum, f) => sum + f.size, 0); | |
| 51 | kept.sort((a, b) => a.mtime - b.mtime); | |
| 52 | for (const f of kept) { | |
| 53 | if (total <= maxBytes) break; | |
| 54 | try { | |
| 55 | rmSync(f.path, { force: true }); | |
| 56 | removed++; | |
| 57 | total -= f.size; | |
| 58 | } catch { | |
| 59 | // busy: the next sweep looks again | |
| 60 | } | |
| 61 | } | |
| 40 | 62 | return removed; |
| 41 | 63 | } |
test/run-prune.test.ts +15
| @@ -38,3 +38,18 @@ test("a log is kept a week after its last write (#13569)", () => { | ||
| 38 | 38 | expect(existsSync(nine)).toBe(false); |
| 39 | 39 | expect(existsSync(five)).toBe(true); |
| 40 | 40 | }); |
| 41 | ||
| 42 | test("over the size cap the oldest files go first (#13576)", () => { | |
| 43 | const dir = mkdtempSync(join(tmpdir(), "prune-")); | |
| 44 | mkdirSync(runsRoot(dir), { recursive: true }); | |
| 45 | const at = (days: number) => new Date(Date.now() - days * 86_400_000); | |
| 46 | for (const [name, days] of [["a", 3], ["b", 2], ["c", 1]] as const) { | |
| 47 | const f = join(runsRoot(dir), `${name}.log`); | |
| 48 | writeFileSync(f, "x".repeat(100)); | |
| 49 | utimesSync(f, at(days), at(days)); | |
| 50 | } | |
| 51 | expect(pruneRunFiles(dir, Date.now(), RUN_FILES_KEEP_MS, 200)).toBe(1); | |
| 52 | expect(existsSync(join(runsRoot(dir), "a.log"))).toBe(false); | |
| 53 | expect(existsSync(join(runsRoot(dir), "b.log"))).toBe(true); | |
| 54 | expect(existsSync(join(runsRoot(dir), "c.log"))).toBe(true); | |
| 55 | }); |
new above
offline
Sorting by mtime means a still-written log is newest and safe, but ties break arbitrarily; consider path as a tiebreaker so the sweep is deterministic.