mirror of https://github.com/apache/lucene.git
LUCENE-4209: Enforce cleanup on success and failure while sorting partitions
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1359953 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
20b748a484
commit
891dcd75e9
|
@ -193,6 +193,8 @@ public final class Sort {
|
|||
output.delete();
|
||||
|
||||
ArrayList<File> merges = new ArrayList<File>();
|
||||
boolean success2 = false;
|
||||
try {
|
||||
ByteSequencesReader is = new ByteSequencesReader(input);
|
||||
boolean success = false;
|
||||
try {
|
||||
|
@ -205,12 +207,15 @@ public final class Sort {
|
|||
// 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++;
|
||||
}
|
||||
}
|
||||
|
@ -229,14 +234,19 @@ public final class Sort {
|
|||
// 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);
|
||||
}
|
||||
success2 = true;
|
||||
} finally {
|
||||
for (File file : merges) {
|
||||
file.delete();
|
||||
}
|
||||
if (!success2) {
|
||||
output.delete();
|
||||
}
|
||||
}
|
||||
|
||||
sortInfo.totalTime = (System.currentTimeMillis() - sortInfo.totalTime);
|
||||
|
|
Loading…
Reference in New Issue