关键修复: rename覆盖快照后旧连接仍读旧inode导致数据陈旧(今日永远0), 快照后重开数据库连接
This commit is contained in:
@@ -76,8 +76,10 @@ function makeSnapshot() {
|
||||
src.exec(`VACUUM INTO '${tmp}'`);
|
||||
src.close();
|
||||
fs.renameSync(tmp, SNAP_PATH);
|
||||
try { rdb.close(); } catch (_) {}
|
||||
rdb = new Database(SNAP_PATH, { readonly: true });
|
||||
snapshotAt = new Date().toISOString();
|
||||
console.log(`[snapshot] ok ${snapshotAt}`);
|
||||
console.log(`[snapshot] ok ${snapshotAt} (reopened)`);
|
||||
} catch (e) {
|
||||
console.log(`[snapshot] failed(继续用旧快照): ${String(e.message).slice(0, 120)}`);
|
||||
}
|
||||
@@ -88,7 +90,9 @@ if (RECRUITMENT_SRC) {
|
||||
} else {
|
||||
snapshotAt = fs.existsSync(SNAP_PATH) ? fs.statSync(SNAP_PATH).mtime.toISOString() : null;
|
||||
}
|
||||
const rdb = new Database(SNAP_PATH, { readonly: true });
|
||||
let rdb = new Database(SNAP_PATH, { readonly: true });
|
||||
// 注意: makeSnapshot 用 rename 覆盖快照文件后, 已打开的连接仍指向旧 inode(读到陈旧数据),
|
||||
// 必须在每次快照后重开连接(rdb 为 let 就是为此)。
|
||||
|
||||
// ---------- 会话(内存态,重启需重登) ----------
|
||||
const sessions = new Map(); // sid -> { uid, role, expires }
|
||||
|
||||
Reference in New Issue
Block a user