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


##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/wal/allocation/FirstCreateStrategyTest.java:
##########
@@ -141,6 +142,79 @@ public void testRegisterWALNode() throws 
IllegalPathException {
     }
   }
 
+  @Test
+  public void testReInitializeAfterDiskSpaceCleaned() throws 
IllegalPathException, IOException {
+    // Create temporary directories for testing
+    File tempDir = new File(System.getProperty("java.io.tmpdir"), 
"iotdb_wal_reinit_test");
+    tempDir.mkdirs();
+
+    String[] testWalDirs =
+        new String[] {
+          new File(tempDir, "wal_reinit_test1").getAbsolutePath(),
+          new File(tempDir, "wal_reinit_test2").getAbsolutePath(),
+          new File(tempDir, "wal_reinit_test3").getAbsolutePath()
+        };
+
+    String[] originalWalDirs = commonConfig.getWalDirs();
+    commonConfig.setWalDirs(testWalDirs);
+
+    try {
+      // Create strategy with valid directories first
+      FirstCreateStrategy strategy = new FirstCreateStrategy();
+
+      // Simulate folderManager becoming null (e.g., due to disk space issues)
+      // We'll use reflection to set folderManager to null to test 
re-initialization
+      try {
+        java.lang.reflect.Field folderManagerField =
+            
AbstractNodeAllocationStrategy.class.getDeclaredField("folderManager");
+        folderManagerField.setAccessible(true);
+        folderManagerField.set(strategy, null);
+      } catch (NoSuchFieldException | IllegalAccessException e) {
+        throw new RuntimeException("Failed to set folderManager to null for 
testing", e);
+      }
+
+      // Now apply for WAL node, should successfully re-initialize 
folderManager
+      IWALNode walNode = strategy.applyForWALNode("test_reinit_identifier");
+      assertNotNull("WAL node should be created after re-initialization", 
walNode);

Review Comment:
   Fixed



##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/wal/allocation/FirstCreateStrategyTest.java:
##########
@@ -141,6 +142,79 @@ public void testRegisterWALNode() throws 
IllegalPathException {
     }
   }
 
+  @Test
+  public void testReInitializeAfterDiskSpaceCleaned() throws 
IllegalPathException, IOException {
+    // Create temporary directories for testing
+    File tempDir = new File(System.getProperty("java.io.tmpdir"), 
"iotdb_wal_reinit_test");
+    tempDir.mkdirs();
+
+    String[] testWalDirs =
+        new String[] {
+          new File(tempDir, "wal_reinit_test1").getAbsolutePath(),
+          new File(tempDir, "wal_reinit_test2").getAbsolutePath(),
+          new File(tempDir, "wal_reinit_test3").getAbsolutePath()
+        };
+
+    String[] originalWalDirs = commonConfig.getWalDirs();
+    commonConfig.setWalDirs(testWalDirs);
+
+    try {
+      // Create strategy with valid directories first
+      FirstCreateStrategy strategy = new FirstCreateStrategy();
+
+      // Simulate folderManager becoming null (e.g., due to disk space issues)
+      // We'll use reflection to set folderManager to null to test 
re-initialization
+      try {
+        java.lang.reflect.Field folderManagerField =
+            
AbstractNodeAllocationStrategy.class.getDeclaredField("folderManager");
+        folderManagerField.setAccessible(true);
+        folderManagerField.set(strategy, null);
+      } catch (NoSuchFieldException | IllegalAccessException e) {
+        throw new RuntimeException("Failed to set folderManager to null for 
testing", e);
+      }
+
+      // Now apply for WAL node, should successfully re-initialize 
folderManager
+      IWALNode walNode = strategy.applyForWALNode("test_reinit_identifier");
+      assertNotNull("WAL node should be created after re-initialization", 
walNode);
+
+      // Verify that WAL node was created successfully by logging data
+      walNode.log(1, getInsertRowNode());
+
+      // Verify that WAL files were created in at least one directory
+      boolean walFileCreated = false;
+      for (String walDir : testWalDirs) {
+        File walDirFile = new File(walDir);
+        if (walDirFile.exists()) {
+          File[] nodeDirs = walDirFile.listFiles(File::isDirectory);
+          if (nodeDirs != null && nodeDirs.length > 0) {
+            for (File nodeDir : nodeDirs) {
+              if (nodeDir.exists() && 
WALFileUtils.listAllWALFiles(nodeDir).length > 0) {
+                walFileCreated = true;
+                break;
+              }
+            }
+          }
+        }
+        if (walFileCreated) {
+          break;
+        }
+      }
+      assertTrue("WAL files should be created after re-initialization", 
walFileCreated);
+
+      // Clean up
+      walNode.close();
+    } finally {
+      // Clean up the test directories
+      for (String walDir : testWalDirs) {
+        EnvironmentUtils.cleanDir(walDir);
+      }
+      // Clean up temp directory
+      EnvironmentUtils.cleanDir(tempDir.getAbsolutePath());
+      // Restore original WAL directories
+      commonConfig.setWalDirs(originalWalDirs);
+    }
+  }

Review Comment:
   Added



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