|
38 | 38 | import org.junit.Test; |
39 | 39 |
|
40 | 40 | import java.io.File; |
| 41 | +import java.io.IOException; |
41 | 42 |
|
42 | 43 | import static org.junit.Assert.assertEquals; |
43 | 44 | import static org.junit.Assert.assertNotEquals; |
@@ -141,6 +142,79 @@ public void testRegisterWALNode() throws IllegalPathException { |
141 | 142 | } |
142 | 143 | } |
143 | 144 |
|
| 145 | + @Test |
| 146 | + public void testReInitializeAfterDiskSpaceCleaned() throws IllegalPathException, IOException { |
| 147 | + // Create temporary directories for testing |
| 148 | + File tempDir = new File(System.getProperty("java.io.tmpdir"), "iotdb_wal_reinit_test"); |
| 149 | + tempDir.mkdirs(); |
| 150 | + |
| 151 | + String[] walDirs = |
| 152 | + new String[] { |
| 153 | + new File(tempDir, "wal_reinit_test1").getAbsolutePath(), |
| 154 | + new File(tempDir, "wal_reinit_test2").getAbsolutePath(), |
| 155 | + new File(tempDir, "wal_reinit_test3").getAbsolutePath() |
| 156 | + }; |
| 157 | + |
| 158 | + String[] originalWalDirs = commonConfig.getWalDirs(); |
| 159 | + commonConfig.setWalDirs(walDirs); |
| 160 | + |
| 161 | + try { |
| 162 | + // Create strategy with valid directories first |
| 163 | + FirstCreateStrategy strategy = new FirstCreateStrategy(); |
| 164 | + |
| 165 | + // Simulate folderManager becoming null (e.g., due to disk space issues) |
| 166 | + // We'll use reflection to set folderManager to null to test re-initialization |
| 167 | + try { |
| 168 | + java.lang.reflect.Field folderManagerField = |
| 169 | + AbstractNodeAllocationStrategy.class.getDeclaredField("folderManager"); |
| 170 | + folderManagerField.setAccessible(true); |
| 171 | + folderManagerField.set(strategy, null); |
| 172 | + } catch (NoSuchFieldException | IllegalAccessException e) { |
| 173 | + throw new RuntimeException("Failed to set folderManager to null for testing", e); |
| 174 | + } |
| 175 | + |
| 176 | + // Now apply for WAL node, should successfully re-initialize folderManager |
| 177 | + IWALNode walNode = strategy.applyForWALNode("test_reinit_identifier"); |
| 178 | + assertNotNull("WAL node should be created after re-initialization", walNode); |
| 179 | + |
| 180 | + // Verify that WAL node was created successfully by logging data |
| 181 | + walNode.log(1, getInsertRowNode()); |
| 182 | + |
| 183 | + // Verify that WAL files were created in at least one directory |
| 184 | + boolean walFileCreated = false; |
| 185 | + for (String walDir : walDirs) { |
| 186 | + File walDirFile = new File(walDir); |
| 187 | + if (walDirFile.exists()) { |
| 188 | + File[] nodeDirs = walDirFile.listFiles(File::isDirectory); |
| 189 | + if (nodeDirs != null && nodeDirs.length > 0) { |
| 190 | + for (File nodeDir : nodeDirs) { |
| 191 | + if (nodeDir.exists() && WALFileUtils.listAllWALFiles(nodeDir).length > 0) { |
| 192 | + walFileCreated = true; |
| 193 | + break; |
| 194 | + } |
| 195 | + } |
| 196 | + } |
| 197 | + } |
| 198 | + if (walFileCreated) { |
| 199 | + break; |
| 200 | + } |
| 201 | + } |
| 202 | + assertTrue("WAL files should be created after re-initialization", walFileCreated); |
| 203 | + |
| 204 | + // Clean up |
| 205 | + walNode.close(); |
| 206 | + } finally { |
| 207 | + // Clean up the test directories |
| 208 | + for (String walDir : walDirs) { |
| 209 | + EnvironmentUtils.cleanDir(walDir); |
| 210 | + } |
| 211 | + // Clean up temp directory |
| 212 | + EnvironmentUtils.cleanDir(tempDir.getAbsolutePath()); |
| 213 | + // Restore original WAL directories |
| 214 | + commonConfig.setWalDirs(originalWalDirs); |
| 215 | + } |
| 216 | + } |
| 217 | + |
144 | 218 | private InsertRowNode getInsertRowNode() throws IllegalPathException { |
145 | 219 | long time = 110L; |
146 | 220 | TSDataType[] dataTypes = |
|
0 commit comments