File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
iotdb-core/datanode/src/main/java/org/apache/iotdb/db
storageengine/rescon/disk Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 3939import java .io .IOException ;
4040import java .nio .charset .StandardCharsets ;
4141import java .nio .file .FileStore ;
42+ import java .nio .file .Files ;
4243import java .nio .file .Path ;
4344import java .util .ArrayList ;
4445import 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 );
Original file line number Diff line number Diff line change 5555import java .nio .file .StandardOpenOption ;
5656import java .util .Collections ;
5757import java .util .List ;
58+ import java .util .Objects ;
5859import java .util .Optional ;
5960
6061public 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
You can’t perform that action at this time.
0 commit comments