This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 32f1010942e Clean up tmp dirs of udf and sort while starting up
(#17377)
32f1010942e is described below
commit 32f1010942e8841e9c1aefcb89e042dba18d42f7
Author: Jackie Tien <[email protected]>
AuthorDate: Fri Mar 27 18:46:14 2026 +0800
Clean up tmp dirs of udf and sort while starting up (#17377)
---
.../java/org/apache/iotdb/db/service/DataNode.java | 12 ++++++++++++
.../db/service/TemporaryQueryDataFileService.java | 20 ++++++++++++++------
.../iotdb/commons/executable/ExecutableManager.java | 4 ++--
3 files changed, 28 insertions(+), 8 deletions(-)
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java
index 0b13da60110..7004d09872d 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java
@@ -765,6 +765,15 @@ public class DataNode extends ServerCommandLine implements
DataNodeMBean {
}
}
+ private void cleanupSortTmpDir() {
+ String sortTmpDir = config.getSortTmpDir();
+ File tmpDir = new File(sortTmpDir);
+ if (tmpDir.exists()) {
+ FileUtils.deleteFileOrDirectory(tmpDir, true);
+ logger.info("Cleaned up stale sort temp directory: {}", sortTmpDir);
+ }
+ }
+
private void prepareResources() throws StartupException {
prepareUDFResources();
prepareTriggerResources();
@@ -819,6 +828,9 @@ public class DataNode extends ServerCommandLine implements
DataNodeMBean {
registerManager.register(new JMXService());
JMXService.registerMBean(getInstance(), mbeanName);
+ // Clean up stale sort temp files left from previous runs
+ cleanupSortTmpDir();
+
// Get resources for trigger,udf,pipe...
prepareResources();
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/TemporaryQueryDataFileService.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/TemporaryQueryDataFileService.java
index cfc56734d00..c8150ea9295 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/TemporaryQueryDataFileService.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/TemporaryQueryDataFileService.java
@@ -33,6 +33,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -59,10 +60,9 @@ public class TemporaryQueryDataFileService implements
IService {
public String register(SerializationRecorder recorder) throws IOException {
String queryId = recorder.getQueryId();
- if (!recorders.containsKey(queryId)) {
- recorders.put(queryId, new ArrayList<>());
- }
- recorders.get(queryId).add(recorder);
+ recorders
+ .computeIfAbsent(queryId, k -> Collections.synchronizedList(new
ArrayList<>()))
+ .add(recorder);
String dirName = getDirName(queryId);
makeDirIfNecessary(dirName);
@@ -109,6 +109,11 @@ public class TemporaryQueryDataFileService implements
IService {
@Override
public void start() throws StartupException {
try {
+ // Clean up stale temp directories left from previous runs (e.g., after
a crash)
+ File tmpDir = SystemFileFactory.INSTANCE.getFile(TEMPORARY_FILE_DIR);
+ if (tmpDir.exists()) {
+ FileUtils.deleteDirectory(tmpDir);
+ }
makeDirIfNecessary(TEMPORARY_FILE_DIR);
} catch (IOException e) {
throw new StartupException(e);
@@ -117,8 +122,11 @@ public class TemporaryQueryDataFileService implements
IService {
@Override
public void stop() {
- for (Object queryId : recorders.keySet().toArray()) {
- deregister((String) queryId);
+ recorders.clear();
+ try {
+
FileUtils.deleteDirectory(SystemFileFactory.INSTANCE.getFile(TEMPORARY_FILE_DIR));
+ } catch (IOException e) {
+ logger.warn("Failed to delete temp dir {}.", TEMPORARY_FILE_DIR, e);
}
}
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/executable/ExecutableManager.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/executable/ExecutableManager.java
index cb6ca1664ac..2c75928fee2 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/executable/ExecutableManager.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/executable/ExecutableManager.java
@@ -81,7 +81,6 @@ public class ExecutableManager {
private void downloadExecutables(List<String> uris, long requestId)
throws IOException, URISyntaxException {
- // TODO: para download
try {
for (String uriString : uris) {
final URL url = new URI(uriString).toURL();
@@ -223,7 +222,8 @@ public class ExecutableManager {
}
Files.createFile(path);
}
- // FileOutPutStream is not in append mode by default, so the file will
be overridden if it
+ // FileOutPutStream is not in append mode by default, so the file will be
+ // overridden if it
// already exists.
try (FileOutputStream outputStream = new FileOutputStream(destination)) {
outputStream.getChannel().write(byteBuffer);