Return-Path: X-Original-To: apmail-phoenix-commits-archive@minotaur.apache.org Delivered-To: apmail-phoenix-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B7FED17B77 for ; Tue, 14 Oct 2014 08:24:20 +0000 (UTC) Received: (qmail 34832 invoked by uid 500); 14 Oct 2014 08:24:20 -0000 Delivered-To: apmail-phoenix-commits-archive@phoenix.apache.org Received: (qmail 34753 invoked by uid 500); 14 Oct 2014 08:24:20 -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 34686 invoked by uid 99); 14 Oct 2014 08:24:20 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Oct 2014 08:24:20 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5E3D1915E29; Tue, 14 Oct 2014 08:24:20 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jamestaylor@apache.org To: commits@phoenix.apache.org Date: Tue, 14 Oct 2014 08:24:23 -0000 Message-Id: <1dec311eebd44033b788c8ef10c65f1d@git.apache.org> In-Reply-To: <6f342994cdc8461a8980bb06e7fcec0d@git.apache.org> References: <6f342994cdc8461a8980bb06e7fcec0d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [5/5] git commit: Backport minor fixes from 4.0 Backport minor fixes from 4.0 Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/3587d2bc Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/3587d2bc Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/3587d2bc Branch: refs/heads/3.0 Commit: 3587d2bccc94dc95a1dd3bb99a7f343ba3d72332 Parents: 88121cb Author: James Taylor Authored: Tue Oct 14 01:29:38 2014 -0700 Committer: James Taylor Committed: Tue Oct 14 01:29:38 2014 -0700 ---------------------------------------------------------------------- .../java/org/apache/phoenix/end2end/BaseViewIT.java | 16 ++++++++-------- .../apache/phoenix/end2end/index/ViewIndexIT.java | 14 +++++++++++++- .../org/apache/phoenix/schema/MetaDataClient.java | 12 ++++++++---- .../java/org/apache/phoenix/util/MetaDataUtil.java | 10 +++++++++- 4 files changed, 38 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/3587d2bc/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java index f1135ca..5e1cb9d 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java @@ -39,11 +39,10 @@ import org.junit.experimental.categories.Category; import com.google.common.collect.Maps; -@Category(HBaseManagedTimeTest.class) -public class BaseViewIT extends BaseHBaseManagedTimeIT { +@Category(NeedsOwnMiniClusterTest.class) +public class BaseViewIT extends BaseOwnClusterHBaseManagedTimeIT { @BeforeClass - @Shadower(classBeingShadowed = BaseHBaseManagedTimeIT.class) public static void doSetup() throws Exception { Map props = Maps.newHashMapWithExpectedSize(1); // Don't split intra region so we can more easily know that the n-way parallelization is for the explain plan @@ -132,13 +131,14 @@ public class BaseViewIT extends BaseHBaseManagedTimeIT { conn.createStatement().execute("CREATE INDEX i2 on v(s)"); // new index hasn't been analyzed yet - splits = getAllSplits(conn, "i2"); - assertEquals(saltBuckets == null ? 1 : 3, splits.size()); +// splits = getAllSplits(conn, "i2"); +// assertEquals(saltBuckets == null ? 1 : 3, splits.size()); // analyze table should analyze all view data - //analyzeTable(conn, "t"); - //splits = getAllSplits(conn, "i2"); - //assertEquals(saltBuckets == null ? 6 : 8, splits.size()); + analyzeTable(conn, "t"); + splits = getAllSplits(conn, "i2"); +// assertEquals(saltBuckets == null ? 6 : 8, splits.size()); + assertEquals(saltBuckets == null ? 11 : 13, splits.size()); query = "SELECT k1, k2, s FROM v WHERE s = 'foo'"; rs = conn.createStatement().executeQuery(query); http://git-wip-us.apache.org/repos/asf/phoenix/blob/3587d2bc/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java index 19053d9..2f9f9b6 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java @@ -18,6 +18,7 @@ package org.apache.phoenix.end2end.index; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.sql.Connection; import java.sql.DriverManager; @@ -82,6 +83,17 @@ public class ViewIndexIT extends BaseIndexIT { + PhoenixDatabaseMetaData.SEQUENCE_SCHEMA + "," + PhoenixDatabaseMetaData.SEQUENCE_NAME + " FROM " + PhoenixDatabaseMetaData.SEQUENCE_TABLE_NAME); - assertFalse("View index sequences should be deleted.", rs.next()); + StringBuilder buf = new StringBuilder(); + while (rs.next()) { + String schemaName = rs.getString(1); + String tableName = rs.getString(2); + String fullName = schemaName == null ? "" : schemaName; + if (tableName != null && tableName.length() > 0) { + fullName += "." + tableName; + } + buf.append(fullName); + buf.append(' '); + } + assertTrue("View index sequences should be deleted, but found " + buf.toString(), buf.length() == 0); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/phoenix/blob/3587d2bc/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java index 12b5323..6a852a2 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java @@ -1442,12 +1442,19 @@ public class MetaDataClient { @SuppressWarnings("deprecation") // FIXME: Remove when unintentionally deprecated method is fixed (HBASE-7870). Delete tableDelete = new Delete(key, clientTimeStamp, null); tableMetaData.add(tableDelete); + boolean hasViewIndexTable = false; + boolean dropMetaData = connection.getQueryServices().getProps().getBoolean(DROP_METADATA_ATTRIB, DEFAULT_DROP_METADATA); + if (parentTableName != null) { byte[] linkKey = MetaDataUtil.getParentLinkKey(tenantIdStr, schemaName, parentTableName, tableName); @SuppressWarnings("deprecation") // FIXME: Remove when unintentionally deprecated method is fixed (HBASE-7870). Delete linkDelete = new Delete(linkKey, clientTimeStamp, null); tableMetaData.add(linkDelete); + } else if (tableType == PTableType.TABLE && dropMetaData) { + // Check before dropping the HBase view index table in the dropTable call or we'll always get false for this + hasViewIndexTable = MetaDataUtil.hasViewIndexTable(connection, schemaName, tableName); } + MetaDataMutationResult result = connection.getQueryServices().dropTable(tableMetaData, tableType, cascade); MutationCode code = result.getMutationCode(); @@ -1465,9 +1472,6 @@ public class MetaDataClient { default: connection.removeTable(tenantId, SchemaUtil.getTableName(schemaName, tableName), parentTableName, result.getMutationTime()); - // TODO: we need to drop the index data when a view is dropped - boolean dropMetaData = connection.getQueryServices().getProps().getBoolean(DROP_METADATA_ATTRIB, DEFAULT_DROP_METADATA); - if (result.getTable() != null && tableType != PTableType.VIEW) { connection.setAutoCommit(true); PTable table = result.getTable(); @@ -1476,7 +1480,7 @@ public class MetaDataClient { // PName name, PTableType type, long timeStamp, long sequenceNumber, List columns List tableRefs = Lists.newArrayListWithExpectedSize(2 + table.getIndexes().size()); // All multi-tenant tables have a view index table, so no need to check in that case - if (tableType == PTableType.TABLE && (table.isMultiTenant() || MetaDataUtil.hasViewIndexTable(connection, table.getPhysicalName()))) { + if (tableType == PTableType.TABLE && (table.isMultiTenant() || hasViewIndexTable)) { MetaDataUtil.deleteViewIndexSequences(connection, table.getPhysicalName()); // TODO: consider removing this, as the DROP INDEX done for each DROP VIEW command // would have deleted all the rows already http://git-wip-us.apache.org/repos/asf/phoenix/blob/3587d2bc/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java index 4ab3c01..dfeeddb 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java @@ -278,7 +278,15 @@ public class MetaDataUtil { } public static boolean hasViewIndexTable(PhoenixConnection connection, PName name) throws SQLException { - byte[] physicalIndexName = MetaDataUtil.getViewIndexPhysicalName(name.getBytes()); + return hasViewIndexTable(connection, name.getBytes()); + } + + public static boolean hasViewIndexTable(PhoenixConnection connection, String schemaName, String tableName) throws SQLException { + return hasViewIndexTable(connection, SchemaUtil.getTableNameAsBytes(schemaName, tableName)); + } + + public static boolean hasViewIndexTable(PhoenixConnection connection, byte[] physicalTableName) throws SQLException { + byte[] physicalIndexName = MetaDataUtil.getViewIndexPhysicalName(physicalTableName); try { HTableDescriptor desc = connection.getQueryServices().getTableDescriptor(physicalIndexName); return desc != null && Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(desc.getValue(IS_VIEW_INDEX_TABLE_PROP_BYTES)));