lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sim...@apache.org
Subject lucene-solr:branch_7x: LUCENE-8217: Remove IndexFileDeleter#decRefWhileHandlingExceptions
Date Wed, 21 Mar 2018 09:09:12 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x af33bc8c3 -> 2539578cb


LUCENE-8217: Remove IndexFileDeleter#decRefWhileHandlingExceptions

This method is a duplicate of IDF#decRef(...) and hides exceptions
from the caller. This change removes this method and replaces it with
it's counterpart that escalades the exception.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/2539578c
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/2539578c
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/2539578c

Branch: refs/heads/branch_7x
Commit: 2539578cb14091e5736ea57deb796e6e43c2739b
Parents: af33bc8
Author: Simon Willnauer <simonw@apache.org>
Authored: Tue Mar 20 12:41:47 2018 +0100
Committer: Simon Willnauer <simonw@apache.org>
Committed: Wed Mar 21 10:09:01 2018 +0100

----------------------------------------------------------------------
 .../apache/lucene/index/IndexFileDeleter.java   | 20 ------
 .../org/apache/lucene/index/IndexWriter.java    | 65 ++++++++++----------
 .../java/org/apache/lucene/util/IOUtils.java    | 31 +---------
 3 files changed, 34 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2539578c/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java b/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java
index 92f9a04..c605b5b 100644
--- a/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java
+++ b/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java
@@ -592,26 +592,6 @@ final class IndexFileDeleter implements Closeable {
     }
   }
 
