PHOENIX-3610 Fix tableName used to get the index maintainers while creating HalfStoreFileReader for local index store
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/b2ebe1f6 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/b2ebe1f6 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/b2ebe1f6 Branch: refs/heads/encodecolumns2 Commit: b2ebe1f6210cd8360b0a25411c3b6783d0ed7f06 Parents: 214328a Author: Ankit Singhal <ankitsingha...@gmail.com> Authored: Mon Feb 6 20:02:01 2017 +0530 Committer: Ankit Singhal <ankitsingha...@gmail.com> Committed: Mon Feb 6 20:02:01 2017 +0530 ---------------------------------------------------------------------- .../IndexHalfStoreFileReaderGenerator.java | 14 ++---------- .../java/org/apache/phoenix/util/IndexUtil.java | 24 ++++++++++++++++++++ .../org/apache/phoenix/util/MetaDataUtil.java | 5 +--- 3 files changed, 27 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/b2ebe1f6/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReaderGenerator.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReaderGenerator.java b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReaderGenerator.java index 6f41fe6..6dfe7d7 100644 --- a/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReaderGenerator.java +++ b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReaderGenerator.java @@ -62,14 +62,11 @@ import org.apache.phoenix.schema.PTableType; import org.apache.phoenix.util.ByteUtil; import org.apache.phoenix.util.IndexUtil; import org.apache.phoenix.util.MetaDataUtil; -import org.apache.phoenix.util.PhoenixRuntime; import org.apache.phoenix.util.QueryUtil; import org.apache.phoenix.util.RepairUtil; import com.google.common.collect.Lists; -import jline.internal.Log; - public class IndexHalfStoreFileReaderGenerator extends BaseRegionObserver { @Override @@ -148,7 +145,7 @@ public class IndexHalfStoreFileReaderGenerator extends BaseRegionObserver { try { conn = QueryUtil.getConnectionOnServer(ctx.getEnvironment().getConfiguration()).unwrap( PhoenixConnection.class); - PTable dataTable = PhoenixRuntime.getTableNoCache(conn, tableName.getNameAsString()); + PTable dataTable = IndexUtil.getPDataTable(conn, ctx.getEnvironment().getRegion().getTableDesc()); List<PTable> indexes = dataTable.getIndexes(); Map<ImmutableBytesWritable, IndexMaintainer> indexMaintainers = new HashMap<ImmutableBytesWritable, IndexMaintainer>(); @@ -271,14 +268,7 @@ public class IndexHalfStoreFileReaderGenerator extends BaseRegionObserver { try { PhoenixConnection conn = QueryUtil.getConnection(env.getConfiguration()) .unwrap(PhoenixConnection.class); - String dataTableName = MetaDataUtil.getPhoenixTableNameFromDesc(env.getRegion().getTableDesc()); - if (dataTableName == null) { - Log.warn("Found corrupted local index for region:" + env.getRegion().getRegionInfo().toString() - + " but data table attribute is not set in tableDescriptor " - + "so automatic repair will not succeed" + ", local index created are may be from old client"); - return null; - } - PTable dataPTable = PhoenixRuntime.getTable(conn, dataTableName); + PTable dataPTable = IndexUtil.getPDataTable(conn, env.getRegion().getTableDesc()); final List<IndexMaintainer> maintainers = Lists .newArrayListWithExpectedSize(dataPTable.getIndexes().size()); for (PTable index : dataPTable.getIndexes()) { http://git-wip-us.apache.org/repos/asf/phoenix/blob/b2ebe1f6/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java index e819ee1..d913abd 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java @@ -22,6 +22,7 @@ import static org.apache.phoenix.query.QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_ import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; +import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; @@ -31,6 +32,7 @@ import java.util.Map; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionLocation; +import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Delete; @@ -739,4 +741,26 @@ public class IndexUtil { public static boolean isLocalIndexStore(Store store) { return store.getFamily().getNameAsString().startsWith(QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX); } + + public static PTable getPDataTable(Connection conn, HTableDescriptor tableDesc) throws SQLException { + String dataTableName = Bytes.toString(tableDesc.getValue(MetaDataUtil.DATA_TABLE_NAME_PROP_BYTES)); + String physicalTableName = tableDesc.getTableName().getNameAsString(); + PTable pDataTable = null; + if (dataTableName == null) { + if (physicalTableName.contains(QueryConstants.NAMESPACE_SEPARATOR)) { + try { + pDataTable = PhoenixRuntime.getTable(conn, physicalTableName + .replace(QueryConstants.NAMESPACE_SEPARATOR, QueryConstants.NAME_SEPARATOR)); + } catch (TableNotFoundException e) { + // could be a table mapped to external table + pDataTable = PhoenixRuntime.getTable(conn, physicalTableName); + } + }else{ + pDataTable = PhoenixRuntime.getTable(conn, physicalTableName); + } + } else { + pDataTable = PhoenixRuntime.getTable(conn, dataTableName); + } + return pDataTable; + } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/b2ebe1f6/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 8a60871..3e10d3b 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 @@ -560,7 +560,7 @@ public class MetaDataUtil { public static final String DATA_TABLE_NAME_PROP_NAME = "DATA_TABLE_NAME"; - private static final byte[] DATA_TABLE_NAME_PROP_BYTES = Bytes.toBytes(DATA_TABLE_NAME_PROP_NAME); + public static final byte[] DATA_TABLE_NAME_PROP_BYTES = Bytes.toBytes(DATA_TABLE_NAME_PROP_NAME); @@ -648,7 +648,4 @@ public class MetaDataUtil { return Bytes.startsWith(cf, QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX_BYTES); } - public static String getPhoenixTableNameFromDesc(HTableDescriptor tableDesc) { - return Bytes.toString(tableDesc.getValue(MetaDataUtil.DATA_TABLE_NAME_PROP_BYTES)); - } }