Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3A105200D48 for ; Wed, 15 Nov 2017 04:06:07 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 3874F160C07; Wed, 15 Nov 2017 03:06:07 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 557F8160BF4 for ; Wed, 15 Nov 2017 04:06:06 +0100 (CET) Received: (qmail 51748 invoked by uid 500); 15 Nov 2017 03:06:05 -0000 Mailing-List: contact commits-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 commits@phoenix.apache.org Received: (qmail 51736 invoked by uid 99); 15 Nov 2017 03:06:05 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Nov 2017 03:06:05 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 309B0DFBEC; Wed, 15 Nov 2017 03:06:05 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tdsilva@apache.org To: commits@phoenix.apache.org Message-Id: <9e2130f1b7d043cca94f921df91ef522@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: phoenix git commit: PHOENIX-4379 Upgrade code to create CHILD links should only create the links for views and not for indexes Date: Wed, 15 Nov 2017 03:06:05 +0000 (UTC) archived-at: Wed, 15 Nov 2017 03:06:07 -0000 Repository: phoenix Updated Branches: refs/heads/4.13-HBase-1.3 f2deac3e1 -> fab91472d PHOENIX-4379 Upgrade code to create CHILD links should only create the links for views and not for indexes Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/fab91472 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/fab91472 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/fab91472 Branch: refs/heads/4.13-HBase-1.3 Commit: fab91472d340fd052af95876126d73e2897b3b2f Parents: f2deac3 Author: Thomas D'Silva Authored: Tue Nov 14 15:28:01 2017 -0800 Committer: Thomas D'Silva Committed: Tue Nov 14 19:04:39 2017 -0800 ---------------------------------------------------------------------- .../org/apache/phoenix/end2end/UpgradeIT.java | 73 ++++++++++++++++++++ .../org/apache/phoenix/util/UpgradeUtil.java | 1 + 2 files changed, 74 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/fab91472/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java index 4cb4642..b71dd7c 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java @@ -39,12 +39,14 @@ import java.sql.SQLException; import java.util.Arrays; import java.util.Collections; import java.util.Properties; +import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.FutureTask; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.curator.shaded.com.google.common.collect.Sets; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.client.HTableInterface; @@ -67,6 +69,7 @@ import org.apache.phoenix.schema.PMetaData; import org.apache.phoenix.schema.PName; import org.apache.phoenix.schema.PNameFactory; import org.apache.phoenix.schema.PTable; +import org.apache.phoenix.schema.PTable.LinkType; import org.apache.phoenix.schema.PTableType; import org.apache.phoenix.util.MetaDataUtil; import org.apache.phoenix.util.PhoenixRuntime; @@ -838,4 +841,74 @@ public class UpgradeIT extends ParallelStatsDisabledIT { return DriverManager.getConnection(getUrl()); } + @Test + public void testAddParentChildLinks() throws Exception { + String schema = "S_" + generateUniqueName(); + String table1 = "T_" + generateUniqueName(); + String table2 = "T_" + generateUniqueName(); + String tableName = SchemaUtil.getTableName(schema, table1); + String multiTenantTableName = SchemaUtil.getTableName(schema, table2); + String viewName1 = "VIEW_" + generateUniqueName(); + String viewIndexName1 = "VIDX_" + generateUniqueName(); + String viewName2 = "VIEW_" + generateUniqueName(); + String viewIndexName2 = "VIDX_" + generateUniqueName(); + try (Connection conn = getConnection(false, null); + Connection tenantConn = getConnection(true, "tenant1"); + Connection metaConn = getConnection(false, null)) { + // create a non multi-tenant and multi-tenant table + conn.createStatement() + .execute("CREATE TABLE IF NOT EXISTS " + tableName + " (" + + " TENANT_ID CHAR(15) NOT NULL, " + " PK1 integer NOT NULL, " + + "PK2 bigint NOT NULL, " + "V1 VARCHAR, " + "V2 VARCHAR " + + " CONSTRAINT NAME_PK PRIMARY KEY (TENANT_ID, PK1, PK2))"); + conn.createStatement() + .execute("CREATE TABLE IF NOT EXISTS " + multiTenantTableName + " (" + + " TENANT_ID CHAR(15) NOT NULL, " + " PK1 integer NOT NULL, " + + "PK2 bigint NOT NULL, " + "V1 VARCHAR, " + "V2 VARCHAR " + + " CONSTRAINT NAME_PK PRIMARY KEY (TENANT_ID, PK1, PK2)" + + " ) MULTI_TENANT= true"); + // create tenant and global view + conn.createStatement().execute( + "CREATE VIEW " + viewName1 + " (col VARCHAR) AS SELECT * FROM " + tableName); + tenantConn.createStatement().execute("CREATE VIEW " + viewName2 + + "(col VARCHAR) AS SELECT * FROM " + multiTenantTableName); + // create index on the above views + conn.createStatement() + .execute("create index " + viewIndexName1 + " on " + viewName1 + "(col)"); + tenantConn.createStatement() + .execute("create index " + viewIndexName2 + " on " + viewName2 + "(col)"); + + // query all parent -> child links + Set expectedChildLinkSet = getChildLinks(conn); + + // delete all the child links + conn.createStatement().execute("DELETE FROM SYSTEM.CATALOG WHERE LINK_TYPE = " + + LinkType.CHILD_TABLE.getSerializedValue()); + + // re-create them by running the upgrade code + PhoenixConnection phxMetaConn = metaConn.unwrap(PhoenixConnection.class); + phxMetaConn.setRunningUpgrade(true); + UpgradeUtil.addParentToChildLinks(phxMetaConn); + Set actualChildLinkSet = getChildLinks(conn); + + assertEquals("Unexpected child links", expectedChildLinkSet, actualChildLinkSet); + } + } + + private Set getChildLinks(Connection conn) throws SQLException { + ResultSet rs = + conn.createStatement().executeQuery( + "SELECT TENANT_ID, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, COLUMN_FAMILY FROM SYSTEM.CATALOG WHERE LINK_TYPE = " + + LinkType.CHILD_TABLE.getSerializedValue()); + Set childLinkSet = Sets.newHashSet(); + while (rs.next()) { + String key = + rs.getString("TENANT_ID") + " " + rs.getString("TABLE_SCHEM") + " " + + rs.getString("TABLE_NAME") + " " + rs.getString("COLUMN_NAME") + " " + + rs.getString("COLUMN_FAMILY"); + childLinkSet.add(key); + } + return childLinkSet; + } + } http://git-wip-us.apache.org/repos/asf/phoenix/blob/fab91472/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java index f5825b4..4488e86 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java @@ -1110,6 +1110,7 @@ public class UpgradeUtil { " 4 AS LINK_TYPE " + "FROM SYSTEM.CATALOG(PARENT_TENANT_ID VARCHAR)" + "WHERE LINK_TYPE = 2 " + + "AND TABLE_TYPE IS NULL " + "AND (TENANT_ID, TABLE_SCHEM, TABLE_NAME) NOT IN ( " + " SELECT TENANT_ID, " + " TABLE_SCHEM, " +