Skip to content

Commit 57c668c

Browse files
authored
Pipe: atomically publish segment lock to avoid uninitialized volatile variable (#14064)
1 parent 70006df commit 57c668c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/tsfile/PipeTsFileResourceSegmentLock.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@ private void initIfNecessary() {
5151
lockSegmentSize = Math.min(SEGMENT_LOCK_MAX_SIZE, lockSegmentSize);
5252
lockSegmentSize = Math.max(SEGMENT_LOCK_MIN_SIZE, lockSegmentSize);
5353

54-
locks = new ReentrantLock[lockSegmentSize];
55-
for (int i = 0; i < locks.length; i++) {
56-
locks[i] = new ReentrantLock();
54+
final ReentrantLock[] tmpLocks = new ReentrantLock[lockSegmentSize];
55+
for (int i = 0; i < tmpLocks.length; i++) {
56+
tmpLocks[i] = new ReentrantLock();
5757
}
58+
59+
// publish this variable
60+
locks = tmpLocks;
5861
}
5962
}
6063
}

0 commit comments

Comments
 (0)