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 2020/03/19 18:29:48 UTC

[GitHub] [phoenix] kadirozde commented on a change in pull request #735: PHOENIX-5734 - IndexScrutinyTool should not report rows beyond maxLoo…

kadirozde commented on a change in pull request #735: PHOENIX-5734 - IndexScrutinyTool should not report rows beyond maxLoo…
URL: https://github.com/apache/phoenix/pull/735#discussion_r395236000
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyWithMaxLookbackIT.java
 ##########
 @@ -0,0 +1,209 @@
+/*
+ * 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;
+
+import com.google.common.collect.Maps;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.regionserver.ScanInfoUtil;
+import org.apache.hadoop.mapreduce.Counters;
+import org.apache.hadoop.mapreduce.Job;
+import org.apache.phoenix.mapreduce.index.IndexScrutinyMapper;
+import org.apache.phoenix.mapreduce.index.IndexScrutinyTool;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
+import org.apache.phoenix.util.ManualEnvironmentEdge;
+import org.apache.phoenix.util.MetaDataUtil;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
+import org.apache.phoenix.util.TestUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.phoenix.mapreduce.index.PhoenixScrutinyJobCounters.INVALID_ROW_COUNT;
+import static org.apache.phoenix.mapreduce.index.PhoenixScrutinyJobCounters.BEYOND_MAX_LOOKBACK;
+import static org.apache.phoenix.mapreduce.index.PhoenixScrutinyJobCounters.VALID_ROW_COUNT;
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class IndexScrutinyWithMaxLookbackIT extends IndexScrutinyToolBaseIT {
+
+    private static PreparedStatement upsertDataStmt;
+    private static String dataTableFullName;
+    private static String schema;
+    private static String dataTableName;
+    private static String indexTableName;
+    private static String viewName;
+    private static boolean isViewIndex;
+    private static ManualEnvironmentEdge testClock;
+    public static final String UPSERT_DATA = "UPSERT INTO %s VALUES (?, ?, ?)";
+    public static final int MAX_LOOKBACK = 6;
+
+
+    @BeforeClass
+    public static synchronized void doSetup() throws Exception {
+        Map<String, String> props = Maps.newHashMapWithExpectedSize(2);
+        props.put(QueryServices.GLOBAL_INDEX_ROW_AGE_THRESHOLD_TO_DELETE_MS_ATTRIB, Long.toString(0));
+        props.put(ScanInfoUtil.PHOENIX_MAX_LOOKBACK_AGE_CONF_KEY,
+            Integer.toString(MAX_LOOKBACK));
+        setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+    }
+
+    @Test
+    public void testScrutinyOnRowsBeyondMaxLookBack() throws Exception {
+        schema = "S" + generateUniqueName();
+        dataTableName = "T" + generateUniqueName();
+        indexTableName = "I" + generateUniqueName();
+        dataTableFullName = SchemaUtil.getTableName(schema, dataTableName);
+        isViewIndex = false;
+        String dataTableDDL = "CREATE TABLE %s (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, "
+            + "ZIP INTEGER) COLUMN_ENCODED_BYTES=0, VERSIONS=1";
+        String indexTableDDL = "CREATE INDEX %s ON %s (NAME) INCLUDE (ZIP)";
+        testClock = new ManualEnvironmentEdge();
+
+        try (Connection conn =
+                 DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES))) {
+            conn.createStatement().execute(String.format(dataTableDDL, dataTableFullName));
+            conn.createStatement().execute(String.format(indexTableDDL, indexTableName,
+                dataTableFullName));
+            conn.commit();
+        }
+        upsertDataAndScrutinize(dataTableName, dataTableFullName, testClock);
+    }
+
+    @Test
+    public void testScrutinyOnRowsBeyondMaxLookback_viewIndex() throws Exception {
+        schema = "S"+generateUniqueName();
+        dataTableName = "T"+generateUniqueName();
+        dataTableFullName = SchemaUtil.getTableName(schema,dataTableName);
+        indexTableName = "VI"+generateUniqueName();
+        isViewIndex = true;
+        viewName = "V"+generateUniqueName();
+        String viewFullName = SchemaUtil.getTableName(schema,viewName);
+        String dataTableDDL = "CREATE TABLE %s (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, "
+            + "ZIP INTEGER) COLUMN_ENCODED_BYTES = 0, VERSIONS = 1 ";
+        String viewDDL = "CREATE VIEW %s AS SELECT * FROM %s";
+        String indexTableDDL = "CREATE INDEX %s ON %s (NAME) INCLUDE (ZIP) VERSIONS = 1";
+        testClock = new ManualEnvironmentEdge();
+
+        try (Connection conn =
+                 DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES))) {
+            conn.createStatement().execute(String.format(dataTableDDL, dataTableFullName));
+            conn.createStatement().execute(String.format(viewDDL, viewFullName, dataTableFullName));
+            conn.createStatement().execute(String.format(indexTableDDL, indexTableName,
+                viewFullName));
+            conn.commit();
+        }
+        upsertDataAndScrutinize(viewName, viewFullName, testClock);
+    }
+
+    private void upsertDataAndScrutinize(String tableName, String tableFullName,
 
 Review comment:
   Can we have tests for deletes in addition to upserts? I am also interested in the cases where rows are deleted within the max loopback window and before and after the scn.

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