Commit 86ddd374 by luoqi

fix(prisma): bump $transaction timeout 5s → 60s

cold-import 在 swap thrashing 大压力下,单 fact-write 事务可能跑 20s+,
默认 5s timeout abort 整条 patient pipeline。服务器全量 cold-import 跑到
15% (479k/3.15M txn) 就被 "Transaction already closed" 杀死。

4 处 $transaction 加 { maxWait:30000, timeout:60000 }:
  fact-writer (最热,每 fact 1 次)
  persona recompute / plan execution / plan engine 上版

风险:长事务期间持锁久,但 cold-import 本身就是串行 patient,无锁竞争。
parent dc8b6a0f
...@@ -226,7 +226,7 @@ export class PersonaService { ...@@ -226,7 +226,7 @@ export class PersonaService {
}, },
}, },
}); });
}); }, { maxWait: 30000, timeout: 60000 });
const status = failed === 0 ? 'success' : drafts.length > 0 ? 'partial' : 'failed'; const status = failed === 0 ? 'success' : drafts.length > 0 ? 'partial' : 'failed';
await this.prisma.personaRecomputeLog.update({ await this.prisma.personaRecomputeLog.update({
......
...@@ -249,7 +249,7 @@ export class PlanEngineService { ...@@ -249,7 +249,7 @@ export class PlanEngineService {
}, },
}, },
}); });
}); }, { maxWait: 30000, timeout: 60000 });
return latest ? 'superseded' : 'created'; return latest ? 'superseded' : 'created';
} }
......
...@@ -160,7 +160,7 @@ export class ExecutionService { ...@@ -160,7 +160,7 @@ export class ExecutionService {
}); });
return execution; return execution;
}); }, { maxWait: 30000, timeout: 60000 });
return { return {
executionId: result.id, executionId: result.id,
......
...@@ -70,6 +70,8 @@ export class FactWriter { ...@@ -70,6 +70,8 @@ export class FactWriter {
// ⚠️ 必须查最新版本(不能只查 active)— 因为 fulfilled / cancelled / expired // ⚠️ 必须查最新版本(不能只查 active)— 因为 fulfilled / cancelled / expired
// 等终态版本"没有 active",但 (subjectId, version) UNIQUE 约束仍在 — // 等终态版本"没有 active",但 (subjectId, version) UNIQUE 约束仍在 —
// 要算下一 version 必须知道历史最高 version。 // 要算下一 version 必须知道历史最高 version。
// ⭐ 默认 timeout 5s 在 cold-import 大压力 / swap thrashing 下不够,撑到 60s
// fact-writer 是最热路径,每 fact 一次 tx,失败一次 = 整条 patient pipeline 中断
return this.prisma.$transaction(async (tx) => { return this.prisma.$transaction(async (tx) => {
const latest = await tx.patientFact.findFirst({ const latest = await tx.patientFact.findFirst({
where: { where: {
...@@ -151,7 +153,7 @@ export class FactWriter { ...@@ -151,7 +153,7 @@ export class FactWriter {
subjectId: draft.subjectId, subjectId: draft.subjectId,
version: nextVersion, version: nextVersion,
}; };
}); }, { maxWait: 30000, timeout: 60000 });
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment