Files
MarkLite/.tscheck/flushkill.mjs
T
thzxx 58c8a1a3a0 fix: 关闭应用前干净关闭数据库 + 自愈仅启动早期触发
- 退出前 db.close() 确保 WAL/SSTable 干净落盘,避免渲染进程销毁时 flush 中断留下半写文件导致下次启动损坏
- 自愈(删损坏库/重载)仅限页面生命周期内首次初始化;运行中失败直接抛错,不再阻塞应用关闭流程
2026-08-09 17:05:31 +08:00

29 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'fake-indexeddb/auto'
import { AriaEngine } from '/mnt/d/CodeWorkspace/MarkLite/node_modules/@metona-team/metona-sqlark/dist/metona-sqlark.esm.js'
// 小 memtable 阈值 → 频繁 flush → 多个 SSTable + WAL
const engine1 = new AriaEngine({ storageBackend: 'indexeddb', memtableSizeThreshold: 4096, walEnabled: true })
await engine1.open('flushkill-test', 1)
await engine1.createTable({ name: 't', columns: { id: { type: 'string', primaryKey: true }, v: { type: 'number' } } })
// 写入大量数据触发多次 flush(写 WAL + 刷 SSTable
for (let i = 0; i < 3000; i++) {
await engine1.insert('t', [{ id: `k${i}`, v: i }])
}
console.log('S1 wrote 3000 rows')
// 不 close!直接丢弃实例(模拟应用被强制关闭/渲染进程被销毁)
// 重新打开同库
const engine2 = new AriaEngine({ storageBackend: 'indexeddb', memtableSizeThreshold: 4096, walEnabled: true })
await engine2.open('flushkill-test', 1)
const tables = await engine2.getTableNames()
console.log('S2 tables:', JSON.stringify(tables))
if (tables.includes('t')) {
const rows = await engine2.find('t', { limit: 5 })
console.log('S2 sample rows:', JSON.stringify(rows))
console.log('REOPEN OK')
} else {
console.log('TABLE LOST')
}
await engine2.close()