dimas-b commented on code in PR #5135:
URL: https://github.com/apache/polaris/pull/5135#discussion_r3641758596


##########
persistence/nosql/persistence/metastore-maintenance/src/main/java/org/apache/polaris/persistence/nosql/metastore/maintenance/CatalogRetainedIdentifier.java:
##########
@@ -725,4 +699,18 @@ private Optional<Index<IndexKey>> 
stableIdIndex(RefIndexKey key) {
   }
 
   private record RefIndexKey(String refName, Class<? extends ContainerObj> 
containerClass) {}
+
+  static <O> Predicate<O> retainLatest(int commitsToRetain) {
+    if (commitsToRetain < 1) {
+      throw new IllegalArgumentException("commitsToRetain must be at least 1");
+    }
+    return new Predicate<>() {
+      private int remaining = commitsToRetain;
+
+      @Override
+      public boolean test(O ignored) {
+        return --remaining > 0;

Review Comment:
   This can underflow (after many calls).



##########
persistence/nosql/persistence/metastore-maintenance/src/test/java/org/apache/polaris/persistence/nosql/metastore/maintenance/TestCommitRetention.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.persistence.nosql.metastore.maintenance;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static 
org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+
+import org.junit.jupiter.api.Test;
+
+class TestCommitRetention {
+
+  @Test
+  void retainsConfiguredNumberOfCommits() {
+    var retainOne = CatalogRetainedIdentifier.<Object>retainLatest(1);
+    assertThat(retainOne.test(new Object())).isFalse();
+
+    var retainThree = CatalogRetainedIdentifier.<Object>retainLatest(3);
+    assertThat(retainThree.test(new Object())).isTrue();
+    assertThat(retainThree.test(new Object())).isTrue();
+    assertThat(retainThree.test(new Object())).isFalse();

Review Comment:
   This is a bit misleading. I'd expect three `test` calls to return `true` 🤔 
   
   E.g. the old CEL expression `commits <= 3` would be `true` on three calls, 
right?



##########
site/content/in-dev/unreleased/admin-tool.md:
##########
@@ -230,6 +230,14 @@ Maintenance covers the deletion of stale database entries.
 It is recommended to run the `nosql maintenance-run` command regulary, for 
example, once per day.
 {{< /alert >}}
 
+{{< alert important >}}
+The catalog-history `*-retain` settings now accept a positive integer number 
of latest commits
+instead of a CEL expression. When upgrading, replace `*-retain=false` with 
`*-retain=1`.
+CEL values such as `true` and expressions using `ageDays`, `ageHours`, or 
`ageMinutes` are no
+longer supported. There is no unbounded or time-based equivalent; choose an 
explicit commit count

Review Comment:
   This looks like a reasonable compromise 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