This commit is contained in:
lxp
2026-10-27 14:35:18 +08:00
parent 27f5849657
commit 64fb4a7325
6 changed files with 120 additions and 4 deletions
@@ -6,7 +6,11 @@ public class GiteaFailure extends BusinessException {
private final boolean uncertain;
public GiteaFailure(int status, String code, String message, boolean uncertain) {
super(status, code, message);
this(status, code, message, uncertain, null);
}
public GiteaFailure(int status, String code, String message, boolean uncertain, Object details) {
super(status, code, message, details);
this.uncertain = uncertain;
}
@@ -536,11 +536,15 @@ public class ProjectServiceImpl implements ProjectService {
code,
error.code(),
error.uncertain());
throw new BusinessException(
// 保留远端结果确定性,避免读取失败被外层写入保护误判为未知写入。
GiteaFailure failure = new GiteaFailure(
error.status(),
error.code(),
error.getMessage(),
error.uncertain(),
Map.of("projectCode", code));
failure.initCause(error);
throw failure;
}
});
}
@@ -83,8 +83,12 @@ public class ProjectLocks {
() -> {
if (writing.get().contains(code)) return action.get();
Project guard = guard(code);
if (uncertain.contains(code)
boolean memoryUncertain = uncertain.contains(code);
if (memoryUncertain
|| guard != null && !"IDLE".equals(guard.getRepoWriteStatus())) {
log.warn(
"仓库写入被阻止 projectCode={} persistedWriteStatus={} memoryUncertain={}",
code, guard == null ? null : guard.getRepoWriteStatus(), memoryUncertain);
markUncertain(code);
throw blocked();
}
@@ -101,7 +105,10 @@ public class ProjectLocks {
503, "PROJECT_LOCK_UNAVAILABLE", "持锁连接已断开,请核对操作结果");
}
}
if (!uncertain.contains(code)) state(code, "IDLE");
if (!uncertain.contains(code)) {
state(code, "IDLE");
log.info("仓库写入完成 projectCode={} writeStatus=IDLE", code);
}
return result;
} catch (RuntimeException error) {
boolean unknown =