You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2019/11/23 10:05:12 UTC
[incubator-iotdb] 01/02: get lock in FileReaderManager outside of
the synchronized block (#582)
This is an automated email from the ASF dual-hosted git repository.
qiaojialin pushed a commit to branch rel/0.9
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit e26cd34de9de473fb2b1bad8bb993ef4ab081d60
Author: Jiang Tian <jt...@163.com>
AuthorDate: Sat Nov 23 17:33:47 2019 +0800
get lock in FileReaderManager outside of the synchronized block (#582)
(cherry picked from commit ed598fd71ad01987e006e56901162d6123d08843)
---
.../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();
}