chore: 移除误提交的临时测试脚本
This commit is contained in:
@@ -1,34 +0,0 @@
|
|||||||
import 'fake-indexeddb/auto'
|
|
||||||
import { create } from '/mnt/d/CodeWorkspace/MarkLite/node_modules/@metona-team/metona-sqlark/dist/metona-sqlark.esm.js'
|
|
||||||
|
|
||||||
const DB = 'aria-corrupt-test'
|
|
||||||
|
|
||||||
// 1. 正常建库写数据
|
|
||||||
const db1 = await create({ name: 'corrupt-test', mode: 'aria', diskEngine: 'indexeddb', version: 0 })
|
|
||||||
await db1.defineTable('recentFiles', { filePath: { type: 'string', primaryKey: true }, lastOpened: { type: 'number' } })
|
|
||||||
await db1.table('recentFiles').insert({ filePath: '/a.md', lastOpened: 1 })
|
|
||||||
await db1.close()
|
|
||||||
|
|
||||||
// 2. 模拟异常退出留下的残缺 SSTable 页面:直接往 IDB 写一个 10 字节的 pg_ 文件
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
const req = indexedDB.open(DB, 1)
|
|
||||||
req.onsuccess = () => {
|
|
||||||
const idb = req.result
|
|
||||||
const tx = idb.transaction('data', 'readwrite')
|
|
||||||
tx.objectStore('data').put(new ArrayBuffer(10), 'pg_1') // 残缺页面(正常 4096 字节)
|
|
||||||
tx.oncomplete = () => { idb.close(); resolve() }
|
|
||||||
tx.onerror = () => reject(tx.error)
|
|
||||||
}
|
|
||||||
req.onerror = () => reject(req.error)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 3. 重新打开 → 应该抛 offset is out of bounds
|
|
||||||
try {
|
|
||||||
const db2 = await create({ name: 'corrupt-test', mode: 'aria', diskEngine: 'indexeddb', version: 0 })
|
|
||||||
const rows = await db2.table('recentFiles').select().execute()
|
|
||||||
console.log('S2 opened OK, rows:', JSON.stringify(rows))
|
|
||||||
await db2.close()
|
|
||||||
console.log('NO ERROR — 未能复现')
|
|
||||||
} catch (e) {
|
|
||||||
console.log('REPRODUCED:', e.constructor.name, '|', e.message)
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
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()
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
import 'fake-indexeddb/auto'
|
|
||||||
import { create } from '/mnt/d/CodeWorkspace/MarkLite/node_modules/@metona-team/metona-sqlark/dist/metona-sqlark.esm.js'
|
|
||||||
|
|
||||||
const DB = 'aria-heal-test'
|
|
||||||
|
|
||||||
// 1. 正常建库写数据
|
|
||||||
const db1 = await create({ name: 'heal-test', mode: 'aria', diskEngine: 'indexeddb', version: 0 })
|
|
||||||
await db1.defineTable('recentFiles', { filePath: { type: 'string', primaryKey: true }, lastOpened: { type: 'number' } })
|
|
||||||
await db1.table('recentFiles').insert({ filePath: '/a.md', lastOpened: 1 })
|
|
||||||
await db1.close()
|
|
||||||
|
|
||||||
// 2. 制造损坏:写一个 footer 声称块偏移在 100000 的残缺 sst 文件(data store 里直接塞坏数据)
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
const req = indexedDB.open(DB, 1)
|
|
||||||
req.onsuccess = () => {
|
|
||||||
const idb = req.result
|
|
||||||
const tx = idb.transaction('data', 'readwrite')
|
|
||||||
const store = tx.objectStore('data')
|
|
||||||
// 残缺 sst:8 字节(正常是 4096 块),meta 记录会声称偏移 4096+
|
|
||||||
store.put(new ArrayBuffer(8), 'sst_1')
|
|
||||||
tx.oncomplete = () => { idb.close(); resolve() }
|
|
||||||
tx.onerror = () => reject(tx.error)
|
|
||||||
}
|
|
||||||
req.onerror = () => reject(req.error)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 3. 删除损坏库(模拟自愈,无活动连接时应该成功)
|
|
||||||
await new Promise((resolve) => {
|
|
||||||
const req = indexedDB.deleteDatabase(DB)
|
|
||||||
req.onsuccess = () => { console.log('deleteDatabase OK'); resolve() }
|
|
||||||
req.onerror = () => { console.log('deleteDatabase error'); resolve() }
|
|
||||||
req.onblocked = () => { console.log('deleteDatabase BLOCKED'); resolve() }
|
|
||||||
})
|
|
||||||
|
|
||||||
// 4. 重建库成功
|
|
||||||
const db2 = await create({ name: 'heal-test', mode: 'aria', diskEngine: 'indexeddb', version: 0 })
|
|
||||||
await db2.defineTable('recentFiles', { filePath: { type: 'string', primaryKey: true }, lastOpened: { type: 'number' } })
|
|
||||||
await db2.table('recentFiles').insert({ filePath: '/new.md', lastOpened: 2 })
|
|
||||||
console.log('rebuilt rows:', JSON.stringify(await db2.table('recentFiles').select().execute()))
|
|
||||||
await db2.close()
|
|
||||||
console.log('HEAL OK')
|
|
||||||
Reference in New Issue
Block a user