fix(server): make SQLite checkpoints durable on macOS (#19304)
Co-authored-by: Soroush Baraouf <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
4 files changed
+36
No files matched your search
@@ -75,6 +75,25 @@ it.layer(NodeServices.layer)("t3-sqlite-state", (it) => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("enables checkpoint_fullfsync on its direct connection", () =>
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-sqlite-state-fsync-" });
|
||||
yield* createFixtureDatabase(baseDir);
|
||||
|
||||
const result = yield* runSqliteState({
|
||||
operation: "query",
|
||||
baseDir,
|
||||
sql: "PRAGMA checkpoint_fullfsync",
|
||||
});
|
||||
|
||||
assert.equal(result.operation, "query");
|
||||
if (result.operation === "query") {
|
||||
assert.deepStrictEqual(result.rows, [{ checkpoint_fullfsync: 1 }]);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect.skipIf(!symlinksSupported)(
|
||||
"backs up isolated state before writes and refuses the shared home",
|
||||
() =>
|
||||
|
||||
@@ -201,6 +201,9 @@ export const runSqliteState = Effect.fn("runSqliteState")(function* (
|
||||
const program = Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
yield* sql.unsafe("PRAGMA busy_timeout = 5000").unprepared;
|
||||
// This connection bypasses persistence/Sqlite.ts and can checkpoint
|
||||
// statev2.sqlite, so it needs the same F_FULLFSYNC checkpoint barrier.
|
||||
yield* sql.unsafe("PRAGMA checkpoint_fullfsync = ON").unprepared;
|
||||
|
||||
if (input.operation === "query") {
|
||||
const rows = yield* sql.unsafe<RawSqliteRow>(source).unprepared.pipe(
|
||||
|
||||
@@ -136,3 +136,13 @@ it.effect("applies busy_timeout in the shared persistence setup", () =>
|
||||
assert.equal(rows[0]?.timeout, 5000);
|
||||
}).pipe(Effect.provide(SqlitePersistence.layerMemory)),
|
||||
);
|
||||
|
||||
it.effect("enables checkpoint_fullfsync in the shared persistence setup", () =>
|
||||
Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
const rows = yield* sql<{
|
||||
readonly checkpoint_fullfsync: number;
|
||||
}>`PRAGMA checkpoint_fullfsync`;
|
||||
assert.equal(rows[0]?.checkpoint_fullfsync, 1);
|
||||
}).pipe(Effect.provide(SqlitePersistence.layerMemory)),
|
||||
);
|
||||
@@ -25,6 +25,10 @@ const layerSetup = Layer.effectDiscard(
|
||||
// cannot corrupt the database and an app crash loses nothing; an OS crash
|
||||
// or power loss can roll back commits since the last checkpoint.
|
||||
yield* sql`PRAGMA synchronous = NORMAL;`;
|
||||
// Checkpoints are now the only sync, and macOS fsync() does not flush the
|
||||
// drive cache. F_FULLFSYNC makes them reach disk; other platforms ignore it.
|
||||
// Per-commit fullfsync stays off.
|
||||
yield* sql`PRAGMA checkpoint_fullfsync = ON;`;
|
||||
// PASSIVE checkpoints never shrink the -wal file, so it otherwise keeps its
|
||||
// largest size until the last connection closes.
|
||||
yield* sql.unsafe(`PRAGMA journal_size_limit = ${WAL_SIZE_LIMIT_BYTES};`);
|
||||
|
||||
Reference in new issue
Block a user