Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 9194a00a9 -> 460f6bffb


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/460f6bff
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/460f6bff
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/460f6bff

Branch: refs/heads/4.x-HBase-1.1
Commit: 460f6bffba0256e2f86725579e5a84606d9598ce
Parents: 9194a00
Author: Ankit Singhal <ankitsingha...@gmail.com>
Authored: Mon Feb 6 20:00:13 2017 +0530
Committer: Ankit Singhal <ankitsingha...@gmail.com>
Committed: Mon Feb 6 20:00:13 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/460f6bff/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 537febd..a8ebe75 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
@@ -61,14 +61,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
@@ -149,7 +146,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>();
@@ -272,14 +269,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/460f6bff/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 54f0453..4a9cb57 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
@@ -23,6 +23,7 @@ import static org.apache.phoenix.util.PhoenixRuntime.getTable;
 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;
@@ -32,6 +33,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;
@@ -738,4 +740,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/460f6bff/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 fe14ba4..2b5e622 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
@@ -559,7 +559,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);
 
 
 
@@ -647,7 +647,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));
-    }
 }

Reply via email to