fix(gsd): disable db mmap on darwin (#4029)

This commit is contained in:
mastertyko 2026-04-13 12:48:49 +02:00 committed by GitHub
parent df4e8245df
commit 7a7683488f
2 changed files with 31 additions and 1 deletions

View file

@ -169,7 +169,7 @@ function initSchema(db: DbAdapter, fileBacked: boolean): void {
if (fileBacked) db.exec("PRAGMA synchronous = NORMAL");
if (fileBacked) db.exec("PRAGMA auto_vacuum = INCREMENTAL");
if (fileBacked) db.exec("PRAGMA cache_size = -8000"); // 8 MB page cache
if (fileBacked) db.exec("PRAGMA mmap_size = 67108864"); // 64 MB mmap
if (fileBacked && process.platform !== "darwin") db.exec("PRAGMA mmap_size = 67108864"); // 64 MB mmap
db.exec("PRAGMA temp_store = MEMORY");
db.exec("PRAGMA foreign_keys = ON");

View file

@ -43,6 +43,16 @@ function cleanup(dbPath: string): void {
}
}
function withPlatform<T>(platform: NodeJS.Platform, fn: () => T): T {
const original = process.platform;
Object.defineProperty(process, 'platform', { value: platform });
try {
return fn();
} finally {
Object.defineProperty(process, 'platform', { value: original });
}
}
// ═══════════════════════════════════════════════════════════════════════════
// gsd-db tests
// ═══════════════════════════════════════════════════════════════════════════
@ -279,6 +289,26 @@ describe('gsd-db', () => {
cleanup(dbPath);
});
test('gsd-db: mmap stays disabled on darwin file-backed DBs', () => {
const darwinDbPath = tempDbPath();
withPlatform('darwin', () => {
openDatabase(darwinDbPath);
const adapter = _getAdapter()!;
const mmap = adapter.prepare('PRAGMA mmap_size').get();
assert.deepStrictEqual(mmap?.['mmap_size'], 0, 'darwin should leave mmap_size disabled');
cleanup(darwinDbPath);
});
const linuxDbPath = tempDbPath();
withPlatform('linux', () => {
openDatabase(linuxDbPath);
const adapter = _getAdapter()!;
const mmap = adapter.prepare('PRAGMA mmap_size').get();
assert.deepStrictEqual(mmap?.['mmap_size'], 67108864, 'non-darwin should still enable mmap_size');
cleanup(linuxDbPath);
});
});
test('gsd-db: transaction rollback on error', () => {
openDatabase(':memory:');