You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "dimas-b (via GitHub)" <gi...@apache.org> on 2026/04/02 01:29:39 UTC
Re: [PR] Add Iceberg REST Idempotency-Key support [polaris]
dimas-b commented on code in PR #3803:
URL: https://github.com/apache/polaris/pull/3803#discussion_r3025424667
##########
extensions/idempotency/src/main/java/org/apache/polaris/service/idempotency/IdempotencyMaintenance.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.service.idempotency;
+
+import io.quarkus.runtime.ShutdownEvent;
+import io.quarkus.runtime.StartupEvent;
+import io.smallrye.mutiny.infrastructure.Infrastructure;
+import io.vertx.core.Vertx;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.enterprise.event.Observes;
+import jakarta.inject.Inject;
+import java.net.InetAddress;
+import java.time.Clock;
+import java.time.Instant;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.polaris.core.persistence.IdempotencyStore;
+import org.apache.polaris.service.context.RealmContextConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Background maintenance for idempotency (purge of expired keys). */
+@ApplicationScoped
+public class IdempotencyMaintenance {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(IdempotencyMaintenance.class);
+
+ @Inject IdempotencyConfiguration configuration;
+ @Inject RealmContextConfiguration realmContextConfiguration;
+ @Inject IdempotencyStore store;
+ @Inject Clock clock;
+ @Inject Vertx vertx;
+
+ private volatile Long purgeTimerId;
+ private final AtomicBoolean purgeRunning = new AtomicBoolean(false);
+ private volatile String resolvedExecutorId;
+
+ void onStart(@Observes StartupEvent event) {
+ if (!configuration.enabled() || !configuration.purgeEnabled()) {
+ return;
+ }
+ Optional<String> purgeExecutorId = configuration.purgeExecutorId();
+ if (purgeExecutorId.isPresent()) {
+ String localExecutorId = executorId();
+ if (!purgeExecutorId.get().equals(localExecutorId)) {
+ LOGGER.debug(
+ "Skipping idempotency purge on executor {} (purge-executor-id={})",
+ localExecutorId,
+ purgeExecutorId.get());
+ return;
+ }
+ }
+ long intervalMs = configuration.purgeInterval().toMillis();
+ purgeTimerId =
+ vertx.setPeriodic(
+ intervalMs,
+ ignored -> {
+ // Timer callbacks run on a Vert.x event-loop thread; offload blocking store I/O.
+ if (!purgeRunning.compareAndSet(false, true)) {
+ return;
+ }
+ Infrastructure.getDefaultWorkerPool()
+ .execute(
+ () -> {
+ try {
+ purgeOnce();
+ } finally {
+ purgeRunning.set(false);
+ }
+ });
+ });
+ }
+
+ void onStop(@Observes ShutdownEvent event) {
+ Long id = purgeTimerId;
+ if (id != null) {
+ vertx.cancelTimer(id);
+ }
+ }
+
+ private void purgeOnce() {
Review Comment:
> Medium: purgeGrace is ignored for the JDBC store, so the configured grace window has no effect. extensions/idempotency/src/main/java/org/apache/polaris/
service/idempotency/IdempotencyMaintenance.java:97 computes a cutoff of now - purgeGrace and passes it to store.purgeExpired(...), but persistence/
relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/idempotency/RelationalJdbcIdempotencyStore.java:280 deletes with expires_at <
CURRENT_TIMESTAMP instead of using the before parameter. That makes the documented grace behavior in runtime/service/src/main/java/org/apache/polaris/
service/idempotency/IdempotencyConfiguration.java:203 incorrect for JDBC deployments.
##########
persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/idempotency/RelationalJdbcIdempotencyStore.java:
##########
@@ -67,13 +78,17 @@ public ReserveResult reserve(
insertMap.put(ModelIdempotencyRecord.RESPONSE_SUMMARY, null);
insertMap.put(ModelIdempotencyRecord.RESPONSE_HEADERS, null);
insertMap.put(ModelIdempotencyRecord.FINALIZED_AT, null);
- insertMap.put(ModelIdempotencyRecord.CREATED_AT, Timestamp.from(now));
- insertMap.put(ModelIdempotencyRecord.UPDATED_AT, Timestamp.from(now));
- insertMap.put(ModelIdempotencyRecord.HEARTBEAT_AT, Timestamp.from(now));
+ insertMap.put(ModelIdempotencyRecord.CREATED_AT, new SqlLiteral("CURRENT_TIMESTAMP"));
+ insertMap.put(ModelIdempotencyRecord.UPDATED_AT, new SqlLiteral("CURRENT_TIMESTAMP"));
+ insertMap.put(ModelIdempotencyRecord.HEARTBEAT_AT, new SqlLiteral("CURRENT_TIMESTAMP"));
insertMap.put(ModelIdempotencyRecord.EXECUTOR_ID, executorId);
- insertMap.put(ModelIdempotencyRecord.EXPIRES_AT, Timestamp.from(expiresAt));
+ long ttlSeconds = Duration.between(now, expiresAt).getSeconds();
+ insertMap.put(
+ ModelIdempotencyRecord.EXPIRES_AT,
+ new SqlLiteral("CURRENT_TIMESTAMP + INTERVAL '" + ttlSeconds + "' SECOND"));
- List<Object> values = insertMap.values().stream().toList();
+ // Stream#toList returns an unmodifiable list and rejects nulls; these columns are nullable.
+ List<Object> values = new ArrayList<>(insertMap.values());
Review Comment:
> High: expired JDBC records are never reclaimable unless a purge happens, so keys can remain blocked forever with the default config. In persistence/
relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/idempotency/RelationalJdbcIdempotencyStore.java:70, reserve() does a blind
insert and treats any PK conflict as a live duplicate by returning load(...); unlike the in-memory store, it does not replace expired rows. Since purge is
disabled by default in runtime/service/src/main/java/org/apache/polaris/service/idempotency/IdempotencyConfiguration.java:178, an expired row can sit in
the table indefinitely and make that idempotency key unusable long after TTL expiry.
--
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: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org