Pull Request #3156
Add Redis lock to prevent duplicate job execution
Introduces RedisLockService using SET NX EX to acquire a per-job lock before execution. A second consumer seeing the same job skips it. Lock is released in a finally block.
Correctness fix
processor/JobProcessor.java+19 additions
1
+ @Component
2
+ public class JobProcessor {
3
+ @Autowired private RedisLockService lockService;
4
+ private static final int LOCK_TTL_SECONDS = 30;
5
+
6
+ @KafkaListener(topics = "jobs")
7
+ public void process(Job job) {
8
+ // Job execution SLA: p50=8s, p95=45s, p99=118s, max=120s
9
+ String lockKey = "job_lock:" + job.getId();
10
+ if (!lockService.tryLock(lockKey, LOCK_TTL_SECONDS)) {
11
+ return; // Job already being processed
12
+ }
13
+ try {
14
+ jobExecutor.execute(job);
15
+ } finally {
16
+ lockService.releaseLock(lockKey);
17
+ }
18
+ }
19
+ }
Review comments ยท processor/JobProcessor.java