refactor(processing): remove unused processing start field

processing_started_at 没有任何判据消费(终态只看尝试上限),删除字段、仓储接口与方法、主泵写入、重放清理、SELECT/映射与 H2 fixture,并新增 V7 DROP COLUMN;V1–V6 历史迁移不动。

验证:./gradlew test 123 tests / 0 fail;V7 的 DROP 与最终 schema 断言需真实 PG,本机无 Docker 时 FlywayMigrationTest 按既有 assumeTrue 跳过。
This commit is contained in:
windyboy
2026-09-12 20:31:23 +08:00
parent 161914eeb8
commit eb103d6244
9 changed files with 34 additions and 51 deletions
@@ -86,12 +86,5 @@ data class ProcState(
val backfillAbandonedAt: Instant? = null,
/** 放弃原因(`MISSING_ROW` / `TRANSIENT_DEADLINE`),供人工对账与恢复判断。 */
val backfillAbandonedReason: String? = null,
/**
* 首次被主泵取得的时刻;重试不刷新。
*
* 当前没有判据消费它(终态只看尝试上限),保留作排障与后续扩展;写入方是
* [com.gzzn.omms.msgexchange.infra.persistence.ProcStateRepository.markProcessingStartedIfAbsent]。
*/
val processingStartedAt: Instant? = null,
val updatedAt: Instant = Instant.now(),
)
@@ -59,9 +59,6 @@ interface ProcStateRepository {
/** 当前队头:还没处理完的消息里 ID 最小的那条。 */
fun headUnfinished(): ProcState?
/** 首次开始处理时记下稳定起点;重试不覆盖。 */
fun markProcessingStartedIfAbsent(msgId: Long, now: Instant)
/** 给消息绑定业务身份;返回 false 表示这个身份已经被另一条消息占了(业务重复)。 */
fun tryBindIdentity(msgId: Long, identityKey: String): Boolean
@@ -107,16 +107,6 @@ class JdbcProcStateRepository(
::mapProcState,
)
override fun markProcessingStartedIfAbsent(msgId: Long, now: Instant) {
ds.update(
"UPDATE proc_state SET processing_started_at = ? WHERE msg_id = ? AND processing_started_at IS NULL",
{ ps ->
ps.setTimestamp(1, now.toSqlTimestamp())
ps.setLong(2, msgId)
},
)
}
override fun tryBindIdentity(msgId: Long, identityKey: String): Boolean {
ownerOfIdentity(identityKey)?.let { owner ->
return owner == msgId
@@ -286,7 +276,7 @@ class JdbcProcStateRepository(
if (errorClasses.isEmpty()) return 0
val placeholders = errorClasses.joinToString(",") { "?" }
return ds.update(
"UPDATE proc_state SET state = 'PENDING', attempts = 0, next_attempt_at = NULL, processing_started_at = NULL, updated_at = ? " +
"UPDATE proc_state SET state = 'PENDING', attempts = 0, next_attempt_at = NULL, updated_at = ? " +
"WHERE state IN ('FAILED', 'DEAD') AND error_class IN ($placeholders)",
{ ps ->
ps.setTimestamp(1, clock.instant().toSqlTimestamp())
@@ -339,7 +329,6 @@ class JdbcProcStateRepository(
backfillError = rs.getString("backfill_error"),
backfillAbandonedAt = rs.getInstant("backfill_abandoned_at"),
backfillAbandonedReason = rs.getString("backfill_abandoned_reason"),
processingStartedAt = rs.getInstant("processing_started_at"),
updatedAt = rs.getInstant("updated_at") ?: clock.instant(),
)
@@ -347,7 +336,7 @@ class JdbcProcStateRepository(
const val SELECT_PROC =
"SELECT msg_id, state, identity_key, attempts, next_attempt_at, error_class, last_error, " +
"received_at, enqueued_at, backfill_at, backfill_next_at, backfill_attempts, backfill_error, " +
"backfill_abandoned_at, backfill_abandoned_reason, processing_started_at, updated_at FROM proc_state"
"backfill_abandoned_at, backfill_abandoned_reason, updated_at FROM proc_state"
}
}
@@ -84,12 +84,6 @@ class StubProcState : ProcStateRepository {
override fun headUnfinished(): ProcState? =
rows.values.filter { it.state == ProcStatus.PENDING || it.state == ProcStatus.FAILED }.minByOrNull { it.msgId }
override fun markProcessingStartedIfAbsent(msgId: Long, now: Instant) {
rows[msgId]?.let { row ->
if (row.processingStartedAt == null) rows[msgId] = row.copy(processingStartedAt = now)
}
}
override fun tryBindIdentity(msgId: Long, identityKey: String): Boolean {
val owner = bound[identityKey]
if (owner != null && owner != msgId) return false
@@ -216,7 +210,7 @@ class StubProcState : ProcStateRepository {
var n = 0
rows.forEach { (id, s) ->
if (s.errorClass in errorClasses && (s.state == ProcStatus.FAILED || s.state == ProcStatus.DEAD)) {
rows[id] = s.copy(state = ProcStatus.PENDING, attempts = 0, nextAttemptAt = null, processingStartedAt = null)
rows[id] = s.copy(state = ProcStatus.PENDING, attempts = 0, nextAttemptAt = null)
n++
}
}
@@ -103,10 +103,7 @@ class Pump(
head.state == ProcStatus.FAILED && (head.nextAttemptAt ?: Instant.EPOCH) > now ->
sleepQuietly(Duration.between(now, head.nextAttemptAt))
// 其余情况(新消息,或退避到期的重试)交给处理入口
else -> {
procState.markProcessingStartedIfAbsent(head.msgId, now)
processor.processOne(head)
}
else -> processor.processOne(head)
}
}
@@ -0,0 +1,14 @@
-- =====================================================================
-- V7PROC_STATE 删除 PROCESSING_STARTED_AT
-- ---------------------------------------------------------------------
-- 只动自有 PostgreSQL;共享 MySQL 不建表、不改结构。
--
-- 该列由 V3 引入(原 HOL deadline 的稳定处理起点),但代码里没有任何判据消费它:
-- 处理终态只看尝试上限(`PARAM:msgx.pipeline.max-attempts`)。按精简原则删除列与
-- 全部读写路径,不留"以后也许有用"的死字段;将来若为 `CLM-9` 需要处理开始时间,
-- 先写文档再实现。
--
-- 已发布的迁移历史(V1–V6)保持不变。
-- =====================================================================
ALTER TABLE PROC_STATE DROP COLUMN PROCESSING_STARTED_AT;