fix(心跳): 影子扫描不再新增 catch 块——静默 catch 棘轮当场抓住
闸门红在 CatchSilenceRatchetTest:影子服务新增的 2 处 log-only catch 与位置指纹 新增的 1 处 fail-open catch 都会抬「只 log / 不重抛」台账。改法是消除新增 catch 而不是调基线:tryLock 内部已把 Redis 异常降级成 null,扫描异常交给 Spring 调度器 记录;指纹复用 describe/readPosition 各自的降级出口。之后 1281 例与棘轮全绿。
This commit is contained in:
+14
-18
@@ -328,28 +328,24 @@ public class TaskHeartbeatPositionService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 影子判官的推进指纹:位置哈希一次读出,计数/文本/阶段任一变化都算推进。
|
||||
* 返回 null 表示这个任务没有任何位置信息(老客户端不传位置),不能作为判死证据。
|
||||
* 影子判官的推进指纹:计数/文本任一变化都算推进。
|
||||
*
|
||||
* <p>复用 {@link #describe} 与 {@link #readPosition}(两者各自把 Redis 异常降级成 null),
|
||||
* 不新增 catch;老客户端只发文本时由 describe 兜住。返回 null 表示没有任何位置信息,
|
||||
* 不能作为判死证据。
|
||||
*/
|
||||
private String readProgressFingerprint(Long taskId) {
|
||||
Map<Object, Object> entries;
|
||||
try {
|
||||
entries = stringRedisTemplate.opsForHash().entries(KEY_PREFIX + taskId);
|
||||
} catch (Exception ex) {
|
||||
log.warn("[heartbeat-position] 读取影子位置失败 taskId={} msg={}", taskId, ex.getMessage());
|
||||
String text = describe(taskId);
|
||||
Position position = readPosition(taskId);
|
||||
if ((text == null || text.isBlank()) && position == null) {
|
||||
return null;
|
||||
}
|
||||
if (entries == null || entries.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
String text = value(entries, "progressText");
|
||||
String current = value(entries, "current");
|
||||
String total = value(entries, "total");
|
||||
if (text.isBlank() && current.isBlank() && total.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
return value(entries, "phase") + "|" + value(entries, "grain")
|
||||
+ "|" + current + "|" + total + "|" + text;
|
||||
String current = position == null || position.current() == null
|
||||
? "" : String.valueOf(position.current());
|
||||
String total = position == null || position.total() == null
|
||||
? "" : String.valueOf(position.total());
|
||||
String grain = position == null || position.grain() == null ? "" : position.grain();
|
||||
return grain + "|" + current + "|" + total + "|" + (text == null ? "" : text);
|
||||
}
|
||||
|
||||
private StallState evaluateAgainstSnapshot(Long taskId,
|
||||
|
||||
+4
-10
@@ -75,22 +75,16 @@ public class TaskLivenessShadowService {
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
DistributedJobLockService.LockHandle lock;
|
||||
try {
|
||||
lock = distributedJobLockService.tryLock(SCAN_LOCK_NAME, Duration.ofMinutes(5));
|
||||
} catch (Exception ex) {
|
||||
log.warn("{} 获取扫描锁失败,本轮跳过 msg={}", LOG_ANCHOR, ex.getMessage());
|
||||
return;
|
||||
}
|
||||
// tryLock 内部已把 Redis 异常降级成 null;扫描失败交给 Spring 调度器记录并继续下一轮,
|
||||
// 不在这里吞异常——影子线只读,抛出去也不会影响任务本身。
|
||||
DistributedJobLockService.LockHandle lock =
|
||||
distributedJobLockService.tryLock(SCAN_LOCK_NAME, Duration.ofMinutes(5));
|
||||
if (lock == null) {
|
||||
log.info("{} 另一实例持有扫描锁,本轮跳过", LOG_ANCHOR);
|
||||
return;
|
||||
}
|
||||
try (lock) {
|
||||
scanOnce();
|
||||
} catch (Exception ex) {
|
||||
// 影子线只读:扫描失败绝不能影响任务本身
|
||||
log.warn("{} 扫描失败(只读,不影响任务) msg={}", LOG_ANCHOR, ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user