You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2019/11/23 09:03:00 UTC

[incubator-iotdb] 01/01: get lock in FileReaderManager outside of the synchronized block

This is an automated email from the ASF dual-hosted git repository.

jiangtian pushed a commit to branch fix_issue_319
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git

commit f22279ac633fa0103f92b14bb223f9182fa3575e
Author: jt2594838 <jt...@163.com>
AuthorDate: Sat Nov 23 17:02:41 2019 +0800

    get lock in FileReaderManager outside of the synchronized block
---
 .../iotdb/db/query/control/FileReaderManager.java  | 26 +++++++++++++---------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/query/control/FileReaderManager.java b/server/src/main/java/org/apache/iotdb/db/query/control/FileReaderManager.java
index c87c059..c961a64 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/control/FileReaderManager.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/control/FileReaderManager.java
@@ -164,25 +164,29 @@ public class FileReaderManager implements IService {
    * Increase the reference count of the reader specified by filePath. Only when the reference count
    * of a reader equals zero, the reader can be closed and removed.
    */
-  synchronized void increaseFileReaderReference(TsFileResource tsFile, boolean isClosed) {
+  void increaseFileReaderReference(TsFileResource tsFile, boolean isClosed) {
     // TODO : this should be called in get()
-    if (!isClosed) {
-      unclosedReferenceMap.computeIfAbsent(tsFile, k -> new AtomicInteger()).getAndIncrement();
-    } else {
-      closedReferenceMap.computeIfAbsent(tsFile, k -> new AtomicInteger()).getAndIncrement();
-    }
     tsFile.getWriteQueryLock().readLock().lock();
+    synchronized (this) {
+      if (!isClosed) {
+        unclosedReferenceMap.computeIfAbsent(tsFile, k -> new AtomicInteger()).getAndIncrement();
+      } else {
+        closedReferenceMap.computeIfAbsent(tsFile, k -> new AtomicInteger()).getAndIncrement();
+      }
+    }
   }
 
   /**
    * Decrease the reference count of the reader specified by filePath. This method is latch-free.
    * Only when the reference count of a reader equals zero, the reader can be closed and removed.
    */
-  synchronized void decreaseFileReaderReference(TsFileResource tsFile, boolean isClosed) {
-    if (!isClosed && unclosedReferenceMap.containsKey(tsFile)) {
-      unclosedReferenceMap.get(tsFile).getAndDecrement();
-    } else if (closedReferenceMap.containsKey(tsFile)){
-      closedReferenceMap.get(tsFile).getAndDecrement();
+  void decreaseFileReaderReference(TsFileResource tsFile, boolean isClosed) {
+    synchronized (this) {
+      if (!isClosed && unclosedReferenceMap.containsKey(tsFile)) {
+        unclosedReferenceMap.get(tsFile).getAndDecrement();
+      } else if (closedReferenceMap.containsKey(tsFile)){
+        closedReferenceMap.get(tsFile).getAndDecrement();
+      }
     }
     tsFile.getWriteQueryLock().readLock().unlock();
   }