Class RedisOutboxRepairWorker

java.lang.Object
com.aim2be.platform.outbox.redis.RedisOutboxRepairWorker

public class RedisOutboxRepairWorker extends Object
zset/hash reconciliation sweep (refinement #10). The two index structures — the :entries Hash (durable record) + the :pending sorted-set (poller index) — can diverge after a mid-script crash (refinement #1: a Lua runtime error does NOT roll back earlier writes). This worker reconciles two classes of inconsistency:
  • orphan zset member — a :pending member with NO :entries field. The poller's HMGET returns nil and skips it forever; the member lingers. Repair: ZREM it (only when the Hash field is STILL absent — re-checked in repair-reconcile.lua).
  • orphan Hash entry — an :entries field with status=PENDING but NO :pending member. The poller scans :pending, so it never sees it → never relayed. Repair: re-ZADD it with score=now (only when STILL PENDING and STILL un-indexed).

The two snapshots (HSCAN entries + ZSCAN pending) are taken at slightly different instants, so a candidate could be stale by the time the repair runs; the repair-reconcile.lua script re-checks the live state and no-ops if the inconsistency has resolved itself — so the worker is safe to run even while the poller + relay are active.

  • Constructor Details

    • RedisOutboxRepairWorker

      public RedisOutboxRepairWorker(org.springframework.data.redis.core.StringRedisTemplate redis, RedisOutboxScripts scripts, RedisOutboxKeys keys, com.fasterxml.jackson.databind.ObjectMapper objectMapper, RedisOutboxMetrics metrics)
      Parameters:
      redis - Redis template (HSCAN/ZSCAN + the reconcile EVAL)
      scripts - Lua scripts (the reconcile script)
      keys - the hash-tagged key set
      objectMapper - JSON decoder for the scanned entries
      metrics - metrics binder (per-class repair counter)
  • Method Details

    • reconcile

      @Scheduled(fixedDelayString="${im2be.outbox.redis.repair.interval-ms:900000}") public void reconcile()
      Scheduled repair sweep. Cadence governed by im2be.outbox.redis.repair.interval-ms.