Copilot commented on code in PR #16869:
URL: https://github.com/apache/iotdb/pull/16869#discussion_r2589414080


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/allocation/AbstractNodeAllocationStrategy.java:
##########
@@ -57,6 +57,10 @@ protected AbstractNodeAllocationStrategy() {
 
   protected IWALNode createWALNode(String identifier) {
     try {
+      if (folderManager == null) {
+          folderManager = new FolderManager(
+                  Arrays.asList(commonConfig.getWalDirs()), 
DirectoryStrategyType.SEQUENCE_STRATEGY);
+      }

Review Comment:
   This lazy initialization of `folderManager` is not thread-safe. The null 
check and initialization need to be synchronized to prevent a race condition 
where multiple threads could simultaneously detect `folderManager == null` and 
create multiple FolderManager instances.
   
   Consider using double-checked locking pattern:
   ```java
   if (folderManager == null) {
     synchronized (this) {
       if (folderManager == null) {
         folderManager = new FolderManager(
           Arrays.asList(commonConfig.getWalDirs()), 
DirectoryStrategyType.SEQUENCE_STRATEGY);
       }
     }
   }
   ```
   
   Alternatively, since all subclasses (ElasticStrategy, RoundRobinStrategy, 
FirstCreateStrategy) already use `nodesLock` when calling `createWALNode`, you 
could document that callers must hold their lock when calling this method.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to