fix: v0.2.3 OPFS数据恢复 + Aria WAL事务边界修复
CI / test (18.x) (push) Successful in 9m58s
CI / test (22.x) (push) Successful in 9m54s
CI / test (20.x) (push) Successful in 10m0s
CI / test (24.x) (push) Successful in 9m52s

This commit is contained in:
thzxx
2026-07-27 21:30:35 +08:00
parent 4a3feac9ea
commit 2493209611
11 changed files with 224 additions and 22 deletions
+16 -2
View File
@@ -133,8 +133,21 @@ export class AriaEngine implements IStorageEngine {
// 6. 初始化 LSM(加载 SSTable 元数据)
await this.lsm.init();
// 7. WAL 恢复(恢复未刷盘的数据
await this.wal.recover((record) => this.applyWALRecord(record));
// 7. WAL 恢复(两阶段:先扫描事务边界,仅回放已提交事务
const committedTxns = new Set<number>();
const allRecords: WALRecord[] = [];
await this.wal.recover((r) => allRecords.push(r));
// 第一遍:确定已提交事务
for (const r of allRecords) {
if (r.type === WALRecordType.COMMIT) committedTxns.add(r.txnId);
if (r.type === WALRecordType.ROLLBACK) committedTxns.delete(r.txnId);
}
// 第二遍:仅应用 txnId==0(非事务)或已提交事务的数据
for (const r of allRecords) {
if (r.txnId === 0 || committedTxns.has(r.txnId)) {
this.applyWALRecord(r);
}
}
// 8. Checkpoint ManagerBufferPool 暂简化,使用 flush 替代)
this.checkpointManager = new CheckpointManager(
@@ -668,6 +681,7 @@ export class AriaEngine implements IStorageEngine {
case WALRecordType.COMMIT:
case WALRecordType.ROLLBACK:
case WALRecordType.BEGIN:
case WALRecordType.DROP_TABLE:
break;
}
}