Skip to content

Commit 476ab93

Browse files
EtanHeyclaude
andcommitted
perf(server): every reclaim span records its page count
The page count was annotated only after a completed loop, so a pass on a database without incremental vacuum, or one that failed partway, ended its span without it. Annotate in a finalizer instead. Claude Opus 5.5 via T3 Code. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f57a4d3 commit 476ab93

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

‎apps/server/src/persistence/DatabaseStorage.ts‎

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,25 @@ const make = Effect.gen(function* () {
8282
Effect.catch((cause) => Effect.logWarning("Database storage inspection failed", { cause })),
8383
);
8484

85-
const reclaim = Effect.gen(function* () {
86-
if (!(yield* readLayout).incrementalVacuum) return;
87-
// The driver steps once per statement; incremental_vacuum frees one page per step. Yield between pages.
85+
const reclaim = Effect.suspend(() => {
8886
let page = 0;
89-
for (; page < RECLAIM_PAGES_PER_PASS; page++) {
90-
const free = yield* sql<{ readonly freelist_count: number }>`PRAGMA freelist_count`;
91-
if ((free[0]?.freelist_count ?? 0) === 0) break;
92-
yield* sql`PRAGMA incremental_vacuum(1)`;
93-
yield* Effect.yieldNow;
94-
}
95-
yield* Effect.annotateCurrentSpan("db.reclaimed_pages", page);
96-
}).pipe(
97-
Effect.catch((cause) => Effect.logWarning("Database space reclamation failed", { cause })),
98-
// The pass owns the span; tracing each page's two PRAGMAs floods the server trace.
99-
Effect.withTracerEnabled(false),
100-
Effect.withSpan("DatabaseStorage.reclaim"),
101-
);
87+
return Effect.gen(function* () {
88+
if (!(yield* readLayout).incrementalVacuum) return;
89+
// The driver steps once per statement; incremental_vacuum frees one page per step. Yield between pages.
90+
for (; page < RECLAIM_PAGES_PER_PASS; page++) {
91+
const free = yield* sql<{ readonly freelist_count: number }>`PRAGMA freelist_count`;
92+
if ((free[0]?.freelist_count ?? 0) === 0) break;
93+
yield* sql`PRAGMA incremental_vacuum(1)`;
94+
yield* Effect.yieldNow;
95+
}
96+
}).pipe(
97+
Effect.ensuring(Effect.suspend(() => Effect.annotateCurrentSpan("db.reclaimed_pages", page))),
98+
Effect.catch((cause) => Effect.logWarning("Database space reclamation failed", { cause })),
99+
// The pass owns the span; tracing each page's two PRAGMAs floods the server trace.
100+
Effect.withTracerEnabled(false),
101+
Effect.withSpan("DatabaseStorage.reclaim"),
102+
);
103+
});
102104

103105
// Even a pass that deletes nothing scans the event store. Persist completion
104106
// so restarting does not trigger another scan before the six-hour interval.

0 commit comments

Comments
 (0)