fix: v0.7.2 语句级原子性 + 事务 DDL 拒绝 + 约束/绑定硬化 — 6 项修复 + 43 回归 + CI 重型套件串行
CI / test (22.x) (push) Successful in 24m26s
CI / e2e (push) Successful in 10m0s
CI / test (18.x) (push) Successful in 27m14s
CI / test (20.x) (push) Failing after 1h19m9s
CI / test (24.x) (push) Successful in 37m49s

- 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:
thzxx
2026-08-13 15:31:16 +08:00
parent cbe407eb49
commit 05e6823bf1
31 changed files with 2635 additions and 762 deletions
+26 -2
View File
@@ -23,6 +23,7 @@ import { DatabaseError } from '../constants';
import { MemoryEngine } from './memory';
import { KVStore } from './kvstore/index';
import type { IStorageBackend } from './aria/store/backend';
import { stripUndefinedUpdates } from '../table/schema';
const SCHEMA_KEY = '__schema';
const ROW_PREFIX = 't:';
@@ -229,6 +230,15 @@ export class KVStoreEngine implements IStorageEngine {
column: import('../constants').ColumnDef & { name: string },
): Promise<void> {
this.ensureOpen();
// v0.7.2: 事务内 ALTER 显式拒绝(与 AriaEngine/MemoryEngine 对齐)——
// memory.alterTable 直接修改共享 columns 对象,事务快照无法回滚
// (此前 ROLLBACK 后新增列残留)
if (this.txActive) {
throw new DatabaseError(
`ALTER TABLE is not supported inside a transaction (KVStoreEngine DDL is not transactional)`,
'NOT_SUPPORTED',
);
}
await this.memory.alterTable(tableName, action, column);
if (this.txActive) {
this.txDirtyTables.add(tableName);
@@ -296,11 +306,13 @@ export class KVStoreEngine implements IStorageEngine {
const schema = await this.memory.getTableSchema(tableName);
if (!schema) throw new DatabaseError(`Table "${tableName}" does not exist`, 'TABLE_NOT_FOUND');
const pkCol = this.getPK(schema);
const pkChanged = pkCol in updates;
// v0.7.2: undefined 值视为"不更新该列"(与 memory.update 语义对齐)
const cleanUpdates = stripUndefinedUpdates(updates);
const pkChanged = pkCol in cleanUpdates;
// 收集受影响旧主键(内存匹配)
const affected = pkChanged ? [] : await this.collectMatchingPks(tableName, query);
const count = await this.memory.update(tableName, query, updates);
const count = await this.memory.update(tableName, query, cleanUpdates);
if (this.txActive) {
this.txDirtyTables.add(tableName);
// v0.7.0: 行级变更记录 —— 主键变更无法行级追踪(旧键删除+新键落盘+级联),
@@ -425,6 +437,12 @@ export class KVStoreEngine implements IStorageEngine {
async createIndex(tableName: string, column: string, unique?: boolean): Promise<void> {
this.ensureOpen();
if (this.txActive) {
throw new DatabaseError(
`CREATE INDEX is not supported inside a transaction (KVStoreEngine DDL is not transactional)`,
'NOT_SUPPORTED',
);
}
await this.memory.createIndex(tableName, column, unique);
if (this.txActive) {
this.txDirtyTables.add(tableName);
@@ -436,6 +454,12 @@ export class KVStoreEngine implements IStorageEngine {
async dropIndex(tableName: string, column: string, indexName?: string): Promise<void> {
this.ensureOpen();
if (this.txActive) {
throw new DatabaseError(
`DROP INDEX is not supported inside a transaction (KVStoreEngine DDL is not transactional)`,
'NOT_SUPPORTED',
);
}
await this.memory.dropIndex(tableName, column, indexName);
if (this.txActive) {
this.txDirtyTables.add(tableName);