You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ma...@apache.org on 2015/03/04 23:41:07 UTC

[32/50] [abbrv] phoenix git commit: PHOENIX-1634 LocalIndexSplitter prevents region from auto split(Rajeshbabu)

PHOENIX-1634 LocalIndexSplitter prevents region from auto split(Rajeshbabu)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/e09a8f8d
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/e09a8f8d
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/e09a8f8d

Branch: refs/heads/calcite
Commit: e09a8f8de715ec17fbdedb28b9b4153b5886d85e
Parents: d4f7b71
Author: Rajeshbabu Chintaguntla <ra...@apache.org>
Authored: Mon Feb 16 23:22:57 2015 +0530
Committer: Rajeshbabu Chintaguntla <ra...@apache.org>
Committed: Mon Feb 16 23:22:57 2015 +0530

----------------------------------------------------------------------
 .../phoenix/coprocessor/MetaDataProtocol.java   |  5 ++-
 .../hbase/index/master/IndexMasterObserver.java | 47 ++++++++++++++++++++
 .../query/ConnectionQueryServicesImpl.java      | 33 +++++++++++---
 3 files changed, 78 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/e09a8f8d/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java
index be5fb4d..cf0aabb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java
@@ -60,8 +60,8 @@ public abstract class MetaDataProtocol extends MetaDataService {
 
     public static final long MIN_TABLE_TIMESTAMP = 0;
 
-    // Incremented from 5 to 6 with the addition of the STORE_NULLS table option in 4.3
-    public static final long MIN_SYSTEM_TABLE_TIMESTAMP = MIN_TABLE_TIMESTAMP + 6;
+    // Incremented from 5 to 7 with the addition of the STORE_NULLS table option in 4.3
+    public static final long MIN_SYSTEM_TABLE_TIMESTAMP = MIN_TABLE_TIMESTAMP + 7;
     public static final int DEFAULT_MAX_META_DATA_VERSIONS = 1000;
     public static final int DEFAULT_MAX_STAT_DATA_VERSIONS = 3;
     public static final boolean DEFAULT_META_DATA_KEEP_DELETED_CELLS = true;
@@ -70,6 +70,7 @@ public abstract class MetaDataProtocol extends MetaDataService {
     public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0 = MIN_TABLE_TIMESTAMP + 3;
     public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_2_0 = MIN_TABLE_TIMESTAMP + 4;
     public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_2_1 = MIN_TABLE_TIMESTAMP + 5;
+    public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_3_0 = MIN_TABLE_TIMESTAMP + 7;
     
     // TODO: pare this down to minimum, as we don't need duplicates for both table and column errors, nor should we need
     // a different code for every type of error.

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e09a8f8d/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/master/IndexMasterObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/master/IndexMasterObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/master/IndexMasterObserver.java
index dfb2c62..1da5aff 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/master/IndexMasterObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/master/IndexMasterObserver.java
@@ -18,15 +18,22 @@
 package org.apache.phoenix.hbase.index.master;
 
 import java.io.IOException;
+import java.util.List;
 
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.coprocessor.BaseMasterObserver;
 import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment;
 import org.apache.hadoop.hbase.coprocessor.ObserverContext;
+import org.apache.hadoop.hbase.master.AssignmentManager;
 import org.apache.hadoop.hbase.master.LoadBalancer;
+import org.apache.hadoop.hbase.master.RegionPlan;
+import org.apache.hadoop.hbase.master.RegionStates;
+import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.hbase.index.balancer.IndexLoadBalancer;
+import org.apache.phoenix.util.MetaDataUtil;
 
 /**
  * Defines of coprocessor hooks(to support secondary indexing) of operations on
@@ -60,6 +67,46 @@ public class IndexMasterObserver extends BaseMasterObserver {
     }
 
     @Override
+    public void preModifyTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,
+            TableName tableName, HTableDescriptor htd) throws IOException {
+        HTableDescriptor oldDesc =
+                ctx.getEnvironment().getMasterServices().getTableDescriptors().get(tableName);
+        if (oldDesc.getValue(IndexLoadBalancer.PARENT_TABLE_KEY) == null
+                && htd.getValue(IndexLoadBalancer.PARENT_TABLE_KEY) != null) {
+            TableName userTableName =
+                    TableName.valueOf(htd.getValue(IndexLoadBalancer.PARENT_TABLE_KEY));
+            balancer.addTablesToColocate(userTableName, htd.getTableName());
+        }
+        super.preModifyTableHandler(ctx, tableName, htd);
+    }
+
+    @Override
+    public void postMove(ObserverContext<MasterCoprocessorEnvironment> ctx, HRegionInfo region,
+            ServerName srcServer, ServerName destServer) throws IOException {
+        if (balancer != null && balancer.isTableColocated(region.getTable())) {
+            AssignmentManager am = ctx.getEnvironment().getMasterServices().getAssignmentManager();
+            RegionStates regionStates = am.getRegionStates();
+            String tableName = region.getTable().getNameAsString();
+            String correspondingTable =
+                    region.getTable().getNameAsString()
+                            .startsWith(MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX) ? MetaDataUtil
+                            .getUserTableName(tableName) : MetaDataUtil
+                            .getLocalIndexTableName(tableName);
+            List<HRegionInfo> regions =
+                    regionStates.getRegionsOfTable(TableName.valueOf(correspondingTable));
+            for (HRegionInfo hri : regions) {
+                if (Bytes.compareTo(region.getStartKey(), hri.getStartKey()) == 0
+                        && destServer != null) {
+                    balancer.regionOnline(hri, destServer);
+                    am.addPlan(hri.getEncodedName(), new RegionPlan(hri, null, destServer));
+                    am.unassign(hri);
+                }
+            }
+        }
+        super.postMove(ctx, region, srcServer, destServer);
+    }
+
+    @Override
     public void postDeleteTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,
             TableName tableName) throws IOException {
         if (balancer != null && balancer.isTableColocated(tableName)) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e09a8f8d/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 2b508b5..b149b92 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
@@ -1197,10 +1197,10 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         if (tableType == PTableType.INDEX) { // Index on view
             // Physical index table created up front for multi tenant
             // TODO: if viewIndexId is Short.MIN_VALUE, then we don't need to attempt to create it
-            if (physicalTableName != null && !MetaDataUtil.isMultiTenant(m, kvBuilder, ptr)) {
+            if (physicalTableName != null) {
                 if (localIndexTable) {
                     ensureLocalIndexTableCreated(tableName, tableProps, families, splits, MetaDataUtil.getClientTimeStamp(m));
-                } else {
+                } else if (!MetaDataUtil.isMultiTenant(m, kvBuilder, ptr)) {
                     ensureViewIndexTableCreated(tenantIdBytes.length == 0 ? null : PNameFactory.newName(tenantIdBytes), physicalTableName, MetaDataUtil.getClientTimeStamp(m));
                 }
             }
@@ -1224,7 +1224,6 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                 familiesPlusDefault.add(new Pair<byte[],Map<String,Object>>(defaultCF,Collections.<String,Object>emptyMap()));
             }
             ensureViewIndexTableCreated(tableName, tableProps, familiesPlusDefault, MetaDataUtil.isSalted(m, kvBuilder, ptr) ? splits : null, MetaDataUtil.getClientTimeStamp(m));
-            ensureLocalIndexTableCreated(MetaDataUtil.getLocalIndexPhysicalName(tableName), tableProps, familiesPlusDefault, splits);
         }
 
         byte[] tableKey = SchemaUtil.getTableKey(tenantIdBytes, schemaBytes, tableBytes);
@@ -1848,8 +1847,32 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                                 // any new columns we've added.
                                 long currentServerSideTableTimeStamp = e.getTable().getTimeStamp();
 
-                                // We know that we always need to add the STORE_NULLS column for 4.3 release
-                                String columnsToAdd = PhoenixDatabaseMetaData.STORE_NULLS + " " + PBoolean.INSTANCE.getSqlTypeName();
+                                String columnsToAdd = "";
+                                if(currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_3_0) {
+                                    // We know that we always need to add the STORE_NULLS column for 4.3 release
+                                    columnsToAdd = PhoenixDatabaseMetaData.STORE_NULLS + " " + PBoolean.INSTANCE.getSqlTypeName();
+                                    HBaseAdmin admin = null;
+                                    try {
+                                        admin = getAdmin();
+                                        HTableDescriptor[] localIndexTables = admin.listTables(MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX+".*");
+                                        for (HTableDescriptor table : localIndexTables) {
+                                            if (table.getValue(MetaDataUtil.PARENT_TABLE_KEY) == null
+                                                    && table.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_NAME) != null) {
+                                                table.setValue(MetaDataUtil.PARENT_TABLE_KEY,
+                                                    MetaDataUtil.getUserTableName(table
+                                                        .getNameAsString()));
+                                                // Explicitly disable, modify and enable the table to ensure co-location of data
+                                                // and index regions. If we just modify the table descriptor when online schema
+                                                // change enabled may reopen the region in same region server instead of following data region.
+                                                admin.disableTable(table.getTableName());
+                                                admin.modifyTable(table.getTableName(), table);
+                                                admin.enableTable(table.getTableName());
+                                            }
+                                        }
+                                    } finally {
+                                        if (admin != null) admin.close();
+                                    }
+                                }
 
                                 // If the server side schema is at before MIN_SYSTEM_TABLE_TIMESTAMP_4_1_0 then 
                                 // we need to add INDEX_TYPE and INDEX_DISABLE_TIMESTAMP columns too.