You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by GitBox <gi...@apache.org> on 2019/05/30 22:50:41 UTC

[GitHub] [phoenix] gjacoby126 commented on a change in pull request #469: PHOENIX-5156 Consistent Global Indexes for Non-Transactional Tables

gjacoby126 commented on a change in pull request #469: PHOENIX-5156 Consistent Global Indexes for Non-Transactional Tables
URL: https://github.com/apache/phoenix/pull/469#discussion_r289169188
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexCheckerIT.java
 ##########
 @@ -0,0 +1,257 @@
+/*
+ * 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.end2end.index;
+
+import static org.apache.phoenix.query.QueryServices.INDEX_REGION_OBSERVER_ENABLED_ATTRIB;
+import static org.apache.phoenix.query.QueryServices.INDEX_FAILURE_DISABLE_INDEX;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+import org.apache.phoenix.end2end.BaseUniqueNamesOwnClusterIT;
+import org.apache.phoenix.end2end.IndexToolIT;
+import org.apache.phoenix.hbase.index.IndexRegionObserver;
+import org.apache.phoenix.util.QueryUtil;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import com.google.common.collect.Lists;
+
+@RunWith(Parameterized.class)
+public class GlobalIndexCheckerIT extends BaseUniqueNamesOwnClusterIT {
+    private final boolean async;
+    private final String tableDDLOptions;
+
+    public GlobalIndexCheckerIT(boolean async, boolean encoded) {
+        this.async = async;
+        StringBuilder optionBuilder = new StringBuilder();
+        if (!encoded) {
+            optionBuilder.append(" COLUMN_ENCODED_BYTES=0 ");
+        }
+        this.tableDDLOptions = optionBuilder.toString();
+    }
+
+    @BeforeClass
+    public static void doSetup() throws Exception {
+        Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
+        props.put(INDEX_REGION_OBSERVER_ENABLED_ATTRIB, Boolean.toString(true));
+        props.put(INDEX_FAILURE_DISABLE_INDEX, Boolean.toString(false));
+        setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+    }
+
+    @Parameters(
+            name = "async={0},encoded={1}")
+    public static Collection<Object[]> data() {
+        List<Object[]> list = Lists.newArrayListWithExpectedSize(4);
+        boolean[] Booleans = new boolean[]{true, false};
+            for (boolean async : Booleans) {
+                for (boolean encoded : Booleans) {
+                    list.add(new Object[]{async, encoded});
+                }
+            }
+        return list;
+    }
+
+    public static void assertExplainPlan(Connection conn, String selectSql,
+                                         String dataTableFullName, String indexTableFullName) throws SQLException {
+        ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
+        String actualExplainPlan = QueryUtil.getExplainPlan(rs);
+        IndexToolIT.assertExplainPlan(false, actualExplainPlan, dataTableFullName, indexTableFullName);
+    }
+
+    private void populateTable(String tableName) throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        conn.createStatement().execute("create table " + tableName +
+                " (id varchar(10) not null primary key, val1 varchar(10), val2 varchar(10), val3 varchar(10))" + tableDDLOptions);
+        conn.createStatement().execute("upsert into " + tableName + " values ('a', 'ab', 'abc', 'abcd')");
+        conn.commit();
+        conn.createStatement().execute("upsert into " + tableName + " values ('b', 'bc', 'bcd', 'bcde')");
+        conn.commit();
+        conn.close();
+    }
+
+    @Test
+    public void testSkipPostIndexDeleteUpdate() throws Exception {
+        String dataTableName = generateUniqueName();
+        populateTable(dataTableName);
+        Connection conn = DriverManager.getConnection(getUrl());
+        String indexName = generateUniqueName();
+        conn.createStatement().execute("CREATE INDEX " + indexName + " on " +
+                dataTableName + " (val1) include (val2, val3)" + (async ? "ASYNC" : ""));
+        if (async) {
+            // run the index MR job.
+            IndexToolIT.runIndexTool(true, false, null, dataTableName, indexName);
+        }
+        String selectSql =  "SELECT id from " + dataTableName + " WHERE val1  = 'ab'";
+        ResultSet rs = conn.createStatement().executeQuery(selectSql);
+        assertTrue(rs.next());
+        assertEquals("a", rs.getString(1));
+        assertFalse(rs.next());
+
+        // Configure Indexer to skip the last write phase (i.e., the post index update phase) where the verify flag is set
+        // to true and/or index rows are deleted and check that this does not impact the correctness
+        IndexRegionObserver.setSkipPostIndexUpdatesForTesting(true);
+        String dml = "DELETE from " + dataTableName + " WHERE id  = 'a'";
+        assertEquals(1, conn.createStatement().executeUpdate(dml));
+        conn.commit();
+
+        // The index rows are actually not deleted yet because Indexer skipped delete operation. However, they are
+        // made unverified in the pre index update phase (i.e., the first write phase)
+        dml = "DELETE from " + dataTableName + " WHERE val1  = 'ab'";
+        // This DML will scan the Index table and detect unverified index rows. This will trigger read repair which
+        // result in deleting these rows since the corresponding data table rows are deleted already. So, the number of
+        // rows to be deleted by the "DELETE" DML will be zero since the rows deleted by read repair will not be visible
+        // to the DML
+        assertEquals(0,conn.createStatement().executeUpdate(dml));
+
+        // Delete the index row directly
 
 Review comment:
   nit: comment is incorrect. 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services