You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "yuqi1129 (via GitHub)" <gi...@apache.org> on 2026/06/18 14:43:52 UTC

[PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

yuqi1129 opened a new pull request, #11739:
URL: https://github.com/apache/gravitino/pull/11739

   ### What changes were proposed in this pull request?
   
   Two fixes to the shared `EntityChangeLogPoller` (consumed today by the jcasbin caches), which could permanently lose a change-log row's invalidation:
   
   1. **Commit-ordering gap (lagging high-water mark).** `selectEntityChanges` now only consumes rows older than a configurable lag (`created_at <= DB_now - lagMs`), computed with the DB clock so there is no app/DB skew. The cursor stays the simple monotonic `id`. New config `gravitino.entityChangeLog.pollLagSecs` (default `1`). The PostgreSQL provider gets its own `selectEntityChanges` override for the EPOCH expression.
   2. **Listener-failure cursor advance.** The high-water mark is now advanced only when *every* listener applied the batch; a failing listener no longer blocks the others, and the batch is retried on the next cycle (invalidation is idempotent).
   
   Also adds the missing `VERSION_1_4_0` constant and relabels the entity-change-log configs from `1.3.0` (never released; dev is `1.4.0-SNAPSHOT`) to `1.4.0`, plus the docs.
   
   > Note: the issue's suggested fix #3 (`expireAfterWrite`) is intentionally **not** included — entity-store-cache multi-node invalidation isn't implemented yet, so it is deferred.
   
   ### Why are the changes needed?
   
   In multi-node deployments these two paths silently drop invalidations, leaving stale entities/relations on remote nodes after an ALTER/DROP/grant/revoke/setOwner on another node. Problems (1) and (2) already affect the existing jcasbin cache path.
   
   Fix: #11736
   
   ### Does this PR introduce _any_ user-facing change?
   
   Adds one property key: `gravitino.entityChangeLog.pollLagSecs` (default `1`s, documented in `gravitino-server-config.md`).
   
   ### How was this patch tested?
   
   - `TestEntityChangeLogPoller`: rewrote the listener-failure test (cursor no longer advances; batch retried), added cursor-recovery and negative-lag-rejection tests.
   - `TestEntityChangeLogMapper`: added `testEntityChangeLogLagExcludesFreshRows` (fresh rows excluded, consumable once aged).
   - Updated `TestEntityChangeLogService` / `TestTableMetaService` for the new mapper signature. All pass; spotless clean.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] fix(core): retry failed entity change log listeners and do not remove logs when polling. [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3664486349


##########
core/src/main/java/org/apache/gravitino/storage/relational/EntityChangeLogCleaner.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.gravitino.storage.relational;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+import org.apache.gravitino.storage.relational.mapper.EntityChangeLogMapper;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Periodically removes expired rows from {@code entity_change_log} on a dedicated thread.

Review Comment:
   Agreed, that failure mode is silent, which makes it worse. `EntityChangeLogCleaner` now takes the poll interval and validates the retention against it at startup:
   
   ```
   retentionMs == 0 (cleanup disabled), or retentionMs >= 10 * pollIntervalMs
   ```
   
   Anything shorter throws `IllegalArgumentException` during initialization instead of silently pruning records before every node consumed them. The bound is 10 poll cycles because a record has to outlive more than a single cycle: a node can miss cycles while restarting, during a long GC pause, or while the poller is paused retrying a failed listener. The comparison uses division rather than multiplication so a large configured poll interval cannot overflow.
   
   Covered by `TestEntityChangeLogCleaner#testRejectsRetentionShorterThanTheConsumptionWindow`, and the constraint is documented for `gravitino.entityChangeLog.retentionSecs` in `docs/gravitino-server-config.md`.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3465618574


##########
core/src/test/java/org/apache/gravitino/storage/relational/mapper/provider/base/TestEntityChangeLogMapper.java:
##########
@@ -150,12 +150,29 @@ void testEntityChangeLogSameTimestampOrderedById() throws SQLException {
     forceCreatedAt("b", 5_000_000L);
     forceCreatedAt("c", 5_000_000L);
 
-    List<EntityChangeRecord> rows = entityChangeLogMapper.selectEntityChanges(0L, 100);
+    List<EntityChangeRecord> rows = entityChangeLogMapper.selectEntityChanges(0L, 0L, 100);
     Assertions.assertEquals(3, rows.size());
     Assertions.assertTrue(rows.get(0).getId() < rows.get(1).getId());
     Assertions.assertTrue(rows.get(1).getId() < rows.get(2).getId());
   }
 
+  @Test
+  void testEntityChangeLogLagExcludesFreshRows() throws SQLException {
+    // A freshly written row is younger than the lag window, so it must not be consumed yet.
+    entityChangeLogMapper.insertEntityChange(
+        "metalake1", "TABLE", "metalake1.cat.schema.fresh", OperateType.ALTER);
+    List<EntityChangeRecord> withLag = entityChangeLogMapper.selectEntityChanges(0L, 60_000L, 100);

Review Comment:
   Changed.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3458217400


##########
core/src/main/java/org/apache/gravitino/storage/relational/EntityChangeLogPoller.java:
##########
@@ -38,8 +38,18 @@
  *
  * <p>The poller owns the single high-water mark for a Gravitino server process and dispatches each
  * consumed batch to registered listeners. Listeners should only perform idempotent local cache
- * invalidation. The cursor always advances after dispatch regardless of individual listener
- * failures, so a faulty listener cannot block other listeners or prevent pruning.
+ * invalidation. A failing listener does not block the other listeners in the same cycle, but the
+ * cursor is <b>not</b> advanced past a batch whose dispatch had any listener failure, so the batch
+ * is retried on the next cycle until every listener succeeds. Because invalidation is idempotent,
+ * re-dispatching an already-applied batch to a healthy listener is harmless.

Review Comment:
   Clarified the wording in `EntityChangeLogPoller`: a failed listener does not prevent other listeners from being invoked in the same cycle, but the shared cursor pauses forward progress until the failed batch is retried successfully. I also bounded the retry wording by the retention window to match the cleanup behavior.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3436729696


##########
core/src/main/java/org/apache/gravitino/Configs.java:
##########
@@ -188,31 +188,46 @@ private Configs() {}
   public static final long DEFAULT_ENTITY_CHANGE_LOG_POLL_INTERVAL_SECS = 3L;
   public static final long DEFAULT_ENTITY_CHANGE_LOG_RETENTION_SECS = 24 * 60 * 60L;
   public static final long DEFAULT_ENTITY_CHANGE_LOG_CLEANUP_INTERVAL_SECS = 60 * 60L;
+  public static final long DEFAULT_ENTITY_CHANGE_LOG_POLL_LAG_SECS = 1L;
 
   public static final ConfigEntry<Long> ENTITY_CHANGE_LOG_POLL_INTERVAL_SECS =
       new ConfigBuilder("gravitino.entityChangeLog.pollIntervalSecs")
           .doc("The interval in seconds for polling entity change logs")
-          .version(ConfigConstants.VERSION_1_3_0)
+          .version(ConfigConstants.VERSION_1_4_0)
           .longConf()
           .checkValue(value -> value > 0, ConfigConstants.POSITIVE_NUMBER_ERROR_MSG)
           .createWithDefault(DEFAULT_ENTITY_CHANGE_LOG_POLL_INTERVAL_SECS);
 
   public static final ConfigEntry<Long> ENTITY_CHANGE_LOG_RETENTION_SECS =
       new ConfigBuilder("gravitino.entityChangeLog.retentionSecs")
           .doc("The retention time in seconds for entity change logs. Set 0 to disable cleanup")
-          .version(ConfigConstants.VERSION_1_3_0)
+          .version(ConfigConstants.VERSION_1_4_0)
           .longConf()
           .checkValue(value -> value >= 0, ConfigConstants.NON_NEGATIVE_NUMBER_ERROR_MSG)
           .createWithDefault(DEFAULT_ENTITY_CHANGE_LOG_RETENTION_SECS);
 
   public static final ConfigEntry<Long> ENTITY_CHANGE_LOG_CLEANUP_INTERVAL_SECS =
       new ConfigBuilder("gravitino.entityChangeLog.cleanupIntervalSecs")
           .doc("The interval in seconds for pruning expired entity change logs")
-          .version(ConfigConstants.VERSION_1_3_0)
+          .version(ConfigConstants.VERSION_1_4_0)
           .longConf()
           .checkValue(value -> value > 0, ConfigConstants.POSITIVE_NUMBER_ERROR_MSG)
           .createWithDefault(DEFAULT_ENTITY_CHANGE_LOG_CLEANUP_INTERVAL_SECS);
 
+  public static final ConfigEntry<Long> ENTITY_CHANGE_LOG_POLL_LAG_SECS =
+      new ConfigBuilder("gravitino.entityChangeLog.pollLagSecs")
+          .doc(
+              "The lag in seconds applied to the entity change log poller. The poller only consumes"
+                  + " change rows older than this lag (measured by the database clock), so all"
+                  + " transactions that started before a consumed row have already committed. This"
+                  + " closes the auto-increment id commit-ordering gap where a lower id may commit"
+                  + " after a higher id. The value should exceed the longest expected write"

Review Comment:
   The config description claims the lag ensures “all transactions that started before a consumed row have already committed”, which isn’t accurate (transactions can start earlier and commit later without having inserted change-log rows yet). Reword to describe the actual guarantee: reducing missed rows due to auto-increment id commit ordering, assuming lag exceeds the longest write transaction.



##########
core/src/main/java/org/apache/gravitino/storage/relational/EntityChangeLogPoller.java:
##########
@@ -77,20 +87,29 @@ public EntityChangeLogPoller(long pollIntervalSecs) {
    * @param pollIntervalSecs interval between successive polling cycles
    * @param retentionMs entity change retention in milliseconds, or 0 to disable cleanup
    * @param cleanupIntervalMs interval between successive cleanup attempts in milliseconds
+   * @param pollLagMs lag in milliseconds; only rows older than this (by the DB clock) are consumed,
+   *     or 0 to disable the lag
    */
-  public EntityChangeLogPoller(long pollIntervalSecs, long retentionMs, long cleanupIntervalMs) {
-    this(pollIntervalSecs, retentionMs, cleanupIntervalMs, System::currentTimeMillis);
+  public EntityChangeLogPoller(
+      long pollIntervalSecs, long retentionMs, long cleanupIntervalMs, long pollLagMs) {
+    this(pollIntervalSecs, retentionMs, cleanupIntervalMs, pollLagMs, System::currentTimeMillis);
   }
 
   @VisibleForTesting
   EntityChangeLogPoller(
-      long pollIntervalSecs, long retentionMs, long cleanupIntervalMs, LongSupplier clockMs) {
+      long pollIntervalSecs,
+      long retentionMs,
+      long cleanupIntervalMs,
+      long pollLagMs,
+      LongSupplier clockMs) {
     Preconditions.checkArgument(pollIntervalSecs > 0, "pollIntervalSecs must be positive");
     Preconditions.checkArgument(retentionMs >= 0, "retentionMs must be non-negative");
     Preconditions.checkArgument(cleanupIntervalMs > 0, "cleanupIntervalMs must be positive");
+    Preconditions.checkArgument(pollLagMs >= 0, "pollLagMs must be non-negative");
     this.pollIntervalSecs = pollIntervalSecs;
     this.retentionMs = retentionMs;
     this.cleanupIntervalMs = cleanupIntervalMs;
+    this.pollLagMs = pollLagMs;

Review Comment:
   Entity-change-log lag can be misconfigured with cleanup enabled: if `retentionMs` is positive but <= `pollLagMs`, rows may become eligible for pruning before they ever become eligible for polling, silently dropping invalidations. Add a cross-field validation to prevent this configuration.



##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/EntityChangeLogBaseSQLProvider.java:
##########
@@ -35,14 +35,29 @@ public class EntityChangeLogBaseSQLProvider {
    * #selectMaxChangeId()} because its cache starts empty and it does not need historical
    * invalidations. Re-consuming a row on an existing instance is acceptable: entity DROP/ALTER
    * handling only invalidates cache keys, and invalidation is idempotent.
+   *
+   * <p>The {@code created_at <= dbNowMs - lagMs} predicate applies a lagging high-water mark.
+   * Auto-increment ids are assigned at INSERT time but become visible at COMMIT time, so a lower id
+   * can commit after a higher id; advancing the cursor purely by the largest committed id can step
+   * over a not-yet-committed lower id and lose its invalidation forever. By only consuming rows
+   * that are at least {@code lagMs} old (measured by the database clock, so there is no app/DB
+   * clock skew), every transaction that started before a consumed row has had at least {@code
+   * lagMs} to commit. As long as {@code lagMs} exceeds the longest write transaction, no lower id

Review Comment:
   The Javadoc explanation says the lag means “every transaction that started before a consumed row has had … to commit”, but the ordering gap is about when earlier-id rows were *inserted* (id assigned) vs committed. Tighten the wording to avoid implying a guarantee about transaction start time.



##########
docs/gravitino-server-config.md:
##########
@@ -57,9 +57,10 @@ The following table lists the storage configuration items:
 | `gravitino.entity.store.maxTransactionSkewTimeMs`  | The maximum skew time of transactions in milliseconds.                                                                                                                                                                                                  | `2000`                            | No                                              | 0.3.0            |
 | `gravitino.entity.store.deleteAfterTimeMs`         | The maximum time in milliseconds that deleted and old-version data is kept. Set to at least 10 minutes and no longer than 30 days.                                                                                                                      | `604800000`(7 days)               | No                                              | 0.5.0            |
 | `gravitino.entity.store.versionRetentionCount`     | The Count of versions allowed to be retained, including the current version, used to delete old versions data. Set to at least 1 and no greater than 10.                                                                                                | `1`                               | No                                              | 0.5.0            |
-| `gravitino.entityChangeLog.pollIntervalSecs`       | The interval in seconds for polling the entity change log. The poller invalidates stale local caches (e.g. the catalog cache) across HA nodes by consuming change log records. Must be positive.                                                        | `3`                               | No                                              | 1.3.0            |
-| `gravitino.entityChangeLog.retentionSecs`          | The retention time in seconds for entity change log rows. Expired rows are pruned periodically. Set to `0` to disable automatic cleanup. Must be non-negative.                                                                                          | `86400`(1 day)                    | No                                              | 1.3.0            |
-| `gravitino.entityChangeLog.cleanupIntervalSecs`    | The interval in seconds for pruning expired entity change log rows. Must be positive.                                                                                                                                                                   | `3600`(1 hour)                    | No                                              | 1.3.0            |
+| `gravitino.entityChangeLog.pollIntervalSecs`       | The interval in seconds for polling the entity change log. The poller invalidates stale local caches (e.g. the catalog cache) across HA nodes by consuming change log records. Must be positive.                                                        | `3`                               | No                                              | 1.4.0            |
+| `gravitino.entityChangeLog.retentionSecs`          | The retention time in seconds for entity change log rows. Expired rows are pruned periodically. Set to `0` to disable automatic cleanup. Must be non-negative.                                                                                          | `86400`(1 day)                    | No                                              | 1.4.0            |
+| `gravitino.entityChangeLog.cleanupIntervalSecs`    | The interval in seconds for pruning expired entity change log rows. Must be positive.                                                                                                                                                                   | `3600`(1 hour)                    | No                                              | 1.4.0            |
+| `gravitino.entityChangeLog.pollLagSecs`            | The lag in seconds applied to the entity change log poller. Only change rows older than this (by the database clock) are consumed, so all transactions that started before a consumed row have committed. This closes the auto-increment id commit-ordering gap where a lower id may commit after a higher id. Should exceed the longest write transaction. Set to `0` to disable. Must be non-negative. | `1`                               | No                                              | 1.4.0            |

Review Comment:
   The docs text claims the lag ensures “all transactions that started before a consumed row have committed”, which isn’t accurate (the commit-ordering issue is about earlier-id rows being inserted before they commit). Reword to describe the actual effect: consuming only sufficiently-aged rows to reduce missed invalidations due to out-of-order commits (assuming lag exceeds the longest write transaction).



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3473094241


##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/EntityChangeLogBaseSQLProvider.java:
##########
@@ -35,14 +35,31 @@ public class EntityChangeLogBaseSQLProvider {
    * #selectMaxChangeId()} because its cache starts empty and it does not need historical
    * invalidations. Re-consuming a row on an existing instance is acceptable: entity DROP/ALTER
    * handling only invalidates cache keys, and invalidation is idempotent.
+   *
+   * <p>The {@code created_at <= dbNowMs - lagMs} predicate applies a lagging high-water mark.
+   * Auto-increment ids are assigned at INSERT time but become visible at COMMIT time, so a lower id
+   * can commit after a higher id; advancing the cursor purely by the largest committed id can step

Review Comment:
   Yes — id is BIGINT AUTO_INCREMENT (MySQL) / BIGSERIAL (PG). The id is set when the INSERT runs, but the row is only visible after COMMIT. The change-log insert commits together with the rest of the metadata write (the soft-deletes etc.), so a lower id can become visible after a higher id that committed first. An id-only cursor can then jump over the lower id before it shows up and drop its invalidation for good. So the gap is real.
   
   The following is an example:
   
   ```text
   Transaction A starts → INSERT gets id=10 (slow transaction, late commit)
   Transaction B starts → INSERT gets id=11, fast COMMIT
   Poller runs: sees id=11 (committed), cursor advances to 11
   Transaction A finally COMMIT, id=10 becomes visible
   Poller next check WHERE id > 11 → id=10 never seen ❌ Failure information permanently lost
   ```



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 closed pull request #11739: [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance
URL: https://github.com/apache/gravitino/pull/11739


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] fix(core): retry failed entity change log listeners and do not remove logs when polling. [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 merged PR #11739:
URL: https://github.com/apache/gravitino/pull/11739


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3470370148


##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/EntityChangeLogBaseSQLProvider.java:
##########
@@ -35,14 +35,31 @@ public class EntityChangeLogBaseSQLProvider {
    * #selectMaxChangeId()} because its cache starts empty and it does not need historical
    * invalidations. Re-consuming a row on an existing instance is acceptable: entity DROP/ALTER
    * handling only invalidates cache keys, and invalidation is idempotent.
+   *
+   * <p>The {@code created_at <= dbNowMs - lagMs} predicate applies a lagging high-water mark.
+   * Auto-increment ids are assigned at INSERT time but become visible at COMMIT time, so a lower id
+   * can commit after a higher id; advancing the cursor purely by the largest committed id can step

Review Comment:
   How could this be happened, is this a auto incremental id?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3465596194


##########
core/src/main/java/org/apache/gravitino/storage/relational/EntityChangeLogPoller.java:
##########
@@ -183,22 +215,31 @@ private synchronized void doPollChanges() {
     }
 
     List<EntityChangeRecord> dispatchedChanges = Collections.unmodifiableList(changes);
+    boolean allListenersSucceeded = true;
     for (EntityChangeLogListener listener : listeners) {
       try {
         listener.onEntityChange(dispatchedChanges);
       } catch (Exception e) {
+        allListenersSucceeded = false;
         LOG.warn("Entity change listener {} failed", listener.getClass().getName(), e);

Review Comment:
   I'm hesitant about these two levels and adopt the suggestion.



##########
core/src/main/java/org/apache/gravitino/storage/relational/EntityChangeLogPoller.java:
##########
@@ -77,20 +93,36 @@ public EntityChangeLogPoller(long pollIntervalSecs) {
    * @param pollIntervalSecs interval between successive polling cycles
    * @param retentionMs entity change retention in milliseconds, or 0 to disable cleanup
    * @param cleanupIntervalMs interval between successive cleanup attempts in milliseconds
+   * @param pollLagMs lag in milliseconds; only rows older than this (by the DB clock) are consumed,
+   *     or 0 to disable the lag
    */
-  public EntityChangeLogPoller(long pollIntervalSecs, long retentionMs, long cleanupIntervalMs) {
-    this(pollIntervalSecs, retentionMs, cleanupIntervalMs, System::currentTimeMillis);
+  public EntityChangeLogPoller(
+      long pollIntervalSecs, long retentionMs, long cleanupIntervalMs, long pollLagMs) {
+    this(pollIntervalSecs, retentionMs, cleanupIntervalMs, pollLagMs, System::currentTimeMillis);
   }
 

Review Comment:
   OK



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] fix(core): retry failed entity change log listeners and do not remove logs when polling. [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#issuecomment-5091414063

   @roryqi 
   Can you help to review this one?


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] fix(core): retry failed entity change log listeners and do not remove logs when polling. [gravitino]

Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3664124130


##########
core/src/main/java/org/apache/gravitino/storage/relational/EntityChangeLogCleaner.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.gravitino.storage.relational;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+import org.apache.gravitino.storage.relational.mapper.EntityChangeLogMapper;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Periodically removes expired rows from {@code entity_change_log} on a dedicated thread.

Review Comment:
   If we use unreasonable parameter, it may cause the changes lost
   Could u add the parameter for the similar cases?



##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/EntityChangeLogPostgreSQLProvider.java:
##########
@@ -26,6 +27,13 @@
 
 public class EntityChangeLogPostgreSQLProvider extends EntityChangeLogBaseSQLProvider {
 
+  /**
+   * PostgreSQL flavour of the DB-side "now in milliseconds" expression. Insertion and expiration
+   * share it, so retention is measured entirely with the database clock.
+   */
+  private static final String CURRENT_TIME_MILLIS_SQL =

Review Comment:
   It would better to put it a better place. Other class can reuse this constant easily.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3470474789


##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/EntityChangeLogBaseSQLProvider.java:
##########
@@ -35,14 +35,31 @@ public class EntityChangeLogBaseSQLProvider {
    * #selectMaxChangeId()} because its cache starts empty and it does not need historical
    * invalidations. Re-consuming a row on an existing instance is acceptable: entity DROP/ALTER
    * handling only invalidates cache keys, and invalidation is idempotent.
+   *
+   * <p>The {@code created_at <= dbNowMs - lagMs} predicate applies a lagging high-water mark.
+   * Auto-increment ids are assigned at INSERT time but become visible at COMMIT time, so a lower id
+   * can commit after a higher id; advancing the cursor purely by the largest committed id can step
+   * over a not-yet-committed lower id and lose its invalidation forever. A smaller-id row was
+   * necessarily inserted no later than a larger-id row, so by only consuming rows whose {@code
+   * created_at} is at least {@code lagMs} in the past (measured by the database clock, so there is

Review Comment:
   How do you know that 1 sec lag is enough? If for example, we hit minor or major gc in the Gravitino side, the id committed should be late. In this case, is it enough for just 1 second by default?
   
   My feeling is that instead of adding a lag. We should make sure that the id we insert is incremental. And what the reader gets is always sequential.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3474293606


##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/EntityChangeLogBaseSQLProvider.java:
##########
@@ -35,14 +35,31 @@ public class EntityChangeLogBaseSQLProvider {
    * #selectMaxChangeId()} because its cache starts empty and it does not need historical
    * invalidations. Re-consuming a row on an existing instance is acceptable: entity DROP/ALTER
    * handling only invalidates cache keys, and invalidation is idempotent.
+   *
+   * <p>The {@code created_at <= dbNowMs - lagMs} predicate applies a lagging high-water mark.
+   * Auto-increment ids are assigned at INSERT time but become visible at COMMIT time, so a lower id
+   * can commit after a higher id; advancing the cursor purely by the largest committed id can step
+   * over a not-yet-committed lower id and lose its invalidation forever. A smaller-id row was
+   * necessarily inserted no later than a larger-id row, so by only consuming rows whose {@code
+   * created_at} is at least {@code lagMs} in the past (measured by the database clock, so there is

Review Comment:
   I reworked it. The cursor is now created_at instead of id, and every cycle it re-reads a small window before the cursor:
   
   ```sql
     WHERE created_at > #{watermarkMs} - #{overlapMs} ORDER BY created_at, id
   ```
   
   So if a row commits late (its created_at is behind the cursor), the next poll re-reads that window and picks it up, instead of skipping it forever. Re-reading a row we already handled is safe because invalidation is idempotent.
   
   About your "make the ids the reader sees always in order" idea: I did not go that way because auto-increment ids are not reused after a rollback, so a rolled-back id never shows up and the reader would wait on it forever. The overlap window avoids that problem.
   
   One thing I want to be clear about: the overlap does not add delay. A new change is still applied within one poll interval. The overlap only re-scans the past window to catch late commits, it does not hold back new rows
   (this is the difference from the old lag).
   
   Config renamed pollLagSecs -> pollOverlapSecs (default 30s, should be larger than the longest INSERT-to-COMMIT time). Done in the latest commit.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] fix(core): retry failed entity change log listeners and do not remove logs when polling. [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3664481832


##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/EntityChangeLogPostgreSQLProvider.java:
##########
@@ -26,6 +27,13 @@
 
 public class EntityChangeLogPostgreSQLProvider extends EntityChangeLogBaseSQLProvider {
 
+  /**
+   * PostgreSQL flavour of the DB-side "now in milliseconds" expression. Insertion and expiration
+   * share it, so retention is measured entirely with the database clock.
+   */
+  private static final String CURRENT_TIME_MILLIS_SQL =

Review Comment:
   Good point, done. I moved both flavours into `org.apache.gravitino.storage.relational.mapper.provider.DatabaseTimeSQL`, which sits in the package shared by the `base`, `h2` and `postgresql` provider packages, so any provider can reuse them: `DatabaseTimeSQL.MYSQL` and `DatabaseTimeSQL.POSTGRESQL`. The entity change log providers now reference the constants.
   
   I did not migrate the other providers in this PR on purpose. The same literals are inlined 114 times across 32 files (MySQL flavour) and 107 times across 31 files (PostgreSQL flavour), so replacing them all here would bury this PR's actual fix under a large mechanical diff. Filed #12236 to do that separately.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] fix(core): retry failed entity change log listeners and do not remove logs when polling. [gravitino]

Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#issuecomment-5092043165

   > @roryqi Can you help to review this one?
   
   I  will take a  look.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#issuecomment-4743552473

   Thanks for the review — addressed in e85067982:
   
   1. **Cross-field validation (EntityChangeLogPoller):** the constructor now rejects `retentionMs <= pollLagMs` when cleanup is enabled (`retentionMs > 0`), so a row can never be pruned before it becomes eligible for polling. Added `testRejectsRetentionNotGreaterThanLag`.
   2. **Config / Javadoc / docs wording (Configs, EntityChangeLogBaseSQLProvider, gravitino-server-config.md):** dropped the inaccurate "all transactions that started before a consumed row have committed" claim. The wording now states the actual guarantee: a smaller-id row is inserted no later than a larger-id row, so waiting until a row is `pollLagMs` old gives that row's *inserting* transaction time to commit before the cursor advances past it — preventing the commit-ordering gap as long as the lag exceeds the longest write transaction.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3452813084


##########
core/src/main/java/org/apache/gravitino/storage/relational/EntityChangeLogPoller.java:
##########
@@ -38,8 +38,18 @@
  *
  * <p>The poller owns the single high-water mark for a Gravitino server process and dispatches each
  * consumed batch to registered listeners. Listeners should only perform idempotent local cache
- * invalidation. The cursor always advances after dispatch regardless of individual listener
- * failures, so a faulty listener cannot block other listeners or prevent pruning.
+ * invalidation. A failing listener does not block the other listeners in the same cycle, but the
+ * cursor is <b>not</b> advanced past a batch whose dispatch had any listener failure, so the batch
+ * is retried on the next cycle until every listener succeeds. Because invalidation is idempotent,
+ * re-dispatching an already-applied batch to a healthy listener is harmless.

Review Comment:
   The class-level Javadoc says a failing listener "does not block" other listeners, but with a single shared cursor the poller cannot progress to newer change-log rows until all listeners succeed (it will keep re-fetching and redispatching the same batch). Clarify the wording so readers/operators understand that other listeners are still invoked in the same cycle, but forward progress is paused until recovery.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3473099804


##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/EntityChangeLogBaseSQLProvider.java:
##########
@@ -35,14 +35,31 @@ public class EntityChangeLogBaseSQLProvider {
    * #selectMaxChangeId()} because its cache starts empty and it does not need historical
    * invalidations. Re-consuming a row on an existing instance is acceptable: entity DROP/ALTER
    * handling only invalidates cache keys, and invalidation is idempotent.
+   *
+   * <p>The {@code created_at <= dbNowMs - lagMs} predicate applies a lagging high-water mark.
+   * Auto-increment ids are assigned at INSERT time but become visible at COMMIT time, so a lower id
+   * can commit after a higher id; advancing the cursor purely by the largest committed id can step
+   * over a not-yet-committed lower id and lose its invalidation forever. A smaller-id row was
+   * necessarily inserted no later than a larger-id row, so by only consuming rows whose {@code
+   * created_at} is at least {@code lagMs} in the past (measured by the database clock, so there is

Review Comment:
   The lag is just a best-effort guess, not a guarantee. It has to be bigger than the longest time between a row's INSERT and its COMMIT, and a GC pause, a lock wait, a slow disk write, or a long transaction can easily push that past 1s. When it does, the gap comes back and the invalidation is lost silently. So a fixed 1s default is fragile.
   
   I will try to think about it again to gain a better solution. 



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#issuecomment-4787956811

   > The lag is only applied on the regular polling path. `start()` still initializes `entityPollHighWaterId` from unlagged `selectMaxChangeId()`, so a restart can still skip a lower id that was inserted but uncommitted while a higher id was already committed. Once the cursor is initialized past that lower id, the lagged polling query cannot recover it. The startup cursor should be initialized using the same lagged/eligible boundary.
   
   Changed `selectMaxChangeId`.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#issuecomment-4752945335

   <!-- coverage-report -->
   ### Code Coverage Report
   |Overall Project|67.16% **`+0.13%`**|:green_circle:|
   |:-|:-|:-:|
   |Files changed|84.39%|:green_circle:|
   <br>
   
   |Module|Coverage||
   |:-|:-|:-:|
   |aliyun|1.72%|:red_circle:|
   |api|46.82%|:green_circle:|
   |authorization-common|85.96%|:green_circle:|
   |aws|3.66%|:red_circle:|
   |azure|2.47%|:red_circle:|
   |catalog-common|10.4%|:red_circle:|
   |catalog-fileset|80.23%|:green_circle:|
   |catalog-glue|66.91%|:green_circle:|
   |catalog-hive|79.42%|:green_circle:|
   |catalog-jdbc-clickhouse|80.02%|:green_circle:|
   |catalog-jdbc-common|44.22%|:green_circle:|
   |catalog-jdbc-doris|80.28%|:green_circle:|
   |catalog-jdbc-hologres|54.03%|:green_circle:|
   |catalog-jdbc-mysql|79.23%|:green_circle:|
   |catalog-jdbc-oceanbase|78.38%|:green_circle:|
   |catalog-jdbc-postgresql|82.29%|:green_circle:|
   |catalog-jdbc-starrocks|78.51%|:green_circle:|
   |catalog-kafka|77.01%|:green_circle:|
   |catalog-lakehouse-generic|58.53%|:green_circle:|
   |catalog-lakehouse-hudi|79.1%|:green_circle:|
   |catalog-lakehouse-iceberg|85.94%|:green_circle:|
   |catalog-lakehouse-paimon|82.14%|:green_circle:|
   |catalog-model|77.72%|:green_circle:|
   |cli|44.51%|:green_circle:|
   |client-java|78.01%|:green_circle:|
   |common|50.17%|:green_circle:|
   |core|82.6% **`+0.05%`**|:green_circle:|
   |filesystem-hadoop3|77.27%|:green_circle:|
   |flink|0.0%|:red_circle:|
   |flink-common|47.12%|:green_circle:|
   |flink-runtime|0.0%|:red_circle:|
   |gcp|14.12%|:red_circle:|
   |hadoop-common|10.88%|:red_circle:|
   |hive-metastore-common|53.77%|:green_circle:|
   |iceberg-common|58.15%|:green_circle:|
   |iceberg-rest-server|73.9%|:green_circle:|
   |idp-basic|86.2%|:green_circle:|
   |integration-test-common|0.0%|:red_circle:|
   |jobs|66.17%|:green_circle:|
   |lance-common|20.83%|:red_circle:|
   |lance-rest-server|60.13%|:green_circle:|
   |lineage|53.02%|:green_circle:|
   |optimizer|82.95%|:green_circle:|
   |optimizer-api|21.95%|:red_circle:|
   |server|86.09%|:green_circle:|
   |server-common|74.18%|:green_circle:|
   |spark|28.57%|:red_circle:|
   |spark-common|41.66%|:green_circle:|
   |trino-connector|40.13%|:green_circle:|
   
   <details>
   <summary>Files</summary>
   
   |Module|File|Coverage||
   |:-|:-|:-|:-:|
   |common|[ConfigConstants.java](https://github.com/apache/gravitino/blob/648a8c34efe27ec108bb932b562e214d5b77dd00/common/src/main/java/org/apache/gravitino/config/ConfigConstants.java)|0.0%|:red_circle:|
   |core|[EntityChangeLogBaseSQLProvider.java](https://github.com/apache/gravitino/blob/648a8c34efe27ec108bb932b562e214d5b77dd00/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/EntityChangeLogBaseSQLProvider.java)|100.0%|:green_circle:|
   ||[Configs.java](https://github.com/apache/gravitino/blob/648a8c34efe27ec108bb932b562e214d5b77dd00/core/src/main/java/org/apache/gravitino/Configs.java)|98.08%|:green_circle:|
   ||[EntityChangeLogSQLProviderFactory.java](https://github.com/apache/gravitino/blob/648a8c34efe27ec108bb932b562e214d5b77dd00/core/src/main/java/org/apache/gravitino/storage/relational/mapper/EntityChangeLogSQLProviderFactory.java)|93.33%|:green_circle:|
   ||[EntityChangeLogPoller.java](https://github.com/apache/gravitino/blob/648a8c34efe27ec108bb932b562e214d5b77dd00/core/src/main/java/org/apache/gravitino/storage/relational/EntityChangeLogPoller.java)|85.58%|:green_circle:|
   ||[EntityChangeLogPostgreSQLProvider.java](https://github.com/apache/gravitino/blob/648a8c34efe27ec108bb932b562e214d5b77dd00/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/EntityChangeLogPostgreSQLProvider.java)|75.0%|:green_circle:|
   ||[RelationalEntityStore.java](https://github.com/apache/gravitino/blob/648a8c34efe27ec108bb932b562e214d5b77dd00/core/src/main/java/org/apache/gravitino/storage/relational/RelationalEntityStore.java)|62.14%|:green_circle:|
   ||[EntityChangeLogMapper.java](https://github.com/apache/gravitino/blob/648a8c34efe27ec108bb932b562e214d5b77dd00/core/src/main/java/org/apache/gravitino/storage/relational/mapper/EntityChangeLogMapper.java)|0.0%|:red_circle:|
   
   </details>


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3465591937


##########
core/src/main/java/org/apache/gravitino/storage/relational/EntityChangeLogPoller.java:
##########
@@ -68,6 +83,7 @@ public EntityChangeLogPoller(long pollIntervalSecs) {
         pollIntervalSecs,
         TimeUnit.DAYS.toMillis(1),
         TimeUnit.HOURS.toMillis(1),
+        TimeUnit.SECONDS.toMillis(1),
         System::currentTimeMillis);

Review Comment:
   OK, it makes sense. 



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3470310062


##########
common/src/main/java/org/apache/gravitino/config/ConfigConstants.java:
##########
@@ -92,6 +92,9 @@ private ConfigConstants() {}
   /** The version number for the 1.3.0 release. */
   public static final String VERSION_1_3_0 = "1.3.0";
 
+  /** The version number for the 1.4.0 release. */
+  public static final String VERSION_1_4_0 = "1.4.0";

Review Comment:
   Our next release will be 2.0.0, you probably need to update this.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3474312540


##########
common/src/main/java/org/apache/gravitino/config/ConfigConstants.java:
##########
@@ -92,6 +92,9 @@ private ConfigConstants() {}
   /** The version number for the 1.3.0 release. */
   public static final String VERSION_1_3_0 = "1.3.0";
 
+  /** The version number for the 1.4.0 release. */
+  public static final String VERSION_1_4_0 = "1.4.0";

Review Comment:
   modified.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11736] improvement(core): Close EntityChangeLogPoller commit-ordering gap and listener-failure cursor advance [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11739:
URL: https://github.com/apache/gravitino/pull/11739#discussion_r3463388633


##########
core/src/test/java/org/apache/gravitino/storage/relational/mapper/provider/base/TestEntityChangeLogMapper.java:
##########
@@ -150,12 +150,29 @@ void testEntityChangeLogSameTimestampOrderedById() throws SQLException {
     forceCreatedAt("b", 5_000_000L);
     forceCreatedAt("c", 5_000_000L);
 
-    List<EntityChangeRecord> rows = entityChangeLogMapper.selectEntityChanges(0L, 100);
+    List<EntityChangeRecord> rows = entityChangeLogMapper.selectEntityChanges(0L, 0L, 100);
     Assertions.assertEquals(3, rows.size());
     Assertions.assertTrue(rows.get(0).getId() < rows.get(1).getId());
     Assertions.assertTrue(rows.get(1).getId() < rows.get(2).getId());
   }
 
+  @Test
+  void testEntityChangeLogLagExcludesFreshRows() throws SQLException {
+    // A freshly written row is younger than the lag window, so it must not be consumed yet.
+    entityChangeLogMapper.insertEntityChange(
+        "metalake1", "TABLE", "metalake1.cat.schema.fresh", OperateType.ALTER);
+    List<EntityChangeRecord> withLag = entityChangeLogMapper.selectEntityChanges(0L, 60_000L, 100);

Review Comment:
   **Minor: `lagMs = 0` ("disable lag") path not explicitly asserted in this new test.**
   
   Since `lagMs = 0` is the documented contract for users who set `pollLagSecs = 0`, a brief assertion that a fresh row IS immediately returned with `lagMs = 0` would pin the zero-lag SQL behaviour at the mapper level:
   
   ```java
   // lagMs = 0 disables the filter — fresh rows must be consumable immediately
   List<EntityChangeRecord> noLag = entityChangeLogMapper.selectEntityChanges(0L, 0L, 100);
   Assertions.assertFalse(noLag.isEmpty(), "lagMs=0 should return the fresh row");
   ```



##########
core/src/main/java/org/apache/gravitino/storage/relational/EntityChangeLogPoller.java:
##########
@@ -183,22 +215,31 @@ private synchronized void doPollChanges() {
     }
 
     List<EntityChangeRecord> dispatchedChanges = Collections.unmodifiableList(changes);
+    boolean allListenersSucceeded = true;
     for (EntityChangeLogListener listener : listeners) {
       try {
         listener.onEntityChange(dispatchedChanges);
       } catch (Exception e) {
+        allListenersSucceeded = false;
         LOG.warn("Entity change listener {} failed", listener.getClass().getName(), e);

Review Comment:
   **Concern: `LOG.warn` is likely too quiet for a persistent listener failure.**
   
   With the new cursor semantics, a listener failure blocks forward progress for ALL new change rows. If a listener fails on every cycle, the cache silently serves stale data until it recovers — or until retention cleanup prunes the stuck rows, at which point the invalidations are permanently lost. A single `WARN` per cycle is easy to miss in production.
   
   Consider escalating to `LOG.error`, or tracking a consecutive-failure counter per listener and switching to `LOG.error` after N failures. At that point the operator has a closing window (bounded by `retentionMs / pollIntervalMs` cycles) before invalidations are permanently dropped.



##########
core/src/main/java/org/apache/gravitino/storage/relational/EntityChangeLogPoller.java:
##########
@@ -77,20 +93,36 @@ public EntityChangeLogPoller(long pollIntervalSecs) {
    * @param pollIntervalSecs interval between successive polling cycles
    * @param retentionMs entity change retention in milliseconds, or 0 to disable cleanup
    * @param cleanupIntervalMs interval between successive cleanup attempts in milliseconds
+   * @param pollLagMs lag in milliseconds; only rows older than this (by the DB clock) are consumed,
+   *     or 0 to disable the lag
    */
-  public EntityChangeLogPoller(long pollIntervalSecs, long retentionMs, long cleanupIntervalMs) {
-    this(pollIntervalSecs, retentionMs, cleanupIntervalMs, System::currentTimeMillis);
+  public EntityChangeLogPoller(
+      long pollIntervalSecs, long retentionMs, long cleanupIntervalMs, long pollLagMs) {
+    this(pollIntervalSecs, retentionMs, cleanupIntervalMs, pollLagMs, System::currentTimeMillis);
   }
 

Review Comment:
   **Minor: Preconditions error message omits the actual values.**
   
   ```java
   "retentionMs must be greater than pollLagMs when cleanup is enabled"
   ```
   
   When this fires at startup the operator sees an `IllegalArgumentException` without knowing which values triggered it. Prefer:
   
   ```java
   String.format(
       "retentionMs (%d) must be greater than pollLagMs (%d) when cleanup is enabled",
       retentionMs, pollLagMs)
   ```



##########
core/src/main/java/org/apache/gravitino/storage/relational/EntityChangeLogPoller.java:
##########
@@ -68,6 +83,7 @@ public EntityChangeLogPoller(long pollIntervalSecs) {
         pollIntervalSecs,
         TimeUnit.DAYS.toMillis(1),
         TimeUnit.HOURS.toMillis(1),
+        TimeUnit.SECONDS.toMillis(1),
         System::currentTimeMillis);

Review Comment:
   **Style: hardcoded `1` should reference `DEFAULT_ENTITY_CHANGE_LOG_POLL_LAG_SECS`.**
   
   This repeats the magic value that is also defined in `Configs.DEFAULT_ENTITY_CHANGE_LOG_POLL_LAG_SECS`. If the default is ever changed in `Configs`, this single-arg constructor is silently left inconsistent.
   
   ```java
   // Prefer
   TimeUnit.SECONDS.toMillis(DEFAULT_ENTITY_CHANGE_LOG_POLL_LAG_SECS),
   ```



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org