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

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new d516ef625 [hotfix] Add incrementSafely in MathUtils (#2840)
d516ef625 is described below

commit d516ef62550f07d378b4423c144abb075eceba28
Author: Zouxxyy <[email protected]>
AuthorDate: Fri Feb 2 14:08:03 2024 +0800

    [hotfix] Add incrementSafely in MathUtils (#2840)
---
 paimon-common/src/main/java/org/apache/paimon/CoreOptions.java | 10 ++++++----
 .../src/main/java/org/apache/paimon/utils/MathUtils.java       |  8 ++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/paimon-common/src/main/java/org/apache/paimon/CoreOptions.java 
b/paimon-common/src/main/java/org/apache/paimon/CoreOptions.java
index 3e37a0935..5fa99fb82 100644
--- a/paimon-common/src/main/java/org/apache/paimon/CoreOptions.java
+++ b/paimon-common/src/main/java/org/apache/paimon/CoreOptions.java
@@ -30,6 +30,7 @@ import org.apache.paimon.options.OptionsUtils;
 import org.apache.paimon.options.description.DescribedEnum;
 import org.apache.paimon.options.description.Description;
 import org.apache.paimon.options.description.InlineElement;
+import org.apache.paimon.utils.MathUtils;
 import org.apache.paimon.utils.Pair;
 import org.apache.paimon.utils.StringUtils;
 
@@ -1258,8 +1259,7 @@ public class CoreOptions implements Serializable {
     public int sortSpillThreshold() {
         Integer maxSortedRunNum = options.get(SORT_SPILL_THRESHOLD);
         if (maxSortedRunNum == null) {
-            int stopNum = numSortedRunStopTrigger();
-            maxSortedRunNum = Math.max(stopNum, stopNum + 1);
+            maxSortedRunNum = 
MathUtils.incrementSafely(numSortedRunStopTrigger());
         }
         checkArgument(maxSortedRunNum > 1, "The sort spill threshold cannot be 
smaller than 2.");
         return maxSortedRunNum;
@@ -1345,7 +1345,7 @@ public class CoreOptions implements Serializable {
     public int numSortedRunStopTrigger() {
         Integer stopTrigger = options.get(NUM_SORTED_RUNS_STOP_TRIGGER);
         if (stopTrigger == null) {
-            stopTrigger = numSortedRunCompactionTrigger() + 1;
+            stopTrigger = 
MathUtils.incrementSafely(numSortedRunCompactionTrigger());
         }
         return Math.max(numSortedRunCompactionTrigger(), stopTrigger);
     }
@@ -1354,7 +1354,9 @@ public class CoreOptions implements Serializable {
         // By default, this ensures that the compaction does not fall to level 
0, but at least to
         // level 1
         Integer numLevels = options.get(NUM_LEVELS);
-        numLevels = numLevels == null ? numSortedRunCompactionTrigger() + 1 : 
numLevels;
+        if (numLevels == null) {
+            numLevels = 
MathUtils.incrementSafely(numSortedRunCompactionTrigger());
+        }
         return numLevels;
     }
 
diff --git a/paimon-common/src/main/java/org/apache/paimon/utils/MathUtils.java 
b/paimon-common/src/main/java/org/apache/paimon/utils/MathUtils.java
index 310ae9b7f..c50646bd2 100644
--- a/paimon-common/src/main/java/org/apache/paimon/utils/MathUtils.java
+++ b/paimon-common/src/main/java/org/apache/paimon/utils/MathUtils.java
@@ -93,4 +93,12 @@ public class MathUtils {
 
         return Math.min(v1, v2);
     }
+
+    /** Safely increments the given int value by one, ensuring that no 
overflow occurs. */
+    public static int incrementSafely(int a) {
+        if (a == Integer.MAX_VALUE) {
+            return a;
+        }
+        return a + 1;
+    }
 }

Reply via email to