jt2594838 commented on code in PR #16811:
URL: https://github.com/apache/iotdb/pull/16811#discussion_r2579326716


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/disk/FolderManager.java:
##########
@@ -104,6 +105,37 @@ public String getNextFolder() throws 
DiskSpaceInsufficientException {
     }
   }
 
+  /**
+   * Get folder by hash ID (typically consensus group ID), distributing as 
evenly as possible among
+   * healthy folders using hash-based distribution
+   *
+   * @param hashId the hash ID (typically consensus group ID) used to 
determine folder selection
+   * @return the selected folder path
+   * @throws DiskSpaceInsufficientException if no healthy folders are available
+   */
+  public String getFolderByHashId(int hashId) throws 
DiskSpaceInsufficientException {
+    if (folders.isEmpty()) {
+      throw new DiskSpaceInsufficientException(folders);
+    }
+
+    List<String> healthyFolders =
+        folders.stream()
+            .filter(
+                folder ->
+                    foldersStates.getOrDefault(folder, FolderState.ABNORMAL) 
== FolderState.HEALTHY)
+            .collect(Collectors.toList());
+
+    if (healthyFolders.isEmpty()) {
+      logger.error("No healthy folders available, change system mode to 
read-only.");
+      
CommonDescriptor.getInstance().getConfig().setNodeStatus(NodeStatus.ReadOnly);
+      
CommonDescriptor.getInstance().getConfig().setStatusReason(NodeStatus.DISK_FULL);
+      throw new DiskSpaceInsufficientException(folders);
+    }
+
+    int index = Math.abs(hashId) % healthyFolders.size();
+    return healthyFolders.get(index);
+  }

Review Comment:
   If the healthy status of the folders changes, then the same region will be 
distributed to different folders, and the judgement below will also be invalid?
   <img width="1289" height="327" alt="image" 
src="https://github.com/user-attachments/assets/6072cdf0-f8a0-468a-adb3-fa2231ee15b3";
 />
   



##########
iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java:
##########
@@ -465,7 +542,7 @@ public List<ConsensusGroupId> getAllConsensusGroupIds() {
 
   @Override
   public String getRegionDirFromConsensusGroupId(ConsensusGroupId groupId) {
-    return buildPeerDir(storageDir, groupId);
+    return null;
   }

Review Comment:
   Explain this



##########
iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java:
##########
@@ -271,8 +330,19 @@ public void createLocalPeer(ConsensusGroupId groupId, 
List<Peer> peers)
                 k -> {
                   exist.set(false);
 
-                  String path = buildPeerDir(storageDir, groupId);
+                  String path = null;
+                  try {
+                    path = 
buildPeerDir(folderManager.getFolderByHashId(groupId.getId()), groupId);
+                  } catch (DiskSpaceInsufficientException e) {
+                    logger.warn(
+                        "Failed to create consensus directory for group {} due 
to disk space insufficiency: {}",
+                        groupId,
+                        e.getMessage());
+                    return null;
+                  }
                   File file = new File(path);
+                  // debug print the path of consensus dir
+                  System.out.println(file.getAbsolutePath());

Review Comment:
   Remove this



-- 
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