release: v0.2.5 — 质量加固 + Bug修复 + 性能优化 + SQL扩展
CI / test (18.x) (push) Successful in 10m4s
CI / test (20.x) (push) Successful in 10m0s
CI / test (22.x) (push) Successful in 9m58s
CI / test (24.x) (push) Successful in 9m58s

This commit is contained in:
thzxx
2026-07-29 21:50:53 +08:00
parent 29d779d96a
commit eb79b2198e
34 changed files with 2017 additions and 298 deletions
+23 -13
View File
@@ -2,7 +2,7 @@
* AriaEngine — 自研页面式存储引擎主类
* @module engine/aria/index
*
* v0.2.4: 二级索引 + MVCC 集成 + 生产加固
* v0.2.5: WAL 同步修复 + MVCC 接入 + 版本统一 + 生产加固
*/
import type { IStorageEngine } from '../interface';
@@ -27,6 +27,7 @@ import { BloomFilter } from './index/bloom';
import { BufferPool } from './buffer/pool';
import { compressLZ4, decompressLZ4 } from './compression/lz4';
import { isCryptoEnabled, encryptPage, decryptPage } from './crypto';
import type { WALRecord as _WALRecord } from './types';
// ---------------------------------------------------------------------------
// AriaEngine
@@ -163,12 +164,13 @@ export class AriaEngine implements IStorageEngine {
}
}
// 8. Checkpoint ManagerBufferPool 暂简化,使用 flush 替代
// 8. Checkpoint Manager接入 WAL 大小阈值
this.checkpointManager = new CheckpointManager(
this.lsm,
this.wal,
{ flushAll: async () => { await this.lsm.flush(); } } as any,
this.config.checkpointInterval,
this.config.walSizeThreshold,
);
this.opened = true;
@@ -220,7 +222,7 @@ export class AriaEngine implements IStorageEngine {
await this.persistSchemas();
this.wal.append({
await this.wal.append({
type: WALRecordType.CREATE_TABLE,
txnId: 0,
tableName: schema.name,
@@ -244,7 +246,7 @@ export class AriaEngine implements IStorageEngine {
this.tablePKs.delete(tableName);
await this.persistSchemas();
this.wal.append({
await this.wal.append({
type: WALRecordType.DROP_TABLE,
txnId: 0,
tableName,
@@ -293,8 +295,9 @@ export class AriaEngine implements IStorageEngine {
}
if (this.currentTxnId && this.txnSnapshot) {
// Within transaction: buffer to snapshot
// Within transaction: buffer to snapshot + MVCC version chain
this.txnSnapshot.set(key, validated);
this.mvcc.writeVersion(tableName, pkValue, validated, this.currentTxnId);
} else {
// Direct write to LSM (PK index)
this.lsm.put(key, validated);
@@ -305,7 +308,7 @@ export class AriaEngine implements IStorageEngine {
pks.push(pkValue);
this.wal.append({
await this.wal.append({
type: WALRecordType.INSERT,
txnId: this.currentTxnId ?? 0,
tableName,
@@ -399,12 +402,13 @@ export class AriaEngine implements IStorageEngine {
if (this.currentTxnId && this.txnSnapshot) {
this.txnSnapshot.set(key, updated);
this.mvcc.writeVersion(tableName, String(row[pkCol]), updated, this.currentTxnId);
} else {
this.lsm.put(key, updated);
}
count++;
this.wal.append({
await this.wal.append({
type: WALRecordType.UPDATE,
txnId: this.currentTxnId ?? 0,
tableName,
@@ -435,14 +439,15 @@ export class AriaEngine implements IStorageEngine {
if (!query.where || Object.keys(query.where).length === 0 || matchWhere(row, query.where)) {
if (this.currentTxnId && this.txnSnapshot) {
// Buffer delete in snapshot
// Buffer delete in snapshot + MVCC tombstone
this.txnSnapshot.set(key, { __txn_deleted: true } as unknown as Record<string, unknown>);
this.mvcc.deleteVersion(tableName, String(row[pkCol]), this.currentTxnId);
} else {
this.lsm.delete(key);
}
count++;
this.wal.append({
await this.wal.append({
type: WALRecordType.DELETE,
txnId: this.currentTxnId ?? 0,
tableName,
@@ -486,7 +491,7 @@ export class AriaEngine implements IStorageEngine {
this.currentTxnId = this.mvcc.beginTransaction();
this.txnSnapshot = new Map();
this.wal.append({
await this.wal.append({
type: WALRecordType.BEGIN,
txnId: this.currentTxnId,
tableName: '',
@@ -509,7 +514,7 @@ export class AriaEngine implements IStorageEngine {
this.mvcc.commitTransaction(this.currentTxnId);
this.wal.append({
await this.wal.append({
type: WALRecordType.COMMIT,
txnId: this.currentTxnId,
tableName: '',
@@ -527,7 +532,7 @@ export class AriaEngine implements IStorageEngine {
this.mvcc.rollbackTransaction(this.currentTxnId);
this.txnSnapshot = null;
this.wal.append({
await this.wal.append({
type: WALRecordType.ROLLBACK,
txnId: this.currentTxnId,
tableName: '',
@@ -922,6 +927,11 @@ export class AriaEngine implements IStorageEngine {
}
}
/** 估算 WAL 大小(字节) */
getWALEstimatedSize(): number {
return this.wal.getBufferedCount() * 200; // 粗略估算每条 ~200B
}
/**
* ANALYZE: 收集表统计信息
* 返回行数、平均行大小、索引深度等
@@ -997,7 +1007,7 @@ export class AriaEngine implements IStorageEngine {
// 压缩各层级
for (let level = 0; level < 6; level++) {
if (this.lsm.getStats().levelCounts[level] >= 2) {
(this.lsm as any).compactLevelSync(level);
this.lsm.compactLevel(level);
}
}
// GC MVCC 版本(保留最新 10 个)