You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by td...@apache.org on 2017/11/15 03:04:54 UTC
phoenix git commit: PHOENIX-4379 Upgrade code to create CHILD links
should only create the links for views and not for indexes
Repository: phoenix
Updated Branches:
refs/heads/4.13-HBase-0.98 fbfe82250 -> c455886c3
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/c455886c
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/c455886c
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/c455886c
Branch: refs/heads/4.13-HBase-0.98
Commit: c455886c340a7bda32ff173b645630ead242e955
Parents: fbfe822
Author: Thomas D'Silva <td...@apache.org>
Authored: Tue Nov 14 15:28:01 2017 -0800
Committer: Thomas D'Silva <td...@apache.org>
Committed: Tue Nov 14 19:04:24 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/c455886c/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<String> 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<String> actualChildLinkSet = getChildLinks(conn);
+
+ assertEquals("Unexpected child links", expectedChildLinkSet, actualChildLinkSet);
+ }
+ }
+
+ private Set<String> 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<String> 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/c455886c/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 45c81f6..a25c071 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, " +