-  /** Decrefs all provided files, ignoring any exceptions hit; call this if
-   *  you are already handling an exception. */
-  void decRefWhileHandlingException(Collection<String> files) {
-    assert locked();
-    Set<String> toDelete = new HashSet<>();
-    for(final String file : files) {
-      try {
-        if (decRef(file)) {
-          toDelete.add(file);
-        }
-      } catch (Throwable t) {
-      }
-    }
-
-    try {
-      deleteFiles(toDelete);
-    } catch (Throwable t) {
-    }
-  }
-
   /** Returns true if the file should now be deleted. */
   private boolean decRef(String fileName) {
     assert locked();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2539578c/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
index 1870d05..c0f9898 100644
--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
@@ -3409,27 +3409,29 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable
{
         maybeCloseOnTragicEvent();
       }
      
-      boolean success = false;
       try {
         if (anyChanges) {
           maybeMerge.set(true);
         }
         startCommit(toCommit);
-        success = true;
         if (pendingCommit == null) {
           return -1;
         } else {
           return seqNo;
         }
-      } finally {
-        if (!success) {
-          synchronized (this) {
-            if (filesToCommit != null) {
-              deleter.decRefWhileHandlingException(filesToCommit);
+      } catch (Throwable t) {
+        synchronized (this) {
+          if (filesToCommit != null) {
+            try {
+              deleter.decRef(filesToCommit);
+            } catch (Throwable t1) {
+              t.addSuppressed(t1);
+            } finally {
               filesToCommit = null;
             }
           }
         }
+        throw t;
       }
     }
   }
@@ -3568,7 +3570,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable
{
   private final void finishCommit() throws IOException {
 
     boolean commitCompleted = false;
-    boolean finished = false;
     String committedSegmentsFileName = null;
 
     try {
@@ -3580,7 +3581,8 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable
{
         }
 
         if (pendingCommit != null) {
-          try {
+          final Collection<String> commitFiles = this.filesToCommit;
+          try (Closeable finalizer = () -> deleter.decRef(commitFiles)) {
 
             if (infoStream.isEnabled("IW")) {
               infoStream.message("IW", "commit: pendingCommit != null");
@@ -3605,21 +3607,10 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable
{
             lastCommitChangeCount = pendingCommitChangeCount;
             rollbackSegments = pendingCommit.createBackupSegmentInfos();
 
-            finished = true;
           } finally {
             notifyAll();
-            try {
-              if (finished) {
-                // all is good
-                deleter.decRef(filesToCommit);
-              } else if (commitCompleted == false) {
-                // exc happened in finishCommit: not a tragedy
-                deleter.decRefWhileHandlingException(filesToCommit);
-              }
-            } finally {
-              pendingCommit = null;
-              filesToCommit = null;
-            }
+            pendingCommit = null;
+            this.filesToCommit = null;
           }
         } else {
           assert filesToCommit == null;
@@ -4824,7 +4815,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable
{
 
         testPoint("midStartCommit2");
 
-        synchronized(this) {
+        synchronized (this) {
 
           assert pendingCommit == null;
 
@@ -4863,7 +4854,23 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable
{
         }
 
         testPoint("midStartCommitSuccess");
-
+      } catch (Throwable t) {
+        synchronized(this) {
+          if (!pendingCommitSet) {
+            if (infoStream.isEnabled("IW")) {
+              infoStream.message("IW", "hit exception committing segments file");
+            }
+            try {
+              // Hit exception
+              deleter.decRef(filesToCommit);
+            } catch (Throwable t1) {
+              t.addSuppressed(t1);
+            } finally {
+              filesToCommit = null;
+            }
+          }
+        }
+        throw t;
       } finally {
         synchronized(this) {
           // Have our master segmentInfos record the
@@ -4871,16 +4878,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable
{
           // on error or success so we don't
           // double-write a segments_N file.
           segmentInfos.updateGeneration(toSync);
-
-          if (!pendingCommitSet) {
-            if (infoStream.isEnabled("IW")) {
-              infoStream.message("IW", "hit exception committing segments file");
-            }
-
-            // Hit exception
-            deleter.decRefWhileHandlingException(filesToCommit);
-            filesToCommit = null;
-          }
         }
       }
     } catch (VirtualMachineError tragedy) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2539578c/lucene/core/src/java/org/apache/lucene/util/IOUtils.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/util/IOUtils.java b/lucene/core/src/java/org/apache/lucene/util/IOUtils.java
index 350ae43..a556789 100644
--- a/lucene/core/src/java/org/apache/lucene/util/IOUtils.java
+++ b/lucene/core/src/java/org/apache/lucene/util/IOUtils.java
@@ -82,17 +82,13 @@ public final class IOUtils {
    */
   public static void close(Iterable<? extends Closeable> objects) throws IOException
{
     Throwable th = null;
-
     for (Closeable object : objects) {
       try {
         if (object != null) {
           object.close();
         }
       } catch (Throwable t) {
-        addSuppressed(th, t);
-        if (th == null) {
-          th = t;
-        }
+        th = useOrSuppress(th, t);
       }
     }
 
@@ -141,16 +137,6 @@ public final class IOUtils {
     }
   }
   
-  /** adds a Throwable to the list of suppressed Exceptions of the first Throwable
-   * @param exception this exception should get the suppressed one added
-   * @param suppressed the suppressed exception
-   */
-  private static void addSuppressed(Throwable exception, Throwable suppressed) {
-    if (exception != null && suppressed != null) {
-      exception.addSuppressed(suppressed);
-    }
-  }
-  
   /**
    * Wrapping the given {@link InputStream} in a reader using a {@link CharsetDecoder}.
    * Unlike Java's defaults this reader will throw an exception if your it detects 
@@ -237,10 +223,7 @@ public final class IOUtils {
         try {
           dir.deleteFile(name);
         } catch (Throwable t) {
-          addSuppressed(th, t);
-          if (th == null) {
-            th = t;
-          }
+          th = useOrSuppress(th, t);
         }
       }
     }
@@ -250,10 +233,6 @@ public final class IOUtils {
     }
   }
 
-  public static void deleteFiles(Directory dir, String... files) throws IOException {
-    deleteFiles(dir, Arrays.asList(files));
-  }
-  
   /**
    * Deletes all given files, suppressing all thrown IOExceptions.
    * <p>
@@ -304,17 +283,13 @@ public final class IOUtils {
    */
   public static void deleteFilesIfExist(Collection<? extends Path> files) throws IOException
{
     Throwable th = null;
-
     for (Path file : files) {
       try {
         if (file != null) {
           Files.deleteIfExists(file);
         }
       } catch (Throwable t) {
-        addSuppressed(th, t);
-        if (th == null) {
-          th = t;
-        }
+        th = useOrSuppress(th, t);
       }
     }
 


Mime
View raw message