huaxingao commented on code in PR #3205:
URL: https://github.com/apache/polaris/pull/3205#discussion_r2638330459


##########
persistence/relational-jdbc/src/main/resources/postgres/schema-v3.sql:
##########
@@ -134,3 +134,31 @@ CREATE TABLE IF NOT EXISTS events (
     additional_properties JSONB NOT NULL DEFAULT '{}'::JSONB,
     PRIMARY KEY (event_id)
 );
+
+-- Idempotency records (key-only idempotency; durable replay)
+CREATE TABLE IF NOT EXISTS idempotency_records (
+    realm_id TEXT NOT NULL,
+    idempotency_key TEXT NOT NULL,
+    operation_type TEXT NOT NULL,
+    resource_id TEXT NOT NULL,
+
+    -- Finalization/replay
+    http_status INTEGER,                 -- NULL while IN_PROGRESS; set only 
on finalized 2xx/terminal 4xx
+    error_subtype TEXT,                  -- optional: e.g., already_exists, 
namespace_not_empty, idempotency_replay_failed
+    response_summary TEXT,               -- minimal body to reproduce 
equivalent response (JSON string)
+    response_headers TEXT,               -- small whitelisted headers to 
replay (JSON string)
+    finalized_at TIMESTAMP,              -- when http_status was written
+
+    -- Liveness/ops
+    created_at TIMESTAMP NOT NULL,
+    updated_at TIMESTAMP NOT NULL,
+    heartbeat_at TIMESTAMP,              -- updated by owner while IN_PROGRESS
+    executor_id TEXT,                    -- owner pod/worker id
+    expires_at TIMESTAMP,
+
+    PRIMARY KEY (realm_id, idempotency_key)
+);
+
+-- Helpful indexes
+CREATE INDEX IF NOT EXISTS idx_idemp_expires ON idempotency_records 
(expires_at);
+CREATE INDEX IF NOT EXISTS idx_idemp_active  ON idempotency_records 
(http_status, heartbeat_at);

Review Comment:
   Good question. Today the only concrete patterns we have are:
    - single‑row lookups by (realm_id, idempotency_key) for load / 
updateHeartbeat / finalize, which are already handled by the PK, and
    - the purge query, which now uses realm_id + expires_at and has its own 
index.
   
   We don’t yet have an API that actually scans by heartbeat_at. I will remove 
this for now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to