You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by je...@apache.org on 2014/11/21 00:50:18 UTC
phoenix git commit: PHOENIX-1395: ResultSpooler spill files are left
behind in /tmp folder (Alicia Ying Shu)
Repository: phoenix
Updated Branches:
refs/heads/master 2d5acb4e9 -> 46aa58216
PHOENIX-1395: ResultSpooler spill files are left behind in /tmp folder (Alicia Ying Shu)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/46aa5821
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/46aa5821
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/46aa5821
Branch: refs/heads/master
Commit: 46aa582165825d215ba7f94ee28b1b957885c11d
Parents: 2d5acb4
Author: Jeffrey Zhong <je...@apache.org>
Authored: Thu Nov 20 15:39:05 2014 -0800
Committer: Jeffrey Zhong <je...@apache.org>
Committed: Thu Nov 20 15:39:05 2014 -0800
----------------------------------------------------------------------
.../phoenix/iterate/SpoolingResultIterator.java | 3 +
.../iterate/SpooledTmpFileDeleteTest.java | 127 +++++++++++++++++++
2 files changed, 130 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/46aa5821/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 87ed241..71ad7d7 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
@@ -116,6 +116,9 @@ public class SpoolingResultIterator implements PeekingResultIterator {
spoolFrom = new InMemoryResultIterator(data, chunk);
} else {
spoolFrom = new OnDiskResultIterator(spoolTo.getFile());
+ if (spoolTo.getFile() != null) {
+ spoolTo.getFile().deleteOnExit();
+ }
}
success = true;
} catch (IOException e) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/46aa5821/phoenix-core/src/test/java/org/apache/phoenix/iterate/SpooledTmpFileDeleteTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/iterate/SpooledTmpFileDeleteTest.java b/phoenix-core/src/test/java/org/apache/phoenix/iterate/SpooledTmpFileDeleteTest.java
new file mode 100644
index 0000000..4a205f9
--- /dev/null
+++ b/phoenix-core/src/test/java/org/apache/phoenix/iterate/SpooledTmpFileDeleteTest.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable
+ * law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
+ * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
+ * for the specific language governing permissions and limitations under the License.
+ */
+package org.apache.phoenix.iterate;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.phoenix.end2end.BaseClientManagedTimeIT;
+import org.apache.phoenix.end2end.ClientManagedTimeTest;
+import org.apache.phoenix.query.QueryServices;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+
+@Category(ClientManagedTimeTest.class)
+public class SpooledTmpFileDeleteTest extends BaseClientManagedTimeIT {
+ private Connection conn = null;
+ private Properties props = null;
+
+ @Before
+ public void setup() throws SQLException {
+ props = new Properties();
+ props.put(QueryServices.SPOOL_DIRECTORY, "/tmp");
+ props.setProperty(QueryServices.SPOOL_THRESHOLD_BYTES_ATTRIB, Integer.toString(1));
+ conn = DriverManager.getConnection(getUrl(), props);
+ Statement stmt = conn.createStatement();
+ stmt.execute("CREATE TABLE test (ID varchar NOT NULL PRIMARY KEY) SPLIT ON ('EA','EZ')");
+ stmt.execute("UPSERT INTO test VALUES ('AA')");
+ stmt.execute("UPSERT INTO test VALUES ('EB')");
+ stmt.execute("UPSERT INTO test VALUES ('FA')");
+ stmt.close();
+ conn.commit();
+ }
+
+ @Test
+ public void testDeleteAllSpooledTmpFiles() throws SQLException, Throwable {
+ File dir = new File("/tmp");
+ File[] files = null;
+
+ class FilenameFilter implements FileFilter {
+ @Override
+ public boolean accept(File dir) {
+ return dir.getName().toLowerCase().endsWith(".bin") &&
+ dir.getName().startsWith("ResultSpooler");
+ }
+ }
+
+ FilenameFilter fnameFilter = new FilenameFilter();
+
+ // clean up first
+ files = dir.listFiles(fnameFilter);
+ for (File file : files) {
+ file.delete();
+ }
+
+ String query = "select * from TEST";
+ Statement statement = conn.createStatement();
+ ResultSet rs = statement.executeQuery(query);
+ assertTrue(rs.next());
+ files = dir.listFiles(fnameFilter);
+ assertTrue(files.length > 0);
+ List<String> fileNames = new ArrayList<String>();
+ for (File file : files) {
+ fileNames.add(file.getName());
+ }
+
+ String preparedQuery = "select * from test where id = ?";
+ PreparedStatement pstmt = conn.prepareStatement(preparedQuery);
+ pstmt.setString(1, "EB");
+ ResultSet prs = pstmt.executeQuery(preparedQuery);
+ assertTrue(prs.next());
+ files = dir.listFiles(fnameFilter);
+ assertTrue(files.length > 0);
+ for (File file : files) {
+ fileNames.add(file.getName());
+ }
+
+ Connection conn2 = DriverManager.getConnection(getUrl(), props);
+ String query2 = "select * from TEST";
+ Statement statement2 = conn2.createStatement();
+ ResultSet rs2 = statement2.executeQuery(query2);
+ assertTrue(rs2.next());
+ files = dir.listFiles(fnameFilter);
+ assertTrue(files.length > 0);
+
+ String preparedQuery2 = "select * from test where id = ?";
+ PreparedStatement pstmt2 = conn2.prepareStatement(preparedQuery2);
+ pstmt2.setString(1, "EB");
+ ResultSet prs2 = pstmt2.executeQuery(preparedQuery2);
+ assertTrue(prs2.next());
+ files = dir.listFiles(fnameFilter);
+ assertTrue(files.length > 0);
+
+ conn.close();
+
+ files = dir.listFiles(fnameFilter);
+
+ for (File file : files) {
+ assertFalse(fileNames.contains(file.getName()));
+ }
+ conn2.close();
+ files = dir.listFiles(fnameFilter);
+ assertTrue(files.length == 0);
+ }
+
+}