kadirozde commented on a change in pull request #592: PHOENIX-5505 Index read 
repair does not repair unverified rows with h…
URL: https://github.com/apache/phoenix/pull/592#discussion_r331583391
 
 

 ##########
 File path: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexCheckerIT.java
 ##########
 @@ -207,10 +210,120 @@ public void testSkipPostIndexPartialRowUpdate() throws 
Exception {
         conn.close();
     }
 
+    @Test
+    public void testOnePhaseOverwiteFollowingTwoPhaseWrite() throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String dataTableName = generateUniqueName();
+            populateTable(dataTableName); // with two rows ('a', 'ab', 'abc', 
'abcd') and ('b', 'bc', 'bcd', 'bcde')
+            String indexTableName = generateUniqueName();
+            conn.createStatement().execute("CREATE INDEX " + indexTableName + 
"1 on " +
+                    dataTableName + " (val1) include (val2, val3)" + (async ? 
"ASYNC" : ""));
+            conn.createStatement().execute("CREATE INDEX " + indexTableName + 
"2 on " +
+                    dataTableName + " (val2) include (val1, val3)" + (async ? 
"ASYNC" : ""));
+            if (async) {
+                // run the index MR job.
+                IndexToolIT.runIndexTool(true, false, null, dataTableName, 
indexTableName + "1");
+                IndexToolIT.runIndexTool(true, false, null, dataTableName, 
indexTableName + "2");
+            }
+            // Two Phase write. This write is recoverable
+            IndexRegionObserver.setSkipPostIndexUpdatesForTesting(true);
+            conn.createStatement().execute("upsert into " + dataTableName + " 
values ('c', 'cd', 'cde', 'cdef')");
+            conn.commit();
+            // One Phase write. This write is not recoverable
+            IndexRegionObserver.setSkipDataTableUpdatesForTesting(true);
+            conn.createStatement().execute("upsert into " + dataTableName + " 
values ('c', 'cd', 'cdee', 'cdfg')");
+            conn.commit();
+            // Let three phase writes happen as in the normal case
+            IndexRegionObserver.setSkipDataTableUpdatesForTesting(false);
+            IndexRegionObserver.setSkipPostIndexUpdatesForTesting(false);
+            String selectSql = "SELECT val2, val3 from " + dataTableName + " 
WHERE val1  = 'cd'";
+            // Verify that we will read from the first index table
+            assertExplainPlan(conn, selectSql, dataTableName, indexTableName + 
"1");
+            // Verify the first write is visible but the second one is not
+            ResultSet rs = conn.createStatement().executeQuery(selectSql);
+            assertTrue(rs.next());
+            assertEquals("cde", rs.getString(1));
+            assertEquals("cdef", rs.getString(2));
+            assertFalse(rs.next());
+        }
+    }
+
+    @Test
+    public void testOnePhaseOverwrite() throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String dataTableName = generateUniqueName();
+            populateTable(dataTableName); // with two rows ('a', 'ab', 'abc', 
'abcd') and ('b', 'bc', 'bcd', 'bcde')
+            String indexTableName = generateUniqueName();
+            conn.createStatement().execute("CREATE INDEX " + indexTableName + 
"1 on " +
+                    dataTableName + " (val1) include (val2, val3)" + (async ? 
"ASYNC" : ""));
+            conn.createStatement().execute("CREATE INDEX " + indexTableName + 
"2 on " +
+                    dataTableName + " (val2) include (val1, val3)" + (async ? 
"ASYNC" : ""));
+            if (async) {
+                // run the index MR job.
+                IndexToolIT.runIndexTool(true, false, null, dataTableName, 
indexTableName + "1");
+                IndexToolIT.runIndexTool(true, false, null, dataTableName, 
indexTableName + "2");
+            }
+            // Configure IndexRegionObserver 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 (one overwrite)
+            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);
+            String selectSql =  "SELECT val2, val3 from " + dataTableName + " 
WHERE val1  = 'ab'";
+            // Verify that we will read from the first index table
+            assertExplainPlan(conn, selectSql, dataTableName, indexTableName + 
"1");
+            // Verify that one phase write has no effect
+            ResultSet rs = conn.createStatement().executeQuery(selectSql);
+            assertTrue(rs.next());
+            assertEquals("abc", rs.getString(1));
+            assertEquals("abcd", rs.getString(2));
+            assertFalse(rs.next());
+            selectSql =  "SELECT val2, val3 from " + dataTableName + " WHERE 
val2  = 'abcc'";
+            // Verify that we will read from the second index table
+            assertExplainPlan(conn, selectSql, dataTableName, indexTableName + 
"2");
+            rs = conn.createStatement().executeQuery(selectSql);
+            // Verify that one phase writes have no effect
+            assertFalse(rs.next());
+            // Configure IndexRegionObserver 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  (two overwrites)
+            IndexRegionObserver.setSkipDataTableUpdatesForTesting(true);
+            IndexRegionObserver.setSkipPostIndexUpdatesForTesting(true);
+            conn.createStatement().execute("upsert into " + dataTableName + " 
(id, val2) values ('a', 'abccc')");
+            conn.commit();
+            conn.createStatement().execute("upsert into " + dataTableName + " 
(id, val2) values ('a', 'abcccc')");
+            conn.commit();
+            IndexRegionObserver.setSkipDataTableUpdatesForTesting(false);
+            IndexRegionObserver.setSkipPostIndexUpdatesForTesting(false);
+            selectSql =  "SELECT val2, val3 from " + dataTableName + " WHERE 
val1  = 'ab'";
+            // Verify that we will read from the first index table
+            assertExplainPlan(conn, selectSql, dataTableName, indexTableName + 
"1");
+            // Verify that one phase writes have no effect
+            rs = conn.createStatement().executeQuery(selectSql);
+            assertTrue(rs.next());
+            assertEquals("abc", rs.getString(1));
+            assertEquals("abcd", rs.getString(2));
+            assertFalse(rs.next());
+            selectSql =  "SELECT val2, val3 from " + dataTableName + " WHERE 
val2  = 'abccc'";
+            // Verify that we will read from the second index table
+            assertExplainPlan(conn, selectSql, dataTableName, indexTableName + 
"2");
+            rs = conn.createStatement().executeQuery(selectSql);
+            // Verify that one phase writes have no effect
+            assertFalse(rs.next());
+            selectSql =  "SELECT val2, val3 from " + dataTableName + " WHERE 
val2  = 'abcccc'";
+            // Verify that we will read from the second index table
+            assertExplainPlan(conn, selectSql, dataTableName, indexTableName + 
"2");
+            rs = conn.createStatement().executeQuery(selectSql);
+            // Verify that one phase writes have no effect
+            assertFalse(rs.next());
+        }
+    }
+
     @Test
     public void testSkipDataTableAndPostIndexPartialRowUpdate() throws 
Exception {
 
 Review comment:
   Done.

----------------------------------------------------------------
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