fix(server): keep writes moving while readers pin the WAL#23496
0 / 2 viewed2 files changedLine totals unavailable
packages/shared/src/nodeSqliteClient.ts · Earlier revision 48b7d20a · right 555
Original diff
@@ -538,38 +541,38 @@ const check = (id, nextJournalSizeLimit, force, nextGeneration = generation) =>
});
return;
}
- const blocked = (atCeiling(state) || oversized) && state.checkpointed < state.log;
+ const blocked = !pinned && (atCeiling(state) || oversized) && state.checkpointed < state.log;
parentPort.postMessage({ type: "checkpoint", id, generation, ...state, blocked });
schedule(state, blocked);
};
const finishTruncate = (truncateId) => {
if (pendingTruncate === undefined || pendingTruncate.truncateId !== truncateId) return;
const pending = pendingTruncate;
parentPort.postMessage({ type: "truncate-start", truncateId });
- let busy;
// Admission is paused here; a pinned reader must not make truncation wait.
db.exec("PRAGMA busy_timeout = 0;");
try {
- busy = truncate.get().busy !== 0;
+ truncate.get();packages/shared/src/nodeSqliteClient.ts · Earlier revision 48b7d20a · right 530
Original diff
@@ -523,8 +523,11 @@ const check = (id, nextJournalSizeLimit, force, nextGeneration = generation) =>
if (Number.isSafeInteger(nextJournalSizeLimit)) journalSizeLimit = nextJournalSizeLimit;
let state = frames.get();
const oversized = exceedsSizeLimit();
+ let pinned = false;
if (force || state.log - state.checkpointed >= workerData.frames || oversized) {
- checkpoint.get();
+ const result = checkpoint.get();
+ // A reader's snapshot stopped the backfill; holding writes cannot let it catch up.
+ pinned = result.checkpointed < result.log;