private void closeUnUsedReaderAndRemoveRef(String tsFilePath, boolean isClosed) {
    Map<String, TsFileSequenceReader> readerMap =
        isClosed ? closedFileReaderMap : unclosedFileReaderMap;
    Map<String, AtomicInteger> refMap = isClosed ? closedReferenceMap : unclosedReferenceMap;
    synchronized (this) {
      // check ref num again
      if (refMap.get(tsFilePath).get() != 0) {
        return;
      }

      TsFileSequenceReader reader = readerMap.get(tsFilePath);
      if (reader != null) {
        try {
          reader.close();
        } catch (IOException e) {
          logger.error("Can not close TsFileSequenceReader {} !", reader.getFileName(), e);
        }
      }
      readerMap.remove(tsFilePath);
      refMap.remove(tsFilePath);
      if (resourceLogger.isDebugEnabled()) {
        resourceLogger.debug("{} TsFileReader is closed because of no reference.", tsFilePath);
      }
    }
  }
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.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/control/FileReaderManager.java