/** * P4.14: idle-time WAL maintenance for the detached project-server daemon. * * `wal_autocheckpoint=1000` is PASSIVE and only attempts a checkpoint after a * COMMIT. A daemon whose clients keep issuing searches (long-running WAL * readers) can hold WAL snapshots indefinitely: the autocheckpointer sees * busy=1 every time and the WAL grows without bound until a reader gap or * shutdown. Nothing re-fires once writes stop — a COMMIT is what arms it. * * This scheduler gives the daemon its own maintenance heartbeat: * - every completed write run arms a sliding idle timer; * - when it fires (no further writes slid it), it checkpoints the WAL * (probe-first; never blocks on readers) and periodically runs * `PRAGMA optimize` so the query planner's statistics stay current. * * All timers are unref'd — they must never keep the daemon alive past its * idle-exit, and firing is harmless at any point because checkpointWal is * best-effort. */ interface WalMaintenanceOptions { /** Idle window after a write completion before maintenance fires. */ idleMs?: number | undefined; /** Run `optimize()` once every N maintenance fires. Default: 8. */ optimizeEvery?: number | undefined; /** Clock for tests. */ setTimeoutFn?: typeof setTimeout | undefined; /** Clear for tests. */ clearTimeoutFn?: typeof clearTimeout | undefined; } interface WalMaintenanceHooks { /** Returns true when a checkpoint completed (WAL reset). */ checkpoint: () => boolean; /** Recompute statistics. */ optimize: () => void; } export declare class WalMaintenance { private readonly hooks; private timer; private fireCount; private disposed; private readonly idleMs; private readonly optimizeEvery; private readonly setTimeoutFn; private readonly clearTimeoutFn; constructor(hooks: WalMaintenanceHooks, options?: WalMaintenanceOptions); /** * Arm (or re-arm) the idle timer. Call after every completed write run — * bursty incremental writes keep sliding the window so maintenance runs * once after the burst settles, not per write. */ notifyWriteCompleted(): void; private fire; /** True when an idle fire is pending (test visibility). */ get armed(): boolean; /** Stop all maintenance. Idempotent; safe to call on every shutdown path. */ dispose(): void; } export {}; //# sourceMappingURL=wal-maintenance.d.ts.map