@camstack/server 1.2.938 → 1.2.939
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/package.json +3 -5
- package/system/dist/addon-runner.js +8 -0
- package/system/dist/addon-runner.mjs +8 -0
- package/system/dist/builtins/sqlite-storage/index.js +1 -1
- package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/sqlite-pragmas.d.ts +2 -0
- package/system/dist/builtins/sqlite-storage/sqlite-settings-backend.d.ts +3 -0
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +1 -1
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/storage-report-runner.d.ts +6 -0
- package/system/dist/builtins/sqlite-storage/storage-report-worker.d.ts +20 -0
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/index.js +9 -1
- package/system/dist/index.mjs +9 -1
- package/system/dist/storage-report-worker.js +77 -0
- package/system/dist/storage-report-worker.mjs +70 -0
- package/system/dist/{wal-maintenance-O6zTzaI7.mjs → wal-maintenance-CjpslZUL.mjs} +0 -0
- package/system/dist/{wal-maintenance-mV4OR3LR.js → wal-maintenance-DKTXQ7UF.js} +0 -0
- package/system/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.2.939] - 2026-11-22
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Boot no longer spikes memory by several GB: the storage report scans on its own read-only connection with the map off, and the database map is re-sized only after the file fills 90% of it
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Fixed UniFi switch ports and sensors reading offline after a restart: a device already built by its parent is no longer constructed a second time
|
|
19
|
+
|
|
10
20
|
## [1.2.938] - 2026-11-22
|
|
11
21
|
|
|
12
22
|
### Changed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camstack/server",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.939",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -66,9 +66,7 @@
|
|
|
66
66
|
],
|
|
67
67
|
"requires": {
|
|
68
68
|
"addons": {
|
|
69
|
-
"@camstack/addon-
|
|
70
|
-
"@camstack/addon-agent-ui": ">=1.2.434",
|
|
71
|
-
"@camstack/addon-pipeline-orchestrator": ">=1.2.716"
|
|
69
|
+
"@camstack/addon-post-analysis": ">=1.2.722"
|
|
72
70
|
},
|
|
73
71
|
"wrapper": {
|
|
74
72
|
"desktop": ">=0.0.1",
|
|
@@ -85,7 +83,7 @@
|
|
|
85
83
|
"@camstack/addon-notifiers": "1.2.642",
|
|
86
84
|
"@camstack/addon-pipeline": "1.2.680",
|
|
87
85
|
"@camstack/addon-pipeline-orchestrator": "1.2.716",
|
|
88
|
-
"@camstack/addon-post-analysis": "1.2.
|
|
86
|
+
"@camstack/addon-post-analysis": "1.2.722",
|
|
89
87
|
"@camstack/develop": "0.1.56",
|
|
90
88
|
"@camstack/sdk": "1.2.160",
|
|
91
89
|
"@camstack/types": "1.2.624",
|
|
@@ -7017,6 +7017,14 @@ function createBrokerDeviceManagerApi(opts) {
|
|
|
7017
7017
|
},
|
|
7018
7018
|
create: async (stableId, DeviceClass, config, parentDeviceId = null, initialMeta = void 0) => {
|
|
7019
7019
|
const id = await deviceApi.allocateDeviceId(stableId);
|
|
7020
|
+
const existing = registry.getById(id);
|
|
7021
|
+
if (existing && existing.stableId === stableId && existing instanceof DeviceClass) {
|
|
7022
|
+
opts.logger.debug("create: already registered, returning the live instance", { tags: {
|
|
7023
|
+
stableId,
|
|
7024
|
+
deviceId: id
|
|
7025
|
+
} });
|
|
7026
|
+
return existing;
|
|
7027
|
+
}
|
|
7020
7028
|
if (initialMeta) {
|
|
7021
7029
|
if (initialMeta.name !== void 0) {
|
|
7022
7030
|
const systemName = stableId.startsWith(_camstack_types_addon.COMPOSED_DEVICE_STABLE_ID_PREFIX);
|
|
@@ -6962,6 +6962,14 @@ function createBrokerDeviceManagerApi(opts) {
|
|
|
6962
6962
|
},
|
|
6963
6963
|
create: async (stableId, DeviceClass, config, parentDeviceId = null, initialMeta = void 0) => {
|
|
6964
6964
|
const id = await deviceApi.allocateDeviceId(stableId);
|
|
6965
|
+
const existing = registry.getById(id);
|
|
6966
|
+
if (existing && existing.stableId === stableId && existing instanceof DeviceClass) {
|
|
6967
|
+
opts.logger.debug("create: already registered, returning the live instance", { tags: {
|
|
6968
|
+
stableId,
|
|
6969
|
+
deviceId: id
|
|
6970
|
+
} });
|
|
6971
|
+
return existing;
|
|
6972
|
+
}
|
|
6965
6973
|
if (initialMeta) {
|
|
6966
6974
|
if (initialMeta.name !== void 0) {
|
|
6967
6975
|
const systemName = stableId.startsWith(COMPOSED_DEVICE_STABLE_ID_PREFIX);
|
|
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
|
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
5
|
require("../../chunk-Cek0wNdY.js");
|
|
6
|
-
const require_wal_maintenance = require("../../wal-maintenance-
|
|
6
|
+
const require_wal_maintenance = require("../../wal-maintenance-DKTXQ7UF.js");
|
|
7
7
|
const require_builtins_sqlite_storage_filesystem_storage_addon = require("./filesystem-storage.addon.js");
|
|
8
8
|
const require_builtins_sqlite_storage_sqlite_settings_addon = require("./sqlite-settings.addon.js");
|
|
9
9
|
//#region src/builtins/sqlite-storage/config-store.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as SQLITE_ENGINE_STORM_WALL_SHARE, F as SQLITE_MMAP_FLOOR_BYTES, G as SqliteOpProfiler, H as SQLITE_PROFILE_REPORT_INTERVAL_MS, I as SQLITE_PAGE_CACHE_CEILING_KIB, K as sqliteEngineStorm, L as SQLITE_PAGE_CACHE_FLOOR_KIB, N as SQLITE_JOURNAL_SIZE_LIMIT_BYTES, P as SQLITE_MMAP_CEILING_BYTES, R as sqliteMmapSizeFor, U as SQLITE_PROFILE_TOP_N, V as SQLITE_PROFILE_REPORT_FLOOR_MS, W as SQLITE_SLOW_CALL_MS, a as WalMaintenance, i as WAL_MAINTENANCE_INTERVAL_MS, l as SqliteSettingsBackend, n as WAL_HIGH_WATER_BYTES, r as WAL_IDLE_QUIET_MS, t as WAL_CHECKPOINT_BUSY_TIMEOUT_MS, z as sqlitePageCacheKibFor } from "../../wal-maintenance-
|
|
1
|
+
import { B as SQLITE_ENGINE_STORM_WALL_SHARE, F as SQLITE_MMAP_FLOOR_BYTES, G as SqliteOpProfiler, H as SQLITE_PROFILE_REPORT_INTERVAL_MS, I as SQLITE_PAGE_CACHE_CEILING_KIB, K as sqliteEngineStorm, L as SQLITE_PAGE_CACHE_FLOOR_KIB, N as SQLITE_JOURNAL_SIZE_LIMIT_BYTES, P as SQLITE_MMAP_CEILING_BYTES, R as sqliteMmapSizeFor, U as SQLITE_PROFILE_TOP_N, V as SQLITE_PROFILE_REPORT_FLOOR_MS, W as SQLITE_SLOW_CALL_MS, a as WalMaintenance, i as WAL_MAINTENANCE_INTERVAL_MS, l as SqliteSettingsBackend, n as WAL_HIGH_WATER_BYTES, r as WAL_IDLE_QUIET_MS, t as WAL_CHECKPOINT_BUSY_TIMEOUT_MS, z as sqlitePageCacheKibFor } from "../../wal-maintenance-CjpslZUL.mjs";
|
|
2
2
|
import { FilesystemStorageAddon, t as FilesystemStorageProvider } from "./filesystem-storage.addon.mjs";
|
|
3
3
|
import { SqliteSettingsAddon } from "./sqlite-settings.addon.mjs";
|
|
4
4
|
//#region src/builtins/sqlite-storage/config-store.ts
|
|
@@ -174,6 +174,8 @@ export declare function sqliteOccupancy(counters: SqlitePageCounters): SqliteOcc
|
|
|
174
174
|
* 418 synchronous page-ins per second. Cheap insurance against a slow leak.
|
|
175
175
|
*/
|
|
176
176
|
export declare const MAP_GROWTH_CHECK_INTERVAL_MS: number;
|
|
177
|
+
/** The file must pass this fraction of the current map before the map is re-sized. */
|
|
178
|
+
export declare const MAP_REMAP_FILL_FRACTION = .9;
|
|
177
179
|
/**
|
|
178
180
|
* The new `mmap_size` when the file has outgrown the current one, or `null`.
|
|
179
181
|
*
|
|
@@ -2,6 +2,7 @@ import type { BulkRecord, DataStoreDatabase, DataStoreEngineInfo, DeclareCollect
|
|
|
2
2
|
import Database from "better-sqlite3";
|
|
3
3
|
import { type MutationFilterInput } from "./filter-compiler.js";
|
|
4
4
|
import { SqliteOpProfiler } from "./query-profiler.js";
|
|
5
|
+
import { type StorageRowsReader } from "./storage-report-runner.js";
|
|
5
6
|
/** How one file of the engine is opened. All optional: the defaults are `camstack.db`'s. */
|
|
6
7
|
export interface SqliteSettingsBackendOptions {
|
|
7
8
|
/** Which file this is — names it in log lines. Default `settings`. */
|
|
@@ -19,6 +20,8 @@ export interface SqliteSettingsBackendOptions {
|
|
|
19
20
|
* and a second copy of them in `events.db` would be a table nobody reads.
|
|
20
21
|
*/
|
|
21
22
|
readonly canonicalKv?: boolean;
|
|
23
|
+
/** Where the boot `dbstat` report is read. Default: a worker thread with its own read-only connection. */
|
|
24
|
+
readonly storageRows?: StorageRowsReader;
|
|
22
25
|
}
|
|
23
26
|
/** Input for {@link SqliteSettingsBackend.insertMany}. */
|
|
24
27
|
interface SettingsInsertManyInput {
|
|
@@ -6,7 +6,7 @@ const require_chunk = require("../../chunk-Cek0wNdY.js");
|
|
|
6
6
|
const require_base_addon = require("../../base-addon-DD5dIfcZ.js");
|
|
7
7
|
const require_scoped_settings = require("../../scoped-settings-CylSSq_8.js");
|
|
8
8
|
const require_record_kind = require("../../record-kind-DoBfYHCs.js");
|
|
9
|
-
const require_wal_maintenance = require("../../wal-maintenance-
|
|
9
|
+
const require_wal_maintenance = require("../../wal-maintenance-DKTXQ7UF.js");
|
|
10
10
|
const require_settings_store_cap = require("../../settings-store.cap-BhOIBtO4.js");
|
|
11
11
|
const require_migration = require("../../migration-BOQlFZCN.js");
|
|
12
12
|
const require_database_snapshot_cap = require("../../database-snapshot.cap-BNS5c60M.js");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { b as EventCategory, i as collectSecretMarkerRefs, t as BaseAddon } from "../../base-addon-Md14i7pe.mjs";
|
|
2
2
|
import { A as NoCallerError, C as normalizeSecretOwner, E as DeclarationRefusedError, L as TransactRefusedError, Z as errMsg$1, k as InvalidRecordError, v as RECORD_SWEEP_INTERVAL_MS, z as UnknownRecordKindError } from "../../scoped-settings-DVWUIP7Z.mjs";
|
|
3
3
|
import { n as RecordKindDeclarationSchema } from "../../record-kind-ub6NXqfh.mjs";
|
|
4
|
-
import { A as callRecords, D as RecordsEngine, E as databaseOfStore, M as controlTargetOf, O as callControl, T as trustResult, _ as rehydrateError, a as WalMaintenance, b as collectTransferables, c as vectorProviderOfOwnedFile, d as callMigrate, f as migrateTargetOf, g as DuplicatePlacementError, h as DatabaseBusyError, j as callVector, k as callData, l as SqliteSettingsBackend, m as CrossDatabaseTransactError, o as createVectorIndex, p as CollectionPlacementError, s as vectorProviderOf, u as HUB_MIGRATIONS, x as isFileHostMessage } from "../../wal-maintenance-
|
|
4
|
+
import { A as callRecords, D as RecordsEngine, E as databaseOfStore, M as controlTargetOf, O as callControl, T as trustResult, _ as rehydrateError, a as WalMaintenance, b as collectTransferables, c as vectorProviderOfOwnedFile, d as callMigrate, f as migrateTargetOf, g as DuplicatePlacementError, h as DatabaseBusyError, j as callVector, k as callData, l as SqliteSettingsBackend, m as CrossDatabaseTransactError, o as createVectorIndex, p as CollectionPlacementError, s as vectorProviderOf, u as HUB_MIGRATIONS, x as isFileHostMessage } from "../../wal-maintenance-CjpslZUL.mjs";
|
|
5
5
|
import { i as DATA_STORE_DATABASES } from "../../settings-store.cap-CaDSOqgK.mjs";
|
|
6
6
|
import { c as catalogueIssues, l as orderMigrations, r as MigrationMetaSchema } from "../../migration-DGAc6ywR.mjs";
|
|
7
7
|
import { a as databaseSnapshotCapability, i as DATABASE_SNAPSHOT_TIMEOUT_MS, n as DATABASE_SNAPSHOT_PARTIAL_SUFFIX, r as DATABASE_SNAPSHOT_SUFFIX } from "../../database-snapshot.cap-a3lSf4hl.mjs";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Reads the `dbstat` rows of one database file, somewhere off the serving thread. */
|
|
2
|
+
export type StorageRowsReader = (dbPath: string) => Promise<readonly unknown[]>;
|
|
3
|
+
/** `dist/storage-report-worker.js` at the package root (see `wal-checkpointer.ts`). */
|
|
4
|
+
export declare function defaultStorageReportWorkerPath(): string;
|
|
5
|
+
/** Run the report on a worker thread with its own read-only connection. */
|
|
6
|
+
export declare function readStorageRowsInWorker(workerPath?: string): StorageRowsReader;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Database from "better-sqlite3";
|
|
2
|
+
/** Page cache of the report connection (negative = KiB for SQLite). */
|
|
3
|
+
export declare const STORAGE_REPORT_CACHE_PRAGMA = -2048;
|
|
4
|
+
export declare const STORAGE_REPORT_SQL = "SELECT d.name AS name,\n COALESCE(m.tbl_name, d.name) AS tableName,\n SUM(d.pgsize) AS bytes,\n COUNT(*) AS pages,\n COALESCE(m.type, 'unknown') AS kind\n FROM dbstat d\n LEFT JOIN sqlite_master m ON m.name = d.name\n GROUP BY d.name, m.tbl_name, m.type";
|
|
5
|
+
/** What the thread is told. */
|
|
6
|
+
export interface StorageReportWorkerData {
|
|
7
|
+
readonly storageReportPath: string;
|
|
8
|
+
}
|
|
9
|
+
export type StorageReportWorkerMessage = {
|
|
10
|
+
readonly kind: "rows";
|
|
11
|
+
readonly rows: readonly unknown[];
|
|
12
|
+
} | {
|
|
13
|
+
readonly kind: "failed";
|
|
14
|
+
readonly error: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function isStorageReportWorkerData(value: unknown): value is StorageReportWorkerData;
|
|
17
|
+
/** Open the report connection: read-only, no map, a small cache. */
|
|
18
|
+
export declare function openReportConnection(livePath: string): Database.Database;
|
|
19
|
+
/** The `dbstat` rows of one file, read through {@link openReportConnection}. */
|
|
20
|
+
export declare function readStorageRows(livePath: string): unknown[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require("./chunk-Cek0wNdY.js");
|
|
2
|
-
const require_wal_maintenance = require("./wal-maintenance-
|
|
2
|
+
const require_wal_maintenance = require("./wal-maintenance-DKTXQ7UF.js");
|
|
3
3
|
let node_worker_threads = require("node:worker_threads");
|
|
4
4
|
//#region src/builtins/sqlite-storage/file-host-worker.ts
|
|
5
5
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as callRecords, C as isFileHostWorkerData, D as RecordsEngine, M as controlTargetOf, O as callControl, S as isFileHostRequest, a as WalMaintenance, b as collectTransferables, d as callMigrate, f as migrateTargetOf, j as callVector, k as callData, l as SqliteSettingsBackend, o as createVectorIndex, s as vectorProviderOf, u as HUB_MIGRATIONS, v as serializeError, w as trustInput } from "./wal-maintenance-
|
|
1
|
+
import { A as callRecords, C as isFileHostWorkerData, D as RecordsEngine, M as controlTargetOf, O as callControl, S as isFileHostRequest, a as WalMaintenance, b as collectTransferables, d as callMigrate, f as migrateTargetOf, j as callVector, k as callData, l as SqliteSettingsBackend, o as createVectorIndex, s as vectorProviderOf, u as HUB_MIGRATIONS, v as serializeError, w as trustInput } from "./wal-maintenance-CjpslZUL.mjs";
|
|
2
2
|
import { parentPort, threadId, workerData } from "node:worker_threads";
|
|
3
3
|
//#region src/builtins/sqlite-storage/file-host-worker.ts
|
|
4
4
|
/**
|
package/system/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ const require_rename_composition_block = require("./rename-composition-block-D44
|
|
|
6
6
|
const require_camstack_error = require("./camstack-error-DJ-TUAi1.js");
|
|
7
7
|
const require_capability_definition = require("./capability-definition-BEVd01Xj.js");
|
|
8
8
|
const require_record_kind = require("./record-kind-DoBfYHCs.js");
|
|
9
|
-
const require_wal_maintenance = require("./wal-maintenance-
|
|
9
|
+
const require_wal_maintenance = require("./wal-maintenance-DKTXQ7UF.js");
|
|
10
10
|
const require_device_certificate = require("./device-certificate-CguVACQO.js");
|
|
11
11
|
const require_addon_settings_cap = require("./addon-settings.cap-DrLdMFIe.js");
|
|
12
12
|
const require_prefix_walk = require("./prefix-walk-BRlQiqVg.js");
|
|
@@ -15492,6 +15492,14 @@ function createBrokerDeviceManagerApi(opts) {
|
|
|
15492
15492
|
},
|
|
15493
15493
|
create: async (stableId, DeviceClass, config, parentDeviceId = null, initialMeta = void 0) => {
|
|
15494
15494
|
const id = await deviceApi.allocateDeviceId(stableId);
|
|
15495
|
+
const existing = registry.getById(id);
|
|
15496
|
+
if (existing && existing.stableId === stableId && existing instanceof DeviceClass) {
|
|
15497
|
+
opts.logger.debug("create: already registered, returning the live instance", { tags: {
|
|
15498
|
+
stableId,
|
|
15499
|
+
deviceId: id
|
|
15500
|
+
} });
|
|
15501
|
+
return existing;
|
|
15502
|
+
}
|
|
15495
15503
|
if (initialMeta) {
|
|
15496
15504
|
if (initialMeta.name !== void 0) {
|
|
15497
15505
|
const systemName = stableId.startsWith(_camstack_types_addon.COMPOSED_DEVICE_STABLE_ID_PREFIX);
|
package/system/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { Un as lifecycleJobSchema, a as isCollectionArrayMethod, c as kebabToCam
|
|
|
5
5
|
import { t as userError } from "./camstack-error-viZYfcj9.mjs";
|
|
6
6
|
import { a as expandCapMethods, n as DEVICE_STATUS_METHOD, t as DEVICE_SETTINGS_CONTRIBUTION_METHODS, u as resolveCapMount } from "./capability-definition-C1TLUVJR.mjs";
|
|
7
7
|
import { s as defineRecordKinds } from "./record-kind-ub6NXqfh.mjs";
|
|
8
|
-
import { D as RecordsEngine, J as asNumber, X as parseJsonObject, Y as asString$1, Z as parseJsonUnknown, l as SqliteSettingsBackend, q as asJsonObject$1 } from "./wal-maintenance-
|
|
8
|
+
import { D as RecordsEngine, J as asNumber, X as parseJsonObject, Y as asString$1, Z as parseJsonUnknown, l as SqliteSettingsBackend, q as asJsonObject$1 } from "./wal-maintenance-CjpslZUL.mjs";
|
|
9
9
|
import { f as AppPageLangSchema } from "./device-certificate-Cddm4Idn.mjs";
|
|
10
10
|
import { i as addonSettingsCapability } from "./addon-settings.cap-CZ4MC7ha.mjs";
|
|
11
11
|
import { t as loadPrefixed } from "./prefix-walk-BrrMuJBM.mjs";
|
|
@@ -15488,6 +15488,14 @@ function createBrokerDeviceManagerApi(opts) {
|
|
|
15488
15488
|
},
|
|
15489
15489
|
create: async (stableId, DeviceClass, config, parentDeviceId = null, initialMeta = void 0) => {
|
|
15490
15490
|
const id = await deviceApi.allocateDeviceId(stableId);
|
|
15491
|
+
const existing = registry.getById(id);
|
|
15492
|
+
if (existing && existing.stableId === stableId && existing instanceof DeviceClass) {
|
|
15493
|
+
opts.logger.debug("create: already registered, returning the live instance", { tags: {
|
|
15494
|
+
stableId,
|
|
15495
|
+
deviceId: id
|
|
15496
|
+
} });
|
|
15497
|
+
return existing;
|
|
15498
|
+
}
|
|
15491
15499
|
if (initialMeta) {
|
|
15492
15500
|
if (initialMeta.name !== void 0) {
|
|
15493
15501
|
const systemName = stableId.startsWith(COMPOSED_DEVICE_STABLE_ID_PREFIX);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_chunk = require("./chunk-Cek0wNdY.js");
|
|
3
|
+
let node_worker_threads = require("node:worker_threads");
|
|
4
|
+
let better_sqlite3 = require("better-sqlite3");
|
|
5
|
+
better_sqlite3 = require_chunk.__toESM(better_sqlite3);
|
|
6
|
+
//#region src/builtins/sqlite-storage/storage-report-worker.ts
|
|
7
|
+
/**
|
|
8
|
+
* The storage-report worker — a thread of the process that OWNS a database,
|
|
9
|
+
* whose one job is the `dbstat` aggregate behind the boot "biggest tables" line.
|
|
10
|
+
*
|
|
11
|
+
* `dbstat` reads EVERY page of the file. On the serving connection, whose
|
|
12
|
+
* `mmap_size` covers the whole file, that made every page resident in the
|
|
13
|
+
* runner (events.db 1.9 GiB + history.db 1 GiB: a ~3.5 GB RSS spike a minute
|
|
14
|
+
* after boot, decaying over ~20 minutes). Here it runs on its OWN read-only
|
|
15
|
+
* connection with the map off and a small page cache — the same footing as the
|
|
16
|
+
* snapshot worker (D693 §1: a read-only connection opened by the owner, D679),
|
|
17
|
+
* and off the serving thread, because the scan is long and synchronous.
|
|
18
|
+
*
|
|
19
|
+
* A worker entry is a separate bundle (`dist/storage-report-worker.js`, wired in
|
|
20
|
+
* `vite.config.ts`). {@link readStorageRows} is exported so a spec can drive it
|
|
21
|
+
* in-process; the thread body runs only when this module is loaded AS the thread.
|
|
22
|
+
*/
|
|
23
|
+
/** Page cache of the report connection (negative = KiB for SQLite). */
|
|
24
|
+
var STORAGE_REPORT_CACHE_PRAGMA = -2048;
|
|
25
|
+
var STORAGE_REPORT_SQL = `SELECT d.name AS name,
|
|
26
|
+
COALESCE(m.tbl_name, d.name) AS tableName,
|
|
27
|
+
SUM(d.pgsize) AS bytes,
|
|
28
|
+
COUNT(*) AS pages,
|
|
29
|
+
COALESCE(m.type, 'unknown') AS kind
|
|
30
|
+
FROM dbstat d
|
|
31
|
+
LEFT JOIN sqlite_master m ON m.name = d.name
|
|
32
|
+
GROUP BY d.name, m.tbl_name, m.type`;
|
|
33
|
+
function isStorageReportWorkerData(value) {
|
|
34
|
+
return typeof value === "object" && value !== null && "storageReportPath" in value && typeof value.storageReportPath === "string";
|
|
35
|
+
}
|
|
36
|
+
/** Open the report connection: read-only, no map, a small cache. */
|
|
37
|
+
function openReportConnection(livePath) {
|
|
38
|
+
const db = new better_sqlite3.default(livePath, { readonly: true });
|
|
39
|
+
db.pragma(`cache_size = ${STORAGE_REPORT_CACHE_PRAGMA}`);
|
|
40
|
+
db.pragma("mmap_size = 0");
|
|
41
|
+
db.pragma("busy_timeout = 5000");
|
|
42
|
+
return db;
|
|
43
|
+
}
|
|
44
|
+
/** The `dbstat` rows of one file, read through {@link openReportConnection}. */
|
|
45
|
+
function readStorageRows(livePath) {
|
|
46
|
+
const db = openReportConnection(livePath);
|
|
47
|
+
try {
|
|
48
|
+
return db.prepare(STORAGE_REPORT_SQL).all();
|
|
49
|
+
} finally {
|
|
50
|
+
db.close();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function run(data) {
|
|
54
|
+
const port = node_worker_threads.parentPort;
|
|
55
|
+
if (port === null) throw new Error("storage-report-worker: no parent port");
|
|
56
|
+
let message;
|
|
57
|
+
try {
|
|
58
|
+
message = {
|
|
59
|
+
kind: "rows",
|
|
60
|
+
rows: readStorageRows(data.storageReportPath)
|
|
61
|
+
};
|
|
62
|
+
} catch (err) {
|
|
63
|
+
message = {
|
|
64
|
+
kind: "failed",
|
|
65
|
+
error: err instanceof Error ? err.message : String(err)
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
port.postMessage(message);
|
|
69
|
+
port.close();
|
|
70
|
+
}
|
|
71
|
+
if (!node_worker_threads.isMainThread && isStorageReportWorkerData(node_worker_threads.workerData)) run(node_worker_threads.workerData);
|
|
72
|
+
//#endregion
|
|
73
|
+
exports.STORAGE_REPORT_CACHE_PRAGMA = STORAGE_REPORT_CACHE_PRAGMA;
|
|
74
|
+
exports.STORAGE_REPORT_SQL = STORAGE_REPORT_SQL;
|
|
75
|
+
exports.isStorageReportWorkerData = isStorageReportWorkerData;
|
|
76
|
+
exports.openReportConnection = openReportConnection;
|
|
77
|
+
exports.readStorageRows = readStorageRows;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { isMainThread, parentPort, workerData } from "node:worker_threads";
|
|
2
|
+
import Database from "better-sqlite3";
|
|
3
|
+
//#region src/builtins/sqlite-storage/storage-report-worker.ts
|
|
4
|
+
/**
|
|
5
|
+
* The storage-report worker — a thread of the process that OWNS a database,
|
|
6
|
+
* whose one job is the `dbstat` aggregate behind the boot "biggest tables" line.
|
|
7
|
+
*
|
|
8
|
+
* `dbstat` reads EVERY page of the file. On the serving connection, whose
|
|
9
|
+
* `mmap_size` covers the whole file, that made every page resident in the
|
|
10
|
+
* runner (events.db 1.9 GiB + history.db 1 GiB: a ~3.5 GB RSS spike a minute
|
|
11
|
+
* after boot, decaying over ~20 minutes). Here it runs on its OWN read-only
|
|
12
|
+
* connection with the map off and a small page cache — the same footing as the
|
|
13
|
+
* snapshot worker (D693 §1: a read-only connection opened by the owner, D679),
|
|
14
|
+
* and off the serving thread, because the scan is long and synchronous.
|
|
15
|
+
*
|
|
16
|
+
* A worker entry is a separate bundle (`dist/storage-report-worker.js`, wired in
|
|
17
|
+
* `vite.config.ts`). {@link readStorageRows} is exported so a spec can drive it
|
|
18
|
+
* in-process; the thread body runs only when this module is loaded AS the thread.
|
|
19
|
+
*/
|
|
20
|
+
/** Page cache of the report connection (negative = KiB for SQLite). */
|
|
21
|
+
var STORAGE_REPORT_CACHE_PRAGMA = -2048;
|
|
22
|
+
var STORAGE_REPORT_SQL = `SELECT d.name AS name,
|
|
23
|
+
COALESCE(m.tbl_name, d.name) AS tableName,
|
|
24
|
+
SUM(d.pgsize) AS bytes,
|
|
25
|
+
COUNT(*) AS pages,
|
|
26
|
+
COALESCE(m.type, 'unknown') AS kind
|
|
27
|
+
FROM dbstat d
|
|
28
|
+
LEFT JOIN sqlite_master m ON m.name = d.name
|
|
29
|
+
GROUP BY d.name, m.tbl_name, m.type`;
|
|
30
|
+
function isStorageReportWorkerData(value) {
|
|
31
|
+
return typeof value === "object" && value !== null && "storageReportPath" in value && typeof value.storageReportPath === "string";
|
|
32
|
+
}
|
|
33
|
+
/** Open the report connection: read-only, no map, a small cache. */
|
|
34
|
+
function openReportConnection(livePath) {
|
|
35
|
+
const db = new Database(livePath, { readonly: true });
|
|
36
|
+
db.pragma(`cache_size = ${STORAGE_REPORT_CACHE_PRAGMA}`);
|
|
37
|
+
db.pragma("mmap_size = 0");
|
|
38
|
+
db.pragma("busy_timeout = 5000");
|
|
39
|
+
return db;
|
|
40
|
+
}
|
|
41
|
+
/** The `dbstat` rows of one file, read through {@link openReportConnection}. */
|
|
42
|
+
function readStorageRows(livePath) {
|
|
43
|
+
const db = openReportConnection(livePath);
|
|
44
|
+
try {
|
|
45
|
+
return db.prepare(STORAGE_REPORT_SQL).all();
|
|
46
|
+
} finally {
|
|
47
|
+
db.close();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function run(data) {
|
|
51
|
+
const port = parentPort;
|
|
52
|
+
if (port === null) throw new Error("storage-report-worker: no parent port");
|
|
53
|
+
let message;
|
|
54
|
+
try {
|
|
55
|
+
message = {
|
|
56
|
+
kind: "rows",
|
|
57
|
+
rows: readStorageRows(data.storageReportPath)
|
|
58
|
+
};
|
|
59
|
+
} catch (err) {
|
|
60
|
+
message = {
|
|
61
|
+
kind: "failed",
|
|
62
|
+
error: err instanceof Error ? err.message : String(err)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
port.postMessage(message);
|
|
66
|
+
port.close();
|
|
67
|
+
}
|
|
68
|
+
if (!isMainThread && isStorageReportWorkerData(workerData)) run(workerData);
|
|
69
|
+
//#endregion
|
|
70
|
+
export { STORAGE_REPORT_CACHE_PRAGMA, STORAGE_REPORT_SQL, isStorageReportWorkerData, openReportConnection, readStorageRows };
|
|
Binary file
|
|
Binary file
|