Add test UpgradeIT.testMoveParentChildLinks()
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/f30994f6 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/f30994f6 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/f30994f6 Branch: refs/heads/system-catalog Commit: f30994f60f61c00135136b3aabaabc1193ea2cdf Parents: 41f8142 Author: Thomas D'Silva <tdsi...@apache.org> Authored: Mon Apr 23 16:31:41 2018 -0700 Committer: Thomas D'Silva <tdsi...@apache.org> Committed: Mon Apr 23 16:31:41 2018 -0700 ---------------------------------------------------------------------- .../java/org/apache/phoenix/end2end/UpgradeIT.java | 12 ++++++------ .../phoenix/query/ConnectionQueryServicesImpl.java | 16 ++++++++-------- .../java/org/apache/phoenix/util/UpgradeUtil.java | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/f30994f6/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 ac0cbd3..eb362fb 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 @@ -20,7 +20,6 @@ package org.apache.phoenix.end2end; import static com.google.common.base.Preconditions.checkNotNull; import static org.apache.phoenix.query.ConnectionQueryServicesImpl.UPGRADE_MUTEX; import static org.apache.phoenix.query.ConnectionQueryServicesImpl.UPGRADE_MUTEX_UNLOCKED; -import static org.apache.phoenix.util.UpgradeUtil.SELECT_BASE_COLUMN_COUNT_FROM_HEADER_ROW; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; @@ -42,11 +41,9 @@ 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; import org.apache.hadoop.hbase.client.Put; -import org.apache.hadoop.hbase.client.RowMutations; import org.apache.hadoop.hbase.snapshot.SnapshotCreationException; import org.apache.hadoop.hbase.util.Bytes; import org.apache.phoenix.coprocessor.MetaDataProtocol; @@ -549,7 +546,7 @@ public class UpgradeIT extends ParallelStatsDisabledIT { } @Test - public void testAddParentChildLinks() throws Exception { + public void testMoveParentChildLinks() throws Exception { String schema = "S_" + generateUniqueName(); String table1 = "T_" + generateUniqueName(); String table2 = "T_" + generateUniqueName(); @@ -589,13 +586,16 @@ public class UpgradeIT extends ParallelStatsDisabledIT { Set<String> expectedChildLinkSet = getChildLinks(conn); // delete all the child links - conn.createStatement().execute("DELETE FROM SYSTEM.CATALOG WHERE LINK_TYPE = " + conn.createStatement().execute("DELETE FROM SYSTEM.CHILD_LINK WHERE LINK_TYPE = " + LinkType.CHILD_TABLE.getSerializedValue()); // re-create them by running the upgrade code PhoenixConnection phxMetaConn = metaConn.unwrap(PhoenixConnection.class); phxMetaConn.setRunningUpgrade(true); + // create the parent-> child links in SYSTEM.CATALOG UpgradeUtil.addParentToChildLinks(phxMetaConn); + // move the parent->child links to SYSTEM.CHILD_LINK + UpgradeUtil.moveChildLinks(phxMetaConn); Set<String> actualChildLinkSet = getChildLinks(conn); assertEquals("Unexpected child links", expectedChildLinkSet, actualChildLinkSet); @@ -605,7 +605,7 @@ public class UpgradeIT extends ParallelStatsDisabledIT { 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 = " + "SELECT TENANT_ID, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, COLUMN_FAMILY FROM SYSTEM.CHILD_LINK WHERE LINK_TYPE = " + LinkType.CHILD_TABLE.getSerializedValue()); Set<String> childLinkSet = Sets.newHashSet(); while (rs.next()) { http://git-wip-us.apache.org/repos/asf/phoenix/blob/f30994f6/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java index 00e1d62..8bd06bc 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java @@ -57,7 +57,11 @@ import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_RENEW_LEASE_ import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_RENEW_LEASE_THREAD_POOL_SIZE; import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_RENEW_LEASE_THRESHOLD_MILLISECONDS; import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_RUN_RENEW_LEASE_FREQUENCY_INTERVAL_MILLISECONDS; -import static org.apache.phoenix.util.UpgradeUtil.*; +import static org.apache.phoenix.util.UpgradeUtil.addParentToChildLinks; +import static org.apache.phoenix.util.UpgradeUtil.addViewIndexToParentLinks; +import static org.apache.phoenix.util.UpgradeUtil.getSysCatalogSnapshotName; +import static org.apache.phoenix.util.UpgradeUtil.moveChildLinks; +import static org.apache.phoenix.util.UpgradeUtil.upgradeTo4_5_0; import java.io.IOException; import java.lang.ref.WeakReference; @@ -2865,14 +2869,10 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement + PBoolean.INSTANCE.getSqlTypeName()); addParentToChildLinks(metaConnection); } - if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_13_0) { - metaConnection = addColumnsIfNotExists( - metaConnection, - PhoenixDatabaseMetaData.SYSTEM_CATALOG, - MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_11_0, - PhoenixDatabaseMetaData.USE_STATS_FOR_PARALLELIZATION + " " - + PBoolean.INSTANCE.getSqlTypeName()); + // TODO set the version for which the following upgrade code runs correct + if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_14_0) { addViewIndexToParentLinks(metaConnection); + moveChildLinks(metaConnection); } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/f30994f6/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 fe6470b..e1c82b2 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 @@ -1159,8 +1159,8 @@ public class UpgradeUtil { metaConnection = new PhoenixConnection(oldMetaConnection, HConstants.LATEST_TIMESTAMP); logger.info("Upgrading metadata to add parent to child links for views"); metaConnection.commit(); - String createChildLink = "UPSERT INTO SYSTEM.CHILD_LINK(TENANT_ID, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, COLUMN_FAMILY, LINK_TYPE)" + - "SELECT TENANT_ID, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, COLUMN_FAMILY, LINK_TYPE" + + String createChildLink = "UPSERT INTO SYSTEM.CHILD_LINK(TENANT_ID, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, COLUMN_FAMILY, LINK_TYPE) " + + "SELECT TENANT_ID, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, COLUMN_FAMILY, LINK_TYPE " + "FROM SYSTEM.CATALOG " + "WHERE LINK_TYPE = 4"; metaConnection.createStatement().execute(createChildLink);