vikramahuja1001 commented on a change in pull request #4072: URL: https://github.com/apache/carbondata/pull/4072#discussion_r578974314
########## File path: core/src/main/java/org/apache/carbondata/core/util/TrashUtil.java ########## @@ -152,46 +153,77 @@ public static void copyFilesToTrash(List<String> filesToCopy, * The below method deletes timestamp subdirectories in the trash folder which have expired as * per the user defined retention time */ - public static void deleteExpiredDataFromTrash(String tablePath) { + public static long[] deleteExpiredDataFromTrash(String tablePath, Boolean isDryRun) { CarbonFile trashFolder = FileFactory.getCarbonFile(CarbonTablePath .getTrashFolderPath(tablePath)); + long sizeFreed = 0; + long trashFolderSize = 0; // Deleting the timestamp based subdirectories in the trashfolder by the given timestamp. try { if (trashFolder.isFileExist()) { + trashFolderSize = FileFactory.getDirectorySize(trashFolder.getAbsolutePath()); CarbonFile[] timestampFolderList = trashFolder.listFiles(); + List<CarbonFile> filesToDelete = new ArrayList<>(); for (CarbonFile timestampFolder : timestampFolderList) { // If the timeStamp at which the timeStamp subdirectory has expired as per the user // defined value, delete the complete timeStamp subdirectory - if (timestampFolder.isDirectory() && isTrashRetentionTimeoutExceeded(Long - .parseLong(timestampFolder.getName()))) { - FileFactory.deleteAllCarbonFilesOfDir(timestampFolder); - LOGGER.info("Timestamp subfolder from the Trash folder deleted: " + timestampFolder + if (isTrashRetentionTimeoutExceeded(Long.parseLong(timestampFolder.getName()))) { + if (timestampFolder.isDirectory()) { + sizeFreed += FileFactory.getDirectorySize(timestampFolder.getAbsolutePath()); + filesToDelete.add(timestampFolder); + } + } + } + if (!isDryRun) { + for (CarbonFile carbonFile : filesToDelete) { + LOGGER.info("Timestamp subfolder from the Trash folder deleted: " + carbonFile .getAbsolutePath()); + FileFactory.deleteAllCarbonFilesOfDir(carbonFile); } } } } catch (IOException e) { LOGGER.error("Error during deleting expired timestamp folder from the trash folder", e); } + return new long[] {sizeFreed, trashFolderSize - sizeFreed}; } /** * The below method deletes all the files and folders in the trash folder of a carbon table. + * Returns an array in which the first element contains the size freed in case of clean files + * operation or size that can be freed in case of dry run and the second element contains the + * remaining size. */ - public static void emptyTrash(String tablePath) { + public static long[] emptyTrash(String tablePath, Boolean isDryRun) { CarbonFile trashFolder = FileFactory.getCarbonFile(CarbonTablePath .getTrashFolderPath(tablePath)); // if the trash folder exists delete the contents of the trash folder + long sizeFreed = 0; + long[] sizeStatistics = new long[]{0, 0}; try { if (trashFolder.isFileExist()) { CarbonFile[] carbonFileList = trashFolder.listFiles(); + List<CarbonFile> filesToDelete = new ArrayList<>(); for (CarbonFile carbonFile : carbonFileList) { - FileFactory.deleteAllCarbonFilesOfDir(carbonFile); + sizeFreed += FileFactory.getDirectorySize(carbonFile.getAbsolutePath()); Review comment: done ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org