slawekjaranowski commented on code in PR #347:
URL: 
https://github.com/apache/maven-clean-plugin/pull/347#discussion_r4111114654


##########
src/main/java/org/apache/maven/plugins/clean/BackgroundCleaner.java:
##########
@@ -255,18 +344,111 @@ boolean fastDelete(Path baseDir) throws IOException {
     }
 
     /**
-     * Deletes the given directory without logging messages and without 
throwing {@link IOException}.
-     * The exceptions are stored for reporting after the end of the session.
+     * Deletes the given directory in a background thread using batch retry.
+     * Unlike the foreground {@link Cleaner}, this method does not call {@code 
System.gc()}
+     * or sleep per file, avoiding the stop-the-world JVM pauses that caused 
the performance
+     * regression described in MCLEAN-102.
+     *
+     * <p>The deletion proceeds in two passes:</p>
+     * <ol>
+     *   <li><b>Walk:</b> traverse the file tree and attempt to delete each 
file/directory once.
+     *       Failures are silently collected without retrying.</li>
+     *   <li><b>Batch retry:</b> if {@code retryOnError} is enabled and there 
were failures,
+     *       sleep once ({@value #BATCH_RETRY_DELAY_MS}ms) to let external 
processes release
+     *       file locks, then retry all failures together.</li>
+     * </ol>
+     *
+     * <p>Any files that still cannot be deleted after the batch retry will be 
cleaned up
+     * by the {@linkplain #scanForLeftovers() leftover scan} on the next 
build.</p>
      *
      * <h4>Thread safety</h4>
-     * Contrarily to most other methods in {@code BackgroundCleaner}, this 
method is
-     * thread-safe because it uses a copy of this cleaner for walking in the 
file tree.
+     * This method is designed to run in the background executor thread. It 
does not share
+     * any mutable state with the main thread except through {@link 
#errorOccurred(IOException)},
+     * which is synchronized.
+     *
+     * @param dir          the directory to delete
+     * @param force        whether to force the deletion of read-only files
+     * @param retryOnError whether to undertake a batch retry of failed 
deletions
      */
-    private void deleteSilently(final Path dir) {
+    private void deleteInBackground(Path dir, boolean force, boolean 
retryOnError) {
+        logger.debug("Deleting " + dir + " in background.");
+        List<Path> failures = new ArrayList<>();
         try {
-            Files.walkFileTree(dir, Set.of(), Integer.MAX_VALUE, new 
Cleaner(this));
+            Files.walkFileTree(dir, Set.of(), Integer.MAX_VALUE, new 
SimpleFileVisitor<>() {

Review Comment:
   ok, we can add special Windows test if will be really need - it can be 
difficult to diagnose



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to