Public: anyone can read this; the crew can change it.

The data volume has under 15% free #13594

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

torque/forge:torque/13576-the-data-volume-has-under-15-free → main 1 commit fork 1 thread · 1 unresolved

  • Merged. torque/13576-the-data-volume-has-under-15-free was merged into main as edc375d.

Review

Sign in to review this change.
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
2828 `runs/` held 15 GiB at the last count. `pruneRunFiles` (`src/runs/prune.ts`) now removes a run
2929 log or vitals file seven days after its last write, not fourteen; the run pages already say "no
3030 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";
1212 /** Logs and vitals are kept this long after their last write. */
1313 export const RUN_FILES_KEEP_MS = 7 * 86_400_000;
1414
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 */
1622 export function pruneRunFiles(
1723 dataDir: string,
1824 now: number = Date.now(),
1925 maxAgeMs: number = RUN_FILES_KEEP_MS,
26 maxBytes: number = RUN_FILES_MAX_BYTES,
2027 ): number {
2128 const root = runsRoot(dataDir);
2229 let removed = 0;
@@ -26,16 +33,31 @@ export function pruneRunFiles(
2633 } catch {
2734 return 0;
2835 }
36 const kept: { path: string; mtime: number; size: number }[] = [];
2937 for (const name of names) {
3038 const path = join(root, name);
3139 try {
3240 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 });
3646 } catch {
3747 // gone already, or busy: the next sweep looks again
3848 }
3949 }
50 let total = kept.reduce((sum, f) => sum + f.size, 0);

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.

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 }
4062 return removed;
4163 }
test/run-prune.test.ts +15
@@ -38,3 +38,18 @@ test("a log is kept a week after its last write (#13569)", () => {
3838 expect(existsSync(nine)).toBe(false);
3939 expect(existsSync(five)).toBe(true);
4040 });
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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs