You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hu...@apache.org on 2022/08/25 06:20:37 UTC

[iotdb] branch lmh/readerBug013 created (now 3b41cc19df)

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

hui pushed a change to branch lmh/readerBug013
in repository https://gitbox.apache.org/repos/asf/iotdb.git


      at 3b41cc19df [To rel/0.13] [IOTDB-4196] Fix concurrent bug in TsFileSequenceReader

This branch includes the following new commits:

     new 3b41cc19df [To rel/0.13] [IOTDB-4196] Fix concurrent bug in TsFileSequenceReader

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[iotdb] 01/01: [To rel/0.13] [IOTDB-4196] Fix concurrent bug in TsFileSequenceReader

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hui pushed a commit to branch lmh/readerBug013
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 3b41cc19dfc2013fd5748199881e5d762d3fb8c8
Author: Minghui Liu <li...@foxmail.com>
AuthorDate: Thu Aug 25 14:18:52 2022 +0800

    [To rel/0.13] [IOTDB-4196] Fix concurrent bug in TsFileSequenceReader
---
 .../org/apache/iotdb/tsfile/read/TsFileSequenceReader.java     | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/TsFileSequenceReader.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/TsFileSequenceReader.java
index 81d6c8a63b..619890a74c 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/TsFileSequenceReader.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/TsFileSequenceReader.java
@@ -100,7 +100,7 @@ public class TsFileSequenceReader implements AutoCloseable {
   protected long fileMetadataPos;
   protected int fileMetadataSize;
   private ByteBuffer markerBuffer = ByteBuffer.allocate(Byte.BYTES);
-  protected TsFileMetadata tsFileMetaData;
+  protected volatile TsFileMetadata tsFileMetaData;
   // device -> measurement -> TimeseriesMetadata
   private Map<String, Map<String, TimeseriesMetadata>> cachedDeviceMetadata =
       new ConcurrentHashMap<>();
@@ -269,8 +269,12 @@ public class TsFileSequenceReader implements AutoCloseable {
   public TsFileMetadata readFileMetadata() throws IOException {
     try {
       if (tsFileMetaData == null) {
-        tsFileMetaData =
-            TsFileMetadata.deserializeFrom(readData(fileMetadataPos, fileMetadataSize));
+        synchronized (this) {
+          if (tsFileMetaData == null) {
+            tsFileMetaData =
+                TsFileMetadata.deserializeFrom(readData(fileMetadataPos, fileMetadataSize));
+          }
+        }
       }
     } catch (Exception e) {
       logger.error("Something error happened while reading file metadata of file {}", file);