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

rong pushed a commit to branch dev/1.3
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/dev/1.3 by this push:
     new d631ff79023 Pipe: atomically publish segment lock to avoid 
uninitialized volatile variable (#14064) (#14066)
d631ff79023 is described below

commit d631ff79023e75d9c299f3a482b4d0ec58a25284
Author: V_Galaxy <[email protected]>
AuthorDate: Wed Nov 13 10:55:20 2024 +0800

    Pipe: atomically publish segment lock to avoid uninitialized volatile 
variable (#14064) (#14066)
---
 .../db/pipe/resource/tsfile/PipeTsFileResourceSegmentLock.java   | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/tsfile/PipeTsFileResourceSegmentLock.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/tsfile/PipeTsFileResourceSegmentLock.java
index cc73ee0db38..d1bf7fef2ad 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/tsfile/PipeTsFileResourceSegmentLock.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/tsfile/PipeTsFileResourceSegmentLock.java
@@ -51,10 +51,13 @@ public class PipeTsFileResourceSegmentLock {
           lockSegmentSize = Math.min(SEGMENT_LOCK_MAX_SIZE, lockSegmentSize);
           lockSegmentSize = Math.max(SEGMENT_LOCK_MIN_SIZE, lockSegmentSize);
 
-          locks = new ReentrantLock[lockSegmentSize];
-          for (int i = 0; i < locks.length; i++) {
-            locks[i] = new ReentrantLock();
+          final ReentrantLock[] tmpLocks = new ReentrantLock[lockSegmentSize];
+          for (int i = 0; i < tmpLocks.length; i++) {
+            tmpLocks[i] = new ReentrantLock();
           }
+
+          // publish this variable
+          locks = tmpLocks;
         }
       }
     }

Reply via email to