phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeffr...@apache.org
Subject git commit: PHOENIX-1396: Avoid unnecessary ResultSpooler.bin files creation/deletion every time SpoolingResultIterator is used
Date Wed, 05 Nov 2014 17:57:20 GMT
Repository: phoenix
Updated Branches:
  refs/heads/master 1fb89e4ab -> 237c55614


PHOENIX-1396: Avoid unnecessary ResultSpooler.bin files creation/deletion every time SpoolingResultIterator
is used


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/237c5561
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/237c5561
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/237c5561

Branch: refs/heads/master
Commit: 237c55614133f9317e7171b329ca7b966c0c28ff
Parents: 1fb89e4
Author: Jeffrey Zhong <jeffreyz@apache.org>
Authored: Wed Nov 5 09:56:19 2014 -0800
Committer: Jeffrey Zhong <jeffreyz@apache.org>
Committed: Wed Nov 5 09:56:19 2014 -0800

----------------------------------------------------------------------
 .../phoenix/iterate/SpoolingResultIterator.java    | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/237c5561/phoenix-core/src/main/java/org/apache/phoenix/iterate/SpoolingResultIterator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/SpoolingResultIterator.java
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/SpoolingResultIterator.java
index 0ba6554..2a5080e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/SpoolingResultIterator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/SpoolingResultIterator.java
@@ -88,14 +88,12 @@ public class SpoolingResultIterator implements PeekingResultIterator {
     */
     SpoolingResultIterator(ResultIterator scanner, MemoryManager mm, final int thresholdBytes,
final long maxSpoolToDisk, final String spoolDirectory) throws SQLException {
         boolean success = false;
-        boolean usedOnDiskIterator = false;
         final MemoryChunk chunk = mm.allocate(0, thresholdBytes);
-        File tempFile = null;
+        DeferredFileOutputStream spoolTo = null;
         try {
             // Can't be bigger than int, since it's the max of the above allocation
             int size = (int)chunk.getSize();
-            tempFile = File.createTempFile("ResultSpooler",".bin", new File(spoolDirectory));
-            DeferredFileOutputStream spoolTo = new DeferredFileOutputStream(size, tempFile)
{
+            spoolTo = new DeferredFileOutputStream(size, "ResultSpooler",".bin", new File(spoolDirectory))
{
                 @Override
                 protected void thresholdReached() throws IOException {
                     super.thresholdReached();
@@ -115,14 +113,12 @@ public class SpoolingResultIterator implements PeekingResultIterator
{
                 }
                 maxSize = Math.max(length, maxSize);
             }
-            spoolTo.close();
             if (spoolTo.isInMemory()) {
                 byte[] data = spoolTo.getData();
                 chunk.resize(data.length);
                 spoolFrom = new InMemoryResultIterator(data, chunk);
             } else {
                 spoolFrom = new OnDiskResultIterator(maxSize, spoolTo.getFile());
-                usedOnDiskIterator = true;
             }
             success = true;
         } catch (IOException e) {
@@ -132,9 +128,14 @@ public class SpoolingResultIterator implements PeekingResultIterator
{
                 scanner.close();
             } finally {
                 try {
-                    if (!usedOnDiskIterator && tempFile != null) {
-                        tempFile.delete();
+                    if (spoolTo != null) {
+                        if(!success && spoolTo.getFile() != null){
+                            spoolTo.getFile().delete();
+                        }
+                        spoolTo.close();
                     }
+                } catch (IOException ignored) {
+                  // ignore close error
                 } finally {
                     if (!success) {
                         chunk.close();


Mime
View raw message