vikramahuja1001 commented on a change in pull request #4109: URL: https://github.com/apache/carbondata/pull/4109#discussion_r596964122
########## File path: core/src/main/java/org/apache/carbondata/core/util/DeleteLoadFolders.java ########## @@ -230,45 +241,46 @@ private static LoadMetadataDetails getCurrentLoadStatusOfSegment(String segmentI return null; } - public static boolean deleteLoadFoldersFromFileSystem( + public static Set<String> deleteLoadFoldersFromFileSystem( AbsoluteTableIdentifier absoluteTableIdentifier, boolean isForceDelete, LoadMetadataDetails[] details, String metadataPath, boolean cleanStaleInProgress) { - boolean isDeleted = false; + Set<String> loadsToDelete = new HashSet<>(); if (details != null && details.length != 0) { for (LoadMetadataDetails oneLoad : details) { - if (checkIfLoadCanBeDeleted(oneLoad, isForceDelete, cleanStaleInProgress)) { - ICarbonLock segmentLock = CarbonLockFactory.getCarbonLockObj(absoluteTableIdentifier, - CarbonTablePath.addSegmentPrefix(oneLoad.getLoadName()) + LockUsage.LOCK); - try { - if (oneLoad.getSegmentStatus() == SegmentStatus.INSERT_OVERWRITE_IN_PROGRESS - || oneLoad.getSegmentStatus() == SegmentStatus.INSERT_IN_PROGRESS) { - if (segmentLock.lockWithRetries(1, 5)) { - LOGGER.info("Info: Acquired segment lock on segment:" + oneLoad.getLoadName()); - LoadMetadataDetails currentDetails = - getCurrentLoadStatusOfSegment(oneLoad.getLoadName(), metadataPath); - if (currentDetails != null && checkIfLoadCanBeDeleted(currentDetails, - isForceDelete, cleanStaleInProgress)) { - oneLoad.setVisibility("false"); - isDeleted = true; - LOGGER.info("Info: Deleted the load " + oneLoad.getLoadName()); - } - } else { - LOGGER.info("Info: Load in progress for segment" + oneLoad.getLoadName()); - return isDeleted; - } - } else { + if (checkIfLoadCanBeDeleted(oneLoad, isForceDelete, cleanStaleInProgress, + absoluteTableIdentifier)) { + if (oneLoad.getSegmentStatus() == SegmentStatus.INSERT_OVERWRITE_IN_PROGRESS + || oneLoad.getSegmentStatus() == SegmentStatus.INSERT_IN_PROGRESS) { + LoadMetadataDetails currentDetails = + getCurrentLoadStatusOfSegment(oneLoad.getLoadName(), metadataPath); + if (currentDetails != null && checkIfLoadCanBeDeleted(currentDetails, + isForceDelete, cleanStaleInProgress, absoluteTableIdentifier)) { oneLoad.setVisibility("false"); - isDeleted = true; + loadsToDelete.add(oneLoad.getLoadName()); LOGGER.info("Info: Deleted the load " + oneLoad.getLoadName()); } - } finally { - segmentLock.unlock(); - LOGGER.info("Info: Segment lock on segment:" + oneLoad.getLoadName() + " is released"); + } else { + oneLoad.setVisibility("false"); + loadsToDelete.add(oneLoad.getLoadName()); + LOGGER.info("Info: Deleted the load " + oneLoad.getLoadName()); } } } } - return isDeleted; + return loadsToDelete; } + private static boolean canSegmentLockBeAcquired(LoadMetadataDetails oneLoad, + AbsoluteTableIdentifier absoluteTableIdentifier) { + ICarbonLock segmentLock = CarbonLockFactory.getCarbonLockObj(absoluteTableIdentifier, + CarbonTablePath.addSegmentPrefix(oneLoad.getLoadName()) + LockUsage.LOCK); + if (segmentLock.lockWithRetries()) { + LOGGER.info("INFO: Segment Lock on segment: " + oneLoad.getLoadName() + "can be acquired."); 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