Package at.aimon.session.postgres
Class PostgresIdempotencyStore
java.lang.Object
at.aimon.session.postgres.PostgresIdempotencyStore
- All Implemented Interfaces:
at.aimon.session.base.spi.IdempotencyStore
public final class PostgresIdempotencyStore
extends Object
implements at.aimon.session.base.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 Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationPrimary TTL applied when an entry transitions toIdempotencyEntry.Status.DONE. -
Constructor Summary
ConstructorsConstructorDescriptionPostgresIdempotencyStore(DataSource dataSource) PostgresIdempotencyStore(DataSource dataSource, com.fasterxml.jackson.databind.ObjectMapper mapper, Duration doneTtl, Clock clock) -
Method Summary
Modifier and TypeMethodDescriptionbooleancompareAndReset(String key, String expectedHolderId) Optional<at.aimon.session.base.spi.IdempotencyEntry>List<at.aimon.session.base.spi.IdempotencyEntry>findStaleInFlight(Instant cutoff) voidat.aimon.session.base.spi.PutResultputIfAbsent(String key, at.aimon.session.base.spi.IdempotencyEntry entry, Duration ttl) intsweepExpired(Instant now) Reaps DONE rows whose primary TTL expired.boolean
-
Field Details
-
DEFAULT_DONE_TTL
Primary TTL applied when an entry transitions toIdempotencyEntry.Status.DONE.
-
-
Constructor Details
-
PostgresIdempotencyStore
-
PostgresIdempotencyStore
public PostgresIdempotencyStore(DataSource dataSource, com.fasterxml.jackson.databind.ObjectMapper mapper, Duration doneTtl, Clock clock)
-
-
Method Details
-
putIfAbsent
public at.aimon.session.base.spi.PutResult putIfAbsent(String key, at.aimon.session.base.spi.IdempotencyEntry entry, Duration ttl) - Specified by:
putIfAbsentin interfaceat.aimon.session.base.spi.IdempotencyStore
-
markDone
- Specified by:
markDonein interfaceat.aimon.session.base.spi.IdempotencyStore
-
find
- Specified by:
findin interfaceat.aimon.session.base.spi.IdempotencyStore
-
touch
- Specified by:
touchin interfaceat.aimon.session.base.spi.IdempotencyStore
-
compareAndReset
- Specified by:
compareAndResetin interfaceat.aimon.session.base.spi.IdempotencyStore
-
findStaleInFlight
- Specified by:
findStaleInFlightin interfaceat.aimon.session.base.spi.IdempotencyStore
-
sweepExpired
Reaps DONE rows whose primary TTL expired. Called by the manager's scheduled cleanup (design §4.4).- Parameters:
now- wall clock against whichexpires_atis compared- Returns:
- number of rows deleted
-