Class PostgresIdempotencyStore

java.lang.Object
at.aimon.session.postgres.PostgresIdempotencyStore
All Implemented Interfaces:
at.aimon.session.web.spi.IdempotencyStore

public final class PostgresIdempotencyStore extends Object implements at.aimon.session.web.spi.IdempotencyStore
Postgres-backed IdempotencyStore per design §4.4.

Each idempotency key maps to one row in idempotency_entry. putIfAbsent uses INSERT ... ON CONFLICT DO NOTHING; the four atomic transitions (markDone, touch, compareAndReset, findStaleInFlight) are single-statement SQL guarded by composite WHERE key = ? AND holder_id = ? AND status = 'IN_FLIGHT' predicates.

result_blob is stored as JSONB; the rest of the entry lives in its own typed columns so the sweeper indexes stay efficient.

  • Field Details

    • DEFAULT_DONE_TTL

      public static final Duration DEFAULT_DONE_TTL
      Primary TTL applied when an entry transitions to IdempotencyEntry.Status.DONE.
  • Constructor Details

    • PostgresIdempotencyStore

      public PostgresIdempotencyStore(DataSource dataSource)
    • PostgresIdempotencyStore

      public PostgresIdempotencyStore(DataSource dataSource, com.fasterxml.jackson.databind.ObjectMapper mapper, Duration doneTtl, Clock clock)
  • Method Details

    • putIfAbsent

      public at.aimon.session.web.spi.PutResult putIfAbsent(String key, at.aimon.session.web.spi.IdempotencyEntry entry, Duration ttl)
      Specified by:
      putIfAbsent in interface at.aimon.session.web.spi.IdempotencyStore
    • markDone

      public void markDone(String key, at.aimon.core.agent.AgentExecutionResult result)
      Specified by:
      markDone in interface at.aimon.session.web.spi.IdempotencyStore
    • find

      public Optional<at.aimon.session.web.spi.IdempotencyEntry> find(String key)
      Specified by:
      find in interface at.aimon.session.web.spi.IdempotencyStore
    • touch

      public boolean touch(String key, String holderId)
      Specified by:
      touch in interface at.aimon.session.web.spi.IdempotencyStore
    • compareAndReset

      public boolean compareAndReset(String key, String expectedHolderId)
      Specified by:
      compareAndReset in interface at.aimon.session.web.spi.IdempotencyStore
    • findStaleInFlight

      public List<at.aimon.session.web.spi.IdempotencyEntry> findStaleInFlight(Instant cutoff)
      Specified by:
      findStaleInFlight in interface at.aimon.session.web.spi.IdempotencyStore
    • sweepExpired

      public int sweepExpired(Instant now)
      Reaps DONE rows whose primary TTL expired. Called by the manager's scheduled cleanup (design §4.4).
      Parameters:
      now - wall clock against which expires_at is compared
      Returns:
      number of rows deleted