This is an automated email from the ASF dual-hosted git repository.

pboado pushed a commit to branch 4.x-cdh5.16
in repository https://gitbox.apache.org/repos/asf/phoenix.git

commit bd4f52f576d11b779a82d89dd20354188adaf850
Author: Kadir <kozde...@salesforce.com>
AuthorDate: Thu Dec 13 01:53:38 2018 +0000

    PHOENIX-5025 Tool to clean up orphan views (addendum)
---
 .../apache/phoenix/end2end/OrphanViewToolIT.java   | 23 +++++++++++++--------
 .../apache/phoenix/mapreduce/OrphanViewTool.java   | 24 ++++++++++++----------
 2 files changed, 28 insertions(+), 19 deletions(-)

diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrphanViewToolIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrphanViewToolIT.java
index f9a1785..ab78ecd 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrphanViewToolIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrphanViewToolIT.java
@@ -27,9 +27,9 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
+import java.io.FileReader;
 import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
+import java.io.LineNumberReader;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
@@ -206,9 +206,13 @@ public class OrphanViewToolIT extends 
ParallelStatsDisabledIT {
     }
 
     private void verifyLineCount(String fileName, long lineCount) throws 
IOException {
-        if (Files.lines(Paths.get(fileName)).count() != lineCount)
-            LOG.debug(Files.lines(Paths.get(fileName)).count() + " != " + 
lineCount);
-        assertTrue(Files.lines(Paths.get(fileName)).count() == lineCount);
+        LineNumberReader reader = new LineNumberReader(new 
FileReader(fileName));
+        while (reader.readLine() != null) {
+        }
+        int count = reader.getLineNumber();
+        if (count != lineCount)
+            LOG.debug(count + " != " + lineCount);
+        assertTrue(count == lineCount);
     }
 
     private void verifyCountQuery(Connection connection, String query, String 
schemaName, long count)
@@ -238,7 +242,6 @@ public class OrphanViewToolIT extends 
ParallelStatsDisabledIT {
         }
     }
 
-
     private void verifyNoChildLink(Connection connection, String 
viewSchemaName) throws Exception {
         // Verify that there there is no link in the system child link table
         verifyCountQuery(connection, countChildLinksQuery, viewSchemaName, 0);
@@ -264,6 +267,7 @@ public class OrphanViewToolIT extends 
ParallelStatsDisabledIT {
                 schemaName == null ? "IS NULL" : "= '" + schemaName + "'"));
         connection.commit();
     }
+
     @Test
     public void testDeleteBaseTableRows() throws Exception {
         String baseTableName = generateUniqueName();
@@ -438,7 +442,8 @@ public class OrphanViewToolIT extends 
ParallelStatsDisabledIT {
         }
     }
 
-    public static String[] getArgValues(boolean clean, boolean identify, 
boolean outputPath, boolean inputPath) {
+    public static String[] getArgValues(boolean clean, boolean identify, 
boolean outputPath, boolean inputPath)
+            throws InterruptedException{
         final List<String> args = Lists.newArrayList();
         if (outputPath) {
             args.add("-op");
@@ -454,8 +459,10 @@ public class OrphanViewToolIT extends 
ParallelStatsDisabledIT {
         if (identify) {
             args.add("-i");
         }
+        final long ageMs = 2000;
+        Thread.sleep(ageMs);
         args.add("-a");
-        args.add("0");
+        args.add(Long.toString(ageMs));
         return args.toArray(new String[0]);
     }
 
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/OrphanViewTool.java 
b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/OrphanViewTool.java
index a8a30b6..713fb05 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/OrphanViewTool.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/OrphanViewTool.java
@@ -812,17 +812,6 @@ public class OrphanViewTool extends Configured implements 
Tool {
             } catch (IllegalStateException e) {
                 printHelpAndExit(e.getMessage(), getOptions());
             }
-
-            Properties props = new Properties();
-            long scn = System.currentTimeMillis() - ageMs;
-            props.setProperty("CurrentSCN", Long.toString(scn));
-            connection = ConnectionUtil.getInputConnection(configuration);
-            PhoenixConnection phoenixConnection = 
connection.unwrap(PhoenixConnection.class);
-
-            if (clean) {
-                // Take a snapshot of system tables to be modified
-                createSnapshot(phoenixConnection, scn);
-            }
             if (outputPath != null) {
                 // Create files to log orphan views and links
                 for (int i = VIEW; i < ORPHAN_TYPE_COUNT; i++) {
@@ -834,7 +823,20 @@ public class OrphanViewTool extends Configured implements 
Tool {
                     writer[i] = new BufferedWriter(new FileWriter(file));
                 }
             }
+            Properties props = new Properties();
+            long scn = System.currentTimeMillis() - ageMs;
+            props.setProperty("CurrentSCN", Long.toString(scn));
+            connection = ConnectionUtil.getInputConnection(configuration, 
props);
+            PhoenixConnection phoenixConnection = 
connection.unwrap(PhoenixConnection.class);
             identifyOrphanViews(phoenixConnection);
+            if (clean) {
+                // Close the connection with SCN
+                phoenixConnection.close();
+                connection = ConnectionUtil.getInputConnection(configuration);
+                phoenixConnection = connection.unwrap(PhoenixConnection.class);
+                // Take a snapshot of system tables to be modified
+                createSnapshot(phoenixConnection, scn);
+            }
             for (Map.Entry<Key, View> entry : orphanViewSet.entrySet()) {
                 try {
                     dropOrLogOrphanViews(phoenixConnection, configuration, 
entry.getKey());

Reply via email to