You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2024/01/10 11:07:01 UTC
(iotdb) 02/02: Avoid ConcurrentModificationException in PipeTsFileResourceManager
This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch fix-pipe-file-read
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit abe9798acd39042f59acbbcc95d7dfe076dc13fc
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Wed Jan 10 19:06:52 2024 +0800
Avoid ConcurrentModificationException in PipeTsFileResourceManager
---
.../resource/tsfile/PipeTsFileResourceManager.java | 18 +++++++-----------
.../db/pipe/resource/wal/PipeWALResourceManager.java | 5 +++--
2 files changed, 10 insertions(+), 13 deletions(-)
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/tsfile/PipeTsFileResourceManager.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/tsfile/PipeTsFileResourceManager.java
index 6e23dba8bc7..9f5904b2cf6 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/tsfile/PipeTsFileResourceManager.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/tsfile/PipeTsFileResourceManager.java
@@ -33,11 +33,10 @@ import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.ConcurrentModificationException;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;
public class PipeTsFileResourceManager {
@@ -45,7 +44,7 @@ public class PipeTsFileResourceManager {
private static final Logger LOGGER = LoggerFactory.getLogger(PipeTsFileResourceManager.class);
private final Map<String, PipeTsFileResource> hardlinkOrCopiedFileToPipeTsFileResourceMap =
- new HashMap<>();
+ new ConcurrentHashMap<>();
private final ReentrantLock lock = new ReentrantLock();
public PipeTsFileResourceManager() {
@@ -57,13 +56,13 @@ public class PipeTsFileResourceManager {
}
private void ttlCheck() {
- final Iterator<Map.Entry<String, PipeTsFileResource>> iterator =
- hardlinkOrCopiedFileToPipeTsFileResourceMap.entrySet().iterator();
+ lock.lock();
try {
+ final Iterator<Map.Entry<String, PipeTsFileResource>> iterator =
+ hardlinkOrCopiedFileToPipeTsFileResourceMap.entrySet().iterator();
while (iterator.hasNext()) {
final Map.Entry<String, PipeTsFileResource> entry = iterator.next();
- lock.lock();
try {
if (entry.getValue().closeIfOutOfTimeToLive()) {
iterator.remove();
@@ -75,13 +74,10 @@ public class PipeTsFileResourceManager {
}
} catch (IOException e) {
LOGGER.warn("failed to close PipeTsFileResource when checking TTL: ", e);
- } finally {
- lock.unlock();
}
}
- } catch (ConcurrentModificationException e) {
- LOGGER.info(
- "Concurrent modification issues happened, skipping the file in this round of ttl check");
+ } finally {
+ lock.unlock();
}
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/wal/PipeWALResourceManager.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/wal/PipeWALResourceManager.java
index 40353d4ac1c..aa8f4e71623 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/wal/PipeWALResourceManager.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/wal/PipeWALResourceManager.java
@@ -82,8 +82,9 @@ public abstract class PipeWALResourceManager {
}
}
} catch (ConcurrentModificationException e) {
- LOGGER.info(
- "Concurrent modification issues happened, skipping the WAL in this round of ttl check");
+ LOGGER.error(
+ "Concurrent modification issues happened, skipping the WAL in this round of ttl check",
+ e);
}
}