This is an automated email from the ASF dual-hosted git repository.
jshao pushed a commit to branch branch-1.0
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/branch-1.0 by this push:
new 34e814caf0 [#8371][followup] improvement: Use tempDir and shutdown the
threadpool (#8585)
34e814caf0 is described below
commit 34e814caf049429c41d27e135c725f3bb18973fc
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Sep 17 17:58:29 2025 +0800
[#8371][followup] improvement: Use tempDir and shutdown the threadpool
(#8585)
### What changes were proposed in this pull request?
Use tempDir and shutdown the threadpool
### Why are the changes needed?
Followup PR.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Add UT.
Co-authored-by: roryqi <[email protected]>
---
.../stats/storage/LancePartitionStatisticStorage.java | 19 ++++++++++++-------
.../storage/TestLancePartitionStatisticStorage.java | 5 +++--
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git
a/core/src/main/java/org/apache/gravitino/stats/storage/LancePartitionStatisticStorage.java
b/core/src/main/java/org/apache/gravitino/stats/storage/LancePartitionStatisticStorage.java
index 9160021d0b..c6e2398b29 100644
---
a/core/src/main/java/org/apache/gravitino/stats/storage/LancePartitionStatisticStorage.java
+++
b/core/src/main/java/org/apache/gravitino/stats/storage/LancePartitionStatisticStorage.java
@@ -124,6 +124,7 @@ public class LancePartitionStatisticStorage implements
PartitionStatisticStorage
private final int readBatchSize;
private final long metadataFileCacheSize;
private final long indexCacheSize;
+ private final ScheduledThreadPoolExecutor scheduler;
private final EntityStore entityStore =
GravitinoEnv.getInstance().entityStore();
@@ -178,16 +179,15 @@ public class LancePartitionStatisticStorage implements
PartitionStatisticStorage
this.properties = properties;
if (datasetCacheSize != 0) {
+ this.scheduler =
+ new ScheduledThreadPoolExecutor(
+ 1,
newDaemonThreadFactory("lance-partition-statistic-storage-cache-cleaner"));
+
this.datasetCache =
Optional.of(
Caffeine.newBuilder()
.maximumSize(datasetCacheSize)
- .scheduler(
- Scheduler.forScheduledExecutorService(
- new ScheduledThreadPoolExecutor(
- 1,
- newDaemonThreadFactory(
-
"lance-partition-statistic-storage-cache-cleaner"))))
+
.scheduler(Scheduler.forScheduledExecutorService(this.scheduler))
.evictionListener(
(RemovalListener<Long, Dataset>)
(key, value, cause) -> {
@@ -197,7 +197,8 @@ public class LancePartitionStatisticStorage implements
PartitionStatisticStorage
})
.build());
} else {
- datasetCache = Optional.empty();
+ this.datasetCache = Optional.empty();
+ this.scheduler = null;
}
}
@@ -330,6 +331,10 @@ public class LancePartitionStatisticStorage implements
PartitionStatisticStorage
}
datasetCache.ifPresent(Cache::invalidateAll);
+
+ if (scheduler != null) {
+ scheduler.shutdown();
+ }
}
@VisibleForTesting
diff --git
a/core/src/test/java/org/apache/gravitino/stats/storage/TestLancePartitionStatisticStorage.java
b/core/src/test/java/org/apache/gravitino/stats/storage/TestLancePartitionStatisticStorage.java
index 3ab553c32e..10fbfc7909 100644
---
a/core/src/test/java/org/apache/gravitino/stats/storage/TestLancePartitionStatisticStorage.java
+++
b/core/src/test/java/org/apache/gravitino/stats/storage/TestLancePartitionStatisticStorage.java
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.when;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.io.File;
+import java.nio.file.Files;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.reflect.FieldUtils;
@@ -64,7 +65,7 @@ public class TestLancePartitionStatisticStorage {
when(tableEntity.id()).thenReturn(1L);
FieldUtils.writeField(GravitinoEnv.getInstance(), "entityStore",
entityStore, true);
- String location = "/tmp/test";
+ String location = Files.createTempDirectory("lance_stats_test").toString();
Map<String, String> properties = Maps.newHashMap();
properties.put("location", location);
@@ -227,7 +228,7 @@ public class TestLancePartitionStatisticStorage {
when(tableEntity.id()).thenReturn(1L);
FieldUtils.writeField(GravitinoEnv.getInstance(), "entityStore",
entityStore, true);
- String location = "/tmp/test";
+ String location = Files.createTempDirectory("lance_stats_test").toString();
Map<String, String> properties = Maps.newHashMap();
properties.put("location", location);
properties.put("datasetCacheSize", "1000");