You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by sn...@apache.org on 2026/05/22 06:33:30 UTC

(polaris) branch main updated: NoSQL: Reject non-positive reference history sizing (#4505)

This is an automated email from the ASF dual-hosted git repository.

snazy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git


The following commit(s) were added to refs/heads/main by this push:
     new ee41b0eb1a NoSQL: Reject non-positive reference history sizing (#4505)
ee41b0eb1a is described below

commit ee41b0eb1a543fe89a7f827e081412bb4a170a50
Author: Robert Stupp <sn...@snazy.de>
AuthorDate: Fri May 22 08:33:26 2026 +0200

    NoSQL: Reject non-positive reference history sizing (#4505)
    
    Reject zero or negative reference history sizes when building the persistence
    implementation.
    
    That setting is supposed to bound retained reference history. Non-positive
    values only produce nonsense later, so it is better to fail during
    initialization.
---
 .../nosql/impl/PersistenceImplementation.java      |  2 +
 .../nosql/impl/TestPersistenceImplementation.java  | 57 ++++++++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git a/persistence/nosql/persistence/impl/src/main/java/org/apache/polaris/persistence/nosql/impl/PersistenceImplementation.java b/persistence/nosql/persistence/impl/src/main/java/org/apache/polaris/persistence/nosql/impl/PersistenceImplementation.java
index 9e98a4eec0..d5024aa50a 100644
--- a/persistence/nosql/persistence/impl/src/main/java/org/apache/polaris/persistence/nosql/impl/PersistenceImplementation.java
+++ b/persistence/nosql/persistence/impl/src/main/java/org/apache/polaris/persistence/nosql/impl/PersistenceImplementation.java
@@ -104,6 +104,8 @@ public final class PersistenceImplementation implements Persistence {
       String realmId,
       MonotonicClock monotonicClock,
       IdGenerator idGenerator) {
+    checkArgument(
+        params.referencePreviousHeadCount() > 0, "referencePreviousHeadCount must be positive");
 
     this.backend = backend;
     this.params = params;
diff --git a/persistence/nosql/persistence/impl/src/test/java/org/apache/polaris/persistence/nosql/impl/TestPersistenceImplementation.java b/persistence/nosql/persistence/impl/src/test/java/org/apache/polaris/persistence/nosql/impl/TestPersistenceImplementation.java
new file mode 100644
index 0000000000..d1da9f7678
--- /dev/null
+++ b/persistence/nosql/persistence/impl/src/test/java/org/apache/polaris/persistence/nosql/impl/TestPersistenceImplementation.java
@@ -0,0 +1,57 @@
+/*
+ * 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.impl;
+
+import static org.mockito.Mockito.mock;
+
+import org.apache.polaris.ids.api.IdGenerator;
+import org.apache.polaris.ids.api.MonotonicClock;
+import org.apache.polaris.persistence.nosql.api.PersistenceParams;
+import org.apache.polaris.persistence.nosql.api.backend.Backend;
+import org.assertj.core.api.SoftAssertions;
+import org.assertj.core.api.junit.jupiter.InjectSoftAssertions;
+import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+@ExtendWith(SoftAssertionsExtension.class)
+public class TestPersistenceImplementation {
+  @InjectSoftAssertions SoftAssertions soft;
+
+  @ParameterizedTest
+  @ValueSource(ints = {0, -1})
+  public void referencePreviousHeadCountMustBePositive(int count) {
+    var params =
+        PersistenceParams.BuildablePersistenceParams.builder()
+            .referencePreviousHeadCount(count)
+            .build();
+
+    soft.assertThatIllegalArgumentException()
+        .isThrownBy(
+            () ->
+                new PersistenceImplementation(
+                    mock(Backend.class),
+                    params,
+                    "realm",
+                    mock(MonotonicClock.class),
+                    IdGenerator.NONE))
+        .withMessage("referencePreviousHeadCount must be positive");
+  }
+}