mridulm commented on code in PR #37922: URL: https://github.com/apache/spark/pull/37922#discussion_r1066428217
########## common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/RemoteBlockPushResolver.java: ########## @@ -396,6 +403,67 @@ public void applicationRemoved(String appId, boolean cleanupLocalDirs) { } } + @Override + public void removeShuffleMerge(RemoveShuffleMerge msg) { + AppShuffleInfo appShuffleInfo = validateAndGetAppShuffleInfo(msg.appId); + if (appShuffleInfo.attemptId != msg.appAttemptId) { + throw new IllegalArgumentException( + String.format("The attempt id %s in this RemoveShuffleMerge message does not match " + + "with the current attempt id %s stored in shuffle service for application %s", + msg.appAttemptId, appShuffleInfo.attemptId, msg.appId)); + } + appShuffleInfo.shuffles.compute(msg.shuffleId, (shuffleId, mergePartitionsInfo) -> { + if (mergePartitionsInfo == null) { + if (msg.shuffleMergeId == DELETE_ALL_MERGED_SHUFFLE) { + return null; + } else { + writeAppAttemptShuffleMergeInfoToDB(new AppAttemptShuffleMergeId( + msg.appId, msg.appAttemptId, msg.shuffleId, msg.shuffleMergeId)); + return new AppShuffleMergePartitionsInfo(msg.shuffleMergeId, true); + } + } + boolean deleteCurrentMergedShuffle = + msg.shuffleMergeId == DELETE_ALL_MERGED_SHUFFLE || + msg.shuffleMergeId == mergePartitionsInfo.shuffleMergeId; + int shuffleMergeId = msg.shuffleMergeId != DELETE_ALL_MERGED_SHUFFLE ? + msg.shuffleMergeId : mergePartitionsInfo.shuffleMergeId; + AppAttemptShuffleMergeId currentAppAttemptShuffleMergeId = + new AppAttemptShuffleMergeId( + msg.appId, msg.appAttemptId, msg.shuffleId, mergePartitionsInfo.shuffleMergeId); + AppAttemptShuffleMergeId appAttemptShuffleMergeId = new AppAttemptShuffleMergeId( + msg.appId, msg.appAttemptId, msg.shuffleId, shuffleMergeId); + if(deleteCurrentMergedShuffle) { + // request to clean up shuffle we are currently hosting + if (!mergePartitionsInfo.isFinalized()) { + submitCleanupTask(() -> + closeAndDeleteOutdatedPartitions( + currentAppAttemptShuffleMergeId, mergePartitionsInfo.shuffleMergePartitions)); + } else { + submitCleanupTask(() -> + deleteMergedFiles(currentAppAttemptShuffleMergeId, appShuffleInfo, + mergePartitionsInfo.getReduceIds(), false)); + } + } else if(shuffleMergeId < mergePartitionsInfo.shuffleMergeId) { + throw new RuntimeException(String.format("Asked to remove old shuffle merged data for " + + "application %s shuffleId %s shuffleMergeId %s, but current shuffleMergeId %s ", + msg.appId, msg.shuffleId, shuffleMergeId, mergePartitionsInfo.shuffleMergeId)); + } else if (shuffleMergeId > mergePartitionsInfo.shuffleMergeId) { + // cleanup request for newer shuffle - remove the outdated data we have. + if (!mergePartitionsInfo.isFinalized()) { + submitCleanupTask(() -> + closeAndDeleteOutdatedPartitions( Review Comment: All file cleanup is async - for example, when a newer merge id is seen during finalize, etc. The metadata removal is immediate and within the critical section - so the files cant be reached once the method returns. -- 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. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org