You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2020/12/14 08:15:08 UTC
[iotdb] branch master updated: Fix the risk of deadlock by
WeakReference (#1968)
This is an automated email from the ASF dual-hosted git repository.
haonan 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 6a68db0 Fix the risk of deadlock by WeakReference (#1968)
6a68db0 is described below
commit 6a68db05cad289d86ce21481b13b941628c57a3f
Author: Benedict Jin <as...@apache.org>
AuthorDate: Mon Dec 14 16:14:48 2020 +0800
Fix the risk of deadlock by WeakReference (#1968)
---
.../org/apache/iotdb/db/engine/cache/TimeSeriesMetadataCache.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/cache/TimeSeriesMetadataCache.java b/server/src/main/java/org/apache/iotdb/db/engine/cache/TimeSeriesMetadataCache.java
index 8273476..62eee4b 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/cache/TimeSeriesMetadataCache.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/cache/TimeSeriesMetadataCache.java
@@ -20,9 +20,13 @@
package org.apache.iotdb.db.engine.cache;
import java.io.IOException;
+import java.lang.ref.WeakReference;
+import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -60,6 +64,7 @@ public class TimeSeriesMetadataCache {
private final ReadWriteLock lock = new ReentrantReadWriteLock();
+ private final Map<String, WeakReference<String>> devices = Collections.synchronizedMap(new WeakHashMap<>());
private TimeSeriesMetadataCache() {
if (CACHE_ENABLE) {
@@ -127,7 +132,7 @@ public class TimeSeriesMetadataCache {
printCacheLog(true);
} else {
// allow for the parallelism of different devices
- synchronized (key.device.intern()) {
+ synchronized (devices.computeIfAbsent(key.device, WeakReference::new)) {
// double check
lock.readLock().lock();
try {