You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2012/07/11 01:42:31 UTC

svn commit: r1359954 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/suggest/ lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/Sort.java

Author: uschindler
Date: Tue Jul 10 23:42:30 2012
New Revision: 1359954

URL: http://svn.apache.org/viewvc?rev=1359954&view=rev
Log:
Merged revision(s) 1359953 from lucene/dev/trunk:
LUCENE-4209: Enforce cleanup on success and failure while sorting partitions

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/suggest/   (props changed)
    lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/Sort.java

Modified: lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/Sort.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/Sort.java?rev=1359954&r1=1359953&r2=1359954&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/Sort.java (original)
+++ lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/Sort.java Tue Jul 10 23:42:30 2012
@@ -193,50 +193,60 @@ public final class Sort {
     output.delete();
 
     ArrayList<File> merges = new ArrayList<File>();
-    ByteSequencesReader is = new ByteSequencesReader(input);
-    boolean success = false;
+    boolean success2 = false;
     try {
-      int lines = 0;
-      while ((lines = readPartition(is)) > 0) {                    
-        merges.add(sortPartition(lines));
-        sortInfo.tempMergeFiles++;
-        sortInfo.lines += lines;
-
-        // Handle intermediate merges.
-        if (merges.size() == maxTempFiles) {
-          File intermediate = File.createTempFile("sort", "intermediate", tempDirectory);
-          mergePartitions(merges, intermediate);
-          for (File file : merges) {
-            file.delete();
-          }
-          merges.clear();
-          merges.add(intermediate);
+      ByteSequencesReader is = new ByteSequencesReader(input);
+      boolean success = false;
+      try {
+        int lines = 0;
+        while ((lines = readPartition(is)) > 0) {
+          merges.add(sortPartition(lines));
           sortInfo.tempMergeFiles++;
+          sortInfo.lines += lines;
+
+          // Handle intermediate merges.
+          if (merges.size() == maxTempFiles) {
+            File intermediate = File.createTempFile("sort", "intermediate", tempDirectory);
+            try {
+              mergePartitions(merges, intermediate);
+            } finally {
+              for (File file : merges) {
+                file.delete();
+              }
+              merges.clear();
+              merges.add(intermediate);
+            }
+            sortInfo.tempMergeFiles++;
+          }
         }
+        success = true;
+      } finally {
+        if (success)
+          IOUtils.close(is);
+        else
+          IOUtils.closeWhileHandlingException(is);
       }
-      success = true;
+
+      // One partition, try to rename or copy if unsuccessful.
+      if (merges.size() == 1) {     
+        File single = merges.get(0);
+        // If simple rename doesn't work this means the output is
+        // on a different volume or something. Copy the input then.
+        if (!single.renameTo(output)) {
+          copy(single, output);
+        }
+      } else { 
+        // otherwise merge the partitions with a priority queue.
+        mergePartitions(merges, output);
+      }
+      success2 = true;
     } finally {
-      if (success)
-        IOUtils.close(is);
-      else
-        IOUtils.closeWhileHandlingException(is);
-    }
-
-    // One partition, try to rename or copy if unsuccessful.
-    if (merges.size() == 1) {     
-      File single = merges.get(0);
-      // If simple rename doesn't work this means the output is
-      // on a different volume or something. Copy the input then.
-      if (!single.renameTo(output)) {
-        copy(single, output);
-        single.delete();
-      }
-    } else { 
-      // otherwise merge the partitions with a priority queue.                  
-      mergePartitions(merges, output);                            
       for (File file : merges) {
         file.delete();
       }
+      if (!success2) {
+        output.delete();
+      }
     }
 
     sortInfo.totalTime = (System.currentTimeMillis() - sortInfo.totalTime);