gjacoby126 commented on a change in pull request #598: PHOENIX-5515 Able to 
write indexed value to data table without writin…
URL: https://github.com/apache/phoenix/pull/598#discussion_r334200312
 
 

 ##########
 File path: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexCheckerIT.java
 ##########
 @@ -317,50 +358,94 @@ public void testOnePhaseOverwrite() throws Exception {
             rs = conn.createStatement().executeQuery(selectSql);
             // Verify that one phase writes have no effect
             assertFalse(rs.next());
+            // Add rows and check everything is still okay
+            verifyTableHealth(conn, dataTableName, indexTableName);
         }
     }
 
     @Test
-    public void testSkipDataTableAndPostIndexPartialRowUpdate() throws 
Exception {
+    public void testFailDataTableAndPostIndexRowUpdate() throws Exception {
         String dataTableName = generateUniqueName();
         populateTable(dataTableName); // with two rows ('a', 'ab', 'abc', 
'abcd') and ('b', 'bc', 'bcd', 'bcde')
-        Connection conn = DriverManager.getConnection(getUrl());
-        String indexName = generateUniqueName();
-        conn.createStatement().execute("CREATE INDEX " + indexName + "1 on " +
-                dataTableName + " (val1) include (val2, val3)" + (async ? 
"ASYNC" : ""));
-        conn.createStatement().execute("CREATE INDEX " + indexName + "2 on " +
-                dataTableName + " (val2) include (val1, val3)" + (async ? 
"ASYNC" : ""));
-        if (async) {
-            // run the index MR job.
-            IndexToolIT.runIndexTool(true, false, null, dataTableName, 
indexName + "1");
-            IndexToolIT.runIndexTool(true, false, null, dataTableName, 
indexName + "2");
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String indexName = generateUniqueName();
+            conn.createStatement().execute("CREATE INDEX " + indexName + "1 on 
" +
+                    dataTableName + " (val1) include (val2, val3)" + (async ? 
"ASYNC" : ""));
+            conn.createStatement().execute("CREATE INDEX " + indexName + "2 on 
" +
+                    dataTableName + " (val2) include (val1, val3)" + (async ? 
"ASYNC" : ""));
+            if (async) {
+                // run the index MR job.
+                IndexToolIT.runIndexTool(true, false, null, dataTableName, 
indexName + "1");
+                IndexToolIT.runIndexTool(true, false, null, dataTableName, 
indexName + "2");
+            }
+            // Configure IndexRegionObserver to fail the last two write phase 
(i.e., the data table update and post index update phase)
+            // and check that this does not impact the correctness
+            IndexRegionObserver.setFailDataTableUpdatesForTesting(true);
+            IndexRegionObserver.setFailPostIndexUpdatesForTesting(true);
+            conn.createStatement().execute("upsert into " + dataTableName + " 
(id, val2) values ('a', 'abcc')");
+            commitWithException(conn);
+            IndexRegionObserver.setFailDataTableUpdatesForTesting(false);
+            IndexRegionObserver.setFailPostIndexUpdatesForTesting(false);
+            conn.createStatement().execute("upsert into " + dataTableName + " 
(id, val3) values ('a', 'abcdd')");
+            conn.commit();
+            String selectSql = "SELECT val2, val3 from " + dataTableName + " 
WHERE val1  = 'ab'";
+            // Verify that we will read from the first index table
+            assertExplainPlan(conn, selectSql, dataTableName, indexName + "1");
+            ResultSet rs = conn.createStatement().executeQuery(selectSql);
+            assertTrue(rs.next());
+            assertEquals("abc", rs.getString(1));
+            assertEquals("abcdd", rs.getString(2));
+            assertFalse(rs.next());
+            selectSql = "SELECT val2, val3 from " + dataTableName + " WHERE 
val2  = 'abc'";
+            // Verify that we will read from the second index table
+            assertExplainPlan(conn, selectSql, dataTableName, indexName + "2");
+            rs = conn.createStatement().executeQuery(selectSql);
+            assertTrue(rs.next());
+            assertEquals("abc", rs.getString(1));
+            assertEquals("abcdd", rs.getString(2));
+            assertFalse(rs.next());
+            // Add rows and check everything is still okay
+            verifyTableHealth(conn, dataTableName, indexName);
         }
-        // Configure Indexer to skip the last two write phase (i.e., the data 
table update and post index update phase)
-        // and check that this does not impact the correctness
-        IndexRegionObserver.setSkipDataTableUpdatesForTesting(true);
-        IndexRegionObserver.setSkipPostIndexUpdatesForTesting(true);
-        conn.createStatement().execute("upsert into " + dataTableName + " (id, 
val2) values ('a', 'abcc')");
-        conn.commit();
-        IndexRegionObserver.setSkipDataTableUpdatesForTesting(false);
-        IndexRegionObserver.setSkipPostIndexUpdatesForTesting(false);
-        conn.createStatement().execute("upsert into " + dataTableName + " (id, 
val3) values ('a', 'abcdd')");
+    }
+
+    static private void commitWithException(Connection conn) {
+        try {
+            conn.commit();
+            IndexRegionObserver.setFailPreIndexUpdatesForTesting(false);
 
 Review comment:
   nit: could be useful to have these three lines setting to false in an After 
method to guarantee that they're always reset between tests. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to