Class IdempotencyRequestContext

java.lang.Object
org.apache.polaris.service.idempotency.IdempotencyRequestContext

@RequestScoped public class IdempotencyRequestContext extends Object
Request-scoped holder for a pending entity-property idempotency key. The REST adapter sets the key before invoking the handler; LocalIcebergCatalog reads it when committing a create so the key is stamped atomically with the new entity.

Although request-scoped, the same instance can be touched from more than one thread over a request's lifetime (e.g. the IdempotencyKeyFilter vs. the REST service code), so the pending key is held in an AtomicReference — mirroring RealmContextHolder.

  • Field Details

    • DISABLED

      public static final IdempotencyRequestContext DISABLED
      Shared no-op context for code paths that build a catalog without request-scoped idempotency (e.g. non-CDI construction and tests). isActive() is always false, so callers can hold a non-null context instead of null-checking.
  • Constructor Details

    • IdempotencyRequestContext

      @Inject public IdempotencyRequestContext(IdempotencyConfiguration idempotencyConfiguration)
  • Method Details

    • setPendingKey

      public void setPendingKey(@Nullable UUID key)
      Records key for the current request, computing expiry from IdempotencyConfiguration.ttl(). No-op when key is null or on the DISABLED context.
    • isActive

      public boolean isActive()
      Whether entity-property idempotency applies to the current request: the feature is enabled and a well-formed Idempotency-Key was supplied (and thus captured by IdempotencyKeyFilter). When true, pendingKey() is non-null.
    • pendingKey

      public @Nullable UUID pendingKey()
    • pendingExpiry

      public @Nullable Instant pendingExpiry()
    • clearPending

      public void clearPending()
      Resets the pending state. Not needed in production, where each request gets a fresh RequestScoped instance; provided so tests that drive multiple logical requests through a shared instance can simulate that per-request lifecycle.