Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#9085] fix(core): enforce minimum jobStatusKeepTimeInMs instead of throwing IllegalArgumentException. (#9102)

Harsh Mehtaad450e59af68
diff --git a/core/src/main/java/org/apache/gravitino/job/local/LocalJobExecutor.java b/core/src/main/java/org/apache/gravitino/job/local/LocalJobExecutor.java
index 4b1af0e4ec..f3b6e5d631 100644
--- a/core/src/main/java/org/apache/gravitino/job/local/LocalJobExecutor.java
+++ b/core/src/main/java/org/apache/gravitino/job/local/LocalJobExecutor.java
@@ -133,6 +133,7 @@ public class LocalJobExecutor implements JobExecutor {
"Job status keep time must be greater than 0, but got: %s",
jobStatusKeepTimeInMs);
+ this.jobStatusKeepTimeInMs = Math.max(jobStatusKeepTimeInMs, 10);
long jobStatusCleanupIntervalInMs = jobStatusKeepTimeInMs / 10;
this.jobStatusCleanupExecutor =
Executors.newSingleThreadScheduledExecutor(
diff --git a/core/src/test/java/org/apache/gravitino/job/local/TestLocalJobExecutor.java b/core/src/test/java/org/apache/gravitino/job/local/TestLocalJobExecutor.java
index 6c2dab5ad1..4f4100a3e3 100644
--- a/core/src/test/java/org/apache/gravitino/job/local/TestLocalJobExecutor.java
+++ b/core/src/test/java/org/apache/gravitino/job/local/TestLocalJobExecutor.java
@@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Field;
import java.net.URL;
import java.nio.file.Files;
import java.util.Collections;
@@ -226,4 +227,30 @@ public class TestLocalJobExecutor {
Assertions.assertDoesNotThrow(() -> jobExecutor.cancelJob(failJobId));
Assertions.assertEquals(JobHandle.Status.FAILED, jobExecutor.getJobStatus(failJobId));
}
+
+ @Test
+ public void testInitializeWithSmallJobStatusKeepTimeIsClampedToMinimum()
+ throws NoSuchFieldException, IllegalAccessException {
+ LocalJobExecutor exec = new LocalJobExecutor();
+
+ exec.initialize(ImmutableMap.of(LocalJobExecutorConfigs.JOB_STATUS_KEEP_TIME_MS, "1"));
+
+ Field field = LocalJobExecutor.class.getDeclaredField("jobStatusKeepTimeInMs");
+ field.setAccessible(true);
+ long actualValue = (long) field.get(exec);
+ Assertions.assertEquals(10L, actualValue);
+ }
+
+ @Test
+ public void TestInitializeWithLargeJobStatusKeepTimeIsClampedToSameValue()
+ throws NoSuchFieldException, IllegalAccessException {
+ LocalJobExecutor exec = new LocalJobExecutor();
+
+ exec.initialize(ImmutableMap.of(LocalJobExecutorConfigs.JOB_STATUS_KEEP_TIME_MS, "11"));
+
+ Field field = LocalJobExecutor.class.getDeclaredField("jobStatusKeepTimeInMs");
+ field.setAccessible(true);
+ long actualValue = (long) field.get(exec);
+ Assertions.assertEquals(11L, actualValue);
+ }
}