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

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


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

commit 57c668ca51608af92c0ccc1daafb14cc354cbc16
Author: V_Galaxy <[email protected]>
AuthorDate: Wed Nov 13 10:39:30 2024 +0800

    Pipe: atomically publish segment lock to avoid uninitialized volatile 
variable (#14064)
---
 .../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