import db from '@adonisjs/lucid/services/db' import logger from '@adonisjs/core/services/logger' import coordinatorConfig from '#config/coordinator' /** How often the catalog's size is measured (pg_tablespace_size walks its files). */ const CHECK_MS = 60_000 /** * The catalog's room on the NVMe (CATALOG_MAX_NVME_GB, like voyager 1's * BACKFILL_MAX_NVME_GB): once its tablespace (the database's * default_tablespace) is over the cap, only the tail and the stored ranges * (priority below 0) are leased and prefetched, and history waits. After * reset 24 the catalog grew ~3.7 GB an hour, root down to 31 GB free with * 600k history ranges to go (LOG.md 2026-10-14 (53)). Off when unset. */ class CatalogSpace { private checkedAt = 0 private over = false async full(): Promise { const cap = coordinatorConfig.catalogMaxNvmeGb if (!cap) return false if (Date.now() - this.checkedAt < CHECK_MS) return this.over this.checkedAt = Date.now() const { rows } = await db.rawQuery( `SELECT pg_tablespace_size(coalesce(nullif(current_setting('default_tablespace'), ''), 'pg_default')) AS bytes` ) const bytes = Number(rows[0].bytes) const was = this.over this.over = bytes > cap * 1e9 if (this.over !== was) { logger.info(`Catalog ${(bytes / 1e9).toFixed(1)} GB of ${cap}: history ${this.over ? 'paused (tail and stored ranges only)' : 'resumed'}.`) } return this.over } } export default new CatalogSpace()