From issues-return-5143-archive-asf-public=cust-asf.ponee.io@phoenix.apache.org Thu Mar 14 18:57:55 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 9AE681807C5 for ; Thu, 14 Mar 2019 19:57:54 +0100 (CET) Received: (qmail 91997 invoked by uid 500); 14 Mar 2019 18:57:53 -0000 Mailing-List: contact issues-help@phoenix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.apache.org Delivered-To: mailing list issues@phoenix.apache.org Received: (qmail 91943 invoked by uid 99); 14 Mar 2019 18:57:53 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Mar 2019 18:57:53 +0000 From: GitBox To: issues@phoenix.apache.org Subject: [GitHub] [phoenix] gjacoby126 commented on a change in pull request #457: PHOENIX-5190 Implement TaskRegionObserver for Index rebuild Message-ID: <155258987312.20105.9366221011338852733.gitbox@gitbox.apache.org> Date: Thu, 14 Mar 2019 18:57:53 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit gjacoby126 commented on a change in pull request #457: PHOENIX-5190 Implement TaskRegionObserver for Index rebuild URL: https://github.com/apache/phoenix/pull/457#discussion_r265708755 ########## File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexRebuildTaskIT.java ########## @@ -0,0 +1,200 @@ +/* + * 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 org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.Admin; +import org.apache.hadoop.hbase.client.Table; +import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.phoenix.coprocessor.TaskRegionObserver; +import org.apache.phoenix.jdbc.PhoenixConnection; +import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData; +import org.apache.phoenix.query.ConnectionQueryServices; +import org.apache.phoenix.query.QueryServicesOptions; +import org.apache.phoenix.schema.PTable; +import org.apache.phoenix.util.PhoenixRuntime; +import org.apache.phoenix.util.PropertiesUtil; +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 java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Timestamp; +import java.util.Arrays; +import java.util.Collection; +import java.util.Properties; + +import static org.apache.phoenix.util.PhoenixRuntime.TENANT_ID_ATTRIB; +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +@RunWith(Parameterized.class) +public class IndexRebuildTaskIT extends BaseUniqueNamesOwnClusterIT { + private final boolean isMultiTenant; + protected static String TENANT1 = "tenant1"; + private final String TENANT_SPECIFIC_URL1 = getUrl() + ';' + TENANT_ID_ATTRIB + "=" + TENANT1; + private static RegionCoprocessorEnvironment TaskRegionEnvironment; + private static int numOfRuns = 1; + + @BeforeClass + public static void doSetup() throws Exception { + SplitSystemCatalogIT.doSetup(); + TaskRegionEnvironment = + getUtility() + .getRSForFirstRegionInTable( + PhoenixDatabaseMetaData.SYSTEM_TASK_HBASE_TABLE_NAME) + .getRegions(PhoenixDatabaseMetaData.SYSTEM_TASK_HBASE_TABLE_NAME) + .get(0).getCoprocessorHost() + .findCoprocessorEnvironment(TaskRegionObserver.class.getName()); + } + + public IndexRebuildTaskIT(boolean isMultiTenant) { + this.isMultiTenant = isMultiTenant; + } + + @Parameters(name="IndexRebuildTaskIT_multiTenant={0}") + public static Collection data() { + return Arrays.asList(new Boolean[] { + true , false}); + } + private String generateDDL(String format) { + StringBuilder optionsBuilder = new StringBuilder(); + + if (isMultiTenant) { + if (optionsBuilder.length() !=0 ) + optionsBuilder.append(","); + optionsBuilder.append("MULTI_TENANT=true"); + } + return String.format(format, isMultiTenant ? "TENANT_ID VARCHAR NOT NULL, " : "", + isMultiTenant ? "TENANT_ID, " : "", optionsBuilder.toString()); + } + + @Test + public void testIndexRebuildTask() throws Exception { + String baseTable = generateUniqueName(); + Connection conn = null; + Connection viewConn = null; + try { + conn = DriverManager.getConnection(getUrl()); + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + if (isMultiTenant) { + props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, TENANT1); + } + + viewConn =DriverManager.getConnection(getUrl(), props); + String ddlFormat = + "CREATE TABLE IF NOT EXISTS " + baseTable + " (" + + " %s PK2 VARCHAR NOT NULL, V1 VARCHAR, V2 VARCHAR " + + " CONSTRAINT NAME_PK PRIMARY KEY (%s PK2)" + " ) %s"; + conn.createStatement().execute(generateDDL(ddlFormat)); + conn.commit(); + // Create a view + String viewName = generateUniqueName(); + String viewDDL = "CREATE VIEW " + viewName + " AS SELECT * FROM " + baseTable; + viewConn.createStatement().execute(viewDDL); + + // Create index + String indexName = generateUniqueName(); + String idxSDDL = String.format("CREATE INDEX %s ON %s (V1)", indexName, viewName); + + viewConn.createStatement().execute(idxSDDL); + + // Insert rows + viewConn.createStatement() + .execute(String.format("UPSERT INTO %s VALUES('%s', '%s', '%s')", viewName, "x", "y", "z")); + viewConn.commit(); + + String data = "{GusWorkId:abc, DisableBefore:true}"; + + // Add a task to System.Task to build indexes + TaskRegionObserver.addTask(conn.unwrap(PhoenixConnection.class), PTable.TaskType.INDEX_REBUILD, + isMultiTenant? TENANT1 : null, null, viewName, indexName, + PTable.TaskStatus.CREATED.toString(), data, null, null, true); + + // Run IndexRebuildTask + TaskRegionObserver.IndexRebuildTask task = + new TaskRegionObserver.IndexRebuildTask( + TaskRegionEnvironment, QueryServicesOptions.DEFAULT_TASK_HANDLING_MAX_INTERVAL_MS); + + task.run(); + + String viewIndexTableName = "_IDX_" + baseTable; + ConnectionQueryServices queryServices = conn.unwrap(PhoenixConnection.class).getQueryServices(); + int count = getUtility().countRows(queryServices.getTable(Bytes.toBytes(viewIndexTableName))); + assertTrue(count == 1); + + + // Remove index contents and try again + Admin admin = queryServices.getAdmin(); + TableName tableName = TableName.valueOf(viewIndexTableName); + admin.disableTable(tableName); + admin.truncateTable(tableName, false); + + data = "{GusWorkId:abc}"; Review comment: nit: consider using a constant ---------------------------------------------------------------- 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