Skip to content

Commit fdbbd52

Browse files
committed
remove empty object dir
1 parent e2383e1 commit fdbbd52

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/rescon/disk/TierManager.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.io.IOException;
4040
import java.nio.charset.StandardCharsets;
4141
import java.nio.file.FileStore;
42+
import java.nio.file.Files;
4243
import java.nio.file.Path;
4344
import java.util.ArrayList;
4445
import java.util.Arrays;
@@ -174,6 +175,16 @@ public synchronized void initFolders() {
174175
} catch (DiskSpaceInsufficientException e) {
175176
logger.error("All disks of tier {} are full.", tierLevel, e);
176177
}
178+
// try to remove empty objectDirs
179+
for (String dir : objectDirs) {
180+
File dirFile = FSFactoryProducer.getFSFactory().getFile(dir);
181+
if (dirFile.isDirectory() && Objects.requireNonNull(dirFile.list()).length == 0) {
182+
try {
183+
Files.delete(dirFile.toPath());
184+
} catch (IOException ignore) {
185+
}
186+
}
187+
}
177188
}
178189

179190
tierDiskTotalSpace = getTierDiskSpace(DiskSpaceType.TOTAL);

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/ObjectTypeUtils.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import java.nio.file.StandardOpenOption;
5656
import java.util.Collections;
5757
import java.util.List;
58+
import java.util.Objects;
5859
import java.util.Optional;
5960

6061
public class ObjectTypeUtils {
@@ -310,8 +311,18 @@ public static void deleteObjectPath(File file) {
310311
logger.error("Failed to remove object file {}", file.getAbsolutePath(), e);
311312
}
312313
}
313-
if (file.getParentFile().exists()) {
314+
deleteEmptyParentDir(file);
315+
}
314316

317+
private static void deleteEmptyParentDir(File file) {
318+
File dir = file.getParentFile();
319+
if (dir.isDirectory() && Objects.requireNonNull(dir.list()).length == 0) {
320+
try {
321+
Files.deleteIfExists(dir.toPath());
322+
deleteEmptyParentDir(dir);
323+
} catch (IOException e) {
324+
logger.error("Failed to remove empty object dir {}", dir.getAbsolutePath(), e);
325+
}
315326
}
316327
}
317328

0 commit comments

Comments
 (0)