fix: v0.7.2 语句级原子性 + 事务 DDL 拒绝 + 约束/绑定硬化 — 6 项修复 + 43 回归 + CI 重型套件串行
- UPDATE 语句级部分提交(P1,四引擎):两阶段全量预检后执行,批内唯一互查, 任何一行失败整句不执行(aria 场景 WAL 与内存不再错位) - 事务内 ALTER/CREATE INDEX/DROP INDEX 残留(P1):Memory/KVStore 显式拒绝 (对齐 Aria),createTable/dropTable 保持可回滚 - SET NULL 级联绕过 required 约束(P1):预检阶段整体拒绝 FOREIGN_KEY_VIOLATION - bindParameters 注释误判(P2):行注释/块注释中的 ? 与引号不再参与绑定 - 未闭合字符串静默接受 → lexer 抛 PARSE_ERROR;未知 where 操作符抛 QUERY_ERROR - UPDATE undefined 覆盖列值 → 语义化为不更新(null 仍置空) - Hybrid 写穿透非原子(P1):磁盘失败自动重载内存对齐磁盘再抛原错误 - CI:Run tests 拆常规并行 + 重型串行(runInBand),重型测试超时余量提升, 性能护栏 kv 120→240s / opfs 150→300s(仍拦截悬崖回归) - 测试 1155 → 1198(74 套件),覆盖率 89.82% 保持
This commit is contained in:
+70
-16
@@ -140,12 +140,20 @@ export class HybridEngine implements IStorageEngine {
|
||||
|
||||
async createTable(schema: TableSchema): Promise<void> {
|
||||
await this.memoryEngine.createTable(schema);
|
||||
await this.diskEngine.createTable(schema);
|
||||
try {
|
||||
await this.diskEngine.createTable(schema);
|
||||
} catch (error) {
|
||||
await this.recoverMemoryAfterDiskError(error);
|
||||
}
|
||||
}
|
||||
|
||||
async dropTable(tableName: string): Promise<void> {
|
||||
await this.memoryEngine.dropTable(tableName);
|
||||
await this.diskEngine.dropTable(tableName);
|
||||
try {
|
||||
await this.diskEngine.dropTable(tableName);
|
||||
} catch (error) {
|
||||
await this.recoverMemoryAfterDiskError(error);
|
||||
}
|
||||
}
|
||||
|
||||
async hasTable(tableName: string): Promise<boolean> {
|
||||
@@ -167,21 +175,47 @@ export class HybridEngine implements IStorageEngine {
|
||||
column: import('../constants').ColumnDef & { name: string },
|
||||
): Promise<void> {
|
||||
await this.memoryEngine.alterTable(tableName, action, column);
|
||||
if (typeof this.diskEngine.alterTable === 'function') {
|
||||
await this.diskEngine.alterTable(tableName, action, column);
|
||||
} else {
|
||||
// 磁盘引擎无引擎级实现 → 从磁盘重建内存 schema(disk 引擎 schema 以自身为准)
|
||||
const schema = await this.diskEngine.getTableSchema(tableName);
|
||||
if (schema && action === 'DROP') delete schema.columns[column.name];
|
||||
try {
|
||||
if (typeof this.diskEngine.alterTable === 'function') {
|
||||
await this.diskEngine.alterTable(tableName, action, column);
|
||||
} else {
|
||||
// 磁盘引擎无引擎级实现 → 从磁盘重建内存 schema(disk 引擎 schema 以自身为准)
|
||||
const schema = await this.diskEngine.getTableSchema(tableName);
|
||||
if (schema && action === 'DROP') delete schema.columns[column.name];
|
||||
}
|
||||
} catch (error) {
|
||||
await this.recoverMemoryAfterDiskError(error);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- CRUD(write-through 策略) ----
|
||||
|
||||
/**
|
||||
* v0.7.2: 磁盘写失败补偿 — 内存已先行写入、磁盘失败 → 内存与磁盘不一致
|
||||
* (重启后数据丢失且调用方已收到错误)。从磁盘重载内存对齐真实状态
|
||||
* (内存=磁盘),再重新抛出原始错误。事务路径由双引擎快照回滚保证,
|
||||
* 无需此补偿。
|
||||
*/
|
||||
private async recoverMemoryAfterDiskError(error: unknown): Promise<never> {
|
||||
try {
|
||||
await this.reloadMemoryFromDisk();
|
||||
} catch {
|
||||
// 磁盘本身不可用(错误根源)时重载可能失败:错误已抛给调用方,
|
||||
// 内存保持失败前状态,repair()/重试可恢复
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn('[metona-sqlark] Hybrid: failed to reload memory after disk write error');
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
async insert(tableName: string, rows: Record<string, unknown>[]): Promise<string[]> {
|
||||
const pks = await this.memoryEngine.insert(tableName, rows);
|
||||
// write-through: 同步写入磁盘
|
||||
await this.diskEngine.insert(tableName, rows);
|
||||
try {
|
||||
await this.diskEngine.insert(tableName, rows);
|
||||
} catch (error) {
|
||||
await this.recoverMemoryAfterDiskError(error);
|
||||
}
|
||||
return pks;
|
||||
}
|
||||
|
||||
@@ -198,14 +232,22 @@ export class HybridEngine implements IStorageEngine {
|
||||
async update(tableName: string, query: QueryPlan, updates: Record<string, unknown>): Promise<number> {
|
||||
const count = await this.memoryEngine.update(tableName, query, updates);
|
||||
// write-through: 同步更新磁盘
|
||||
await this.diskEngine.update(tableName, query, updates);
|
||||
try {
|
||||
await this.diskEngine.update(tableName, query, updates);
|
||||
} catch (error) {
|
||||
await this.recoverMemoryAfterDiskError(error);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
async delete(tableName: string, query: QueryPlan): Promise<number> {
|
||||
const count = await this.memoryEngine.delete(tableName, query);
|
||||
// write-through: 同步删除磁盘
|
||||
await this.diskEngine.delete(tableName, query);
|
||||
try {
|
||||
await this.diskEngine.delete(tableName, query);
|
||||
} catch (error) {
|
||||
await this.recoverMemoryAfterDiskError(error);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -215,22 +257,34 @@ export class HybridEngine implements IStorageEngine {
|
||||
|
||||
async clear(tableName: string): Promise<void> {
|
||||
await this.memoryEngine.clear(tableName);
|
||||
await this.diskEngine.clear(tableName);
|
||||
try {
|
||||
await this.diskEngine.clear(tableName);
|
||||
} catch (error) {
|
||||
await this.recoverMemoryAfterDiskError(error);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 动态索引(v0.3.0) ----
|
||||
|
||||
async createIndex(tableName: string, column: string, unique?: boolean): Promise<void> {
|
||||
await this.memoryEngine.createIndex(tableName, column, unique);
|
||||
if (typeof this.diskEngine.createIndex === 'function') {
|
||||
await this.diskEngine.createIndex(tableName, column, unique);
|
||||
try {
|
||||
if (typeof this.diskEngine.createIndex === 'function') {
|
||||
await this.diskEngine.createIndex(tableName, column, unique);
|
||||
}
|
||||
} catch (error) {
|
||||
await this.recoverMemoryAfterDiskError(error);
|
||||
}
|
||||
}
|
||||
|
||||
async dropIndex(tableName: string, column: string, indexName?: string): Promise<void> {
|
||||
await this.memoryEngine.dropIndex(tableName, column, indexName);
|
||||
if (typeof this.diskEngine.dropIndex === 'function') {
|
||||
await this.diskEngine.dropIndex(tableName, column, indexName);
|
||||
try {
|
||||
if (typeof this.diskEngine.dropIndex === 'function') {
|
||||
await this.diskEngine.dropIndex(tableName, column, indexName);
|
||||
}
|
||||
} catch (error) {
|
||||
await this.recoverMemoryAfterDiskError(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user