hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From syuanji...@apache.org
Subject [05/13] hbase git commit: HBASE-15173 Execute mergeRegions RPC call as the request user
Date Fri, 29 Jan 2016 17:13:58 GMT
HBASE-15173 Execute mergeRegions RPC call as the request user


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

Branch: refs/heads/hbase-12439
Commit: 1ee07688c8e75bf8507c1613feec9c56e950ab4c
Parents: 37ed0f6
Author: tedyu <yuzhihong@gmail.com>
Authored: Thu Jan 28 09:53:24 2016 -0800
Committer: tedyu <yuzhihong@gmail.com>
Committed: Thu Jan 28 09:53:24 2016 -0800

----------------------------------------------------------------------
 .../hadoop/hbase/protobuf/ProtobufUtil.java     | 32 ++++++++++++++++----
 .../org/apache/hadoop/hbase/master/HMaster.java |  5 +--
 .../hadoop/hbase/master/MasterRpcServices.java  |  3 +-
 .../hadoop/hbase/master/MasterServices.java     |  6 ++--
 .../hadoop/hbase/master/ServerManager.java      |  5 +--
 .../handler/DispatchMergingRegionHandler.java   |  7 +++--
 .../apache/hadoop/hbase/client/TestAdmin1.java  |  3 +-
 .../hadoop/hbase/master/TestCatalogJanitor.java |  3 +-
 8 files changed, 47 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/1ee07688/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
index f5e4305..7cd0d91 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
@@ -23,12 +23,14 @@ import static org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpeci
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InterruptedIOException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.nio.ByteBuffer;
+import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -137,6 +139,7 @@ import org.apache.hadoop.hbase.quotas.QuotaType;
 import org.apache.hadoop.hbase.quotas.ThrottleType;
 import org.apache.hadoop.hbase.replication.ReplicationLoadSink;
 import org.apache.hadoop.hbase.replication.ReplicationLoadSource;
+import org.apache.hadoop.hbase.security.User;
 import org.apache.hadoop.hbase.security.access.Permission;
 import org.apache.hadoop.hbase.security.access.TablePermission;
 import org.apache.hadoop.hbase.security.access.UserPermission;
@@ -1846,17 +1849,34 @@ public final class ProtobufUtil {
    * @param region_b
    * @param forcible true if do a compulsory merge, otherwise we will only merge
    *          two adjacent regions
+   * @param user effective user
    * @throws IOException
    */
   public static void mergeRegions(final AdminService.BlockingInterface admin,
       final HRegionInfo region_a, final HRegionInfo region_b,
-      final boolean forcible) throws IOException {
-    MergeRegionsRequest request = RequestConverter.buildMergeRegionsRequest(
+      final boolean forcible, final User user) throws IOException {
+    final MergeRegionsRequest request = RequestConverter.buildMergeRegionsRequest(
         region_a.getRegionName(), region_b.getRegionName(),forcible);
-    try {
-      admin.mergeRegions(null, request);
-    } catch (ServiceException se) {
-      throw ProtobufUtil.getRemoteException(se);
+    if (user != null) {
+      try {
+        user.getUGI().doAs(new PrivilegedExceptionAction<Void>() {
+          @Override
+          public Void run() throws Exception {
+            admin.mergeRegions(null, request);
+            return null;
+          }
+        });
+      } catch (InterruptedException ie) {
+        InterruptedIOException iioe = new InterruptedIOException();
+        iioe.initCause(ie);
+        throw iioe;
+      }
+    } else {
+      try {
+        admin.mergeRegions(null, request);
+      } catch (ServiceException se) {
+        throw ProtobufUtil.getRemoteException(se);
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/1ee07688/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
index 43f8efa..3cf750e 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
@@ -134,6 +134,7 @@ import org.apache.hadoop.hbase.regionserver.RegionSplitPolicy;
 import org.apache.hadoop.hbase.regionserver.compactions.ExploringCompactionPolicy;
 import org.apache.hadoop.hbase.regionserver.compactions.FIFOCompactionPolicy;
 import org.apache.hadoop.hbase.replication.regionserver.Replication;
+import org.apache.hadoop.hbase.security.User;
 import org.apache.hadoop.hbase.security.UserProvider;
 import org.apache.hadoop.hbase.util.Addressing;
 import org.apache.hadoop.hbase.util.Bytes;
@@ -1375,10 +1376,10 @@ public class HMaster extends HRegionServer implements MasterServices
{
 
   @Override
   public void dispatchMergingRegions(final HRegionInfo region_a,
-      final HRegionInfo region_b, final boolean forcible) throws IOException {
+      final HRegionInfo region_b, final boolean forcible, final User user) throws IOException
{
     checkInitialized();
     this.service.submit(new DispatchMergingRegionHandler(this,
-      this.catalogJanitorChore, region_a, region_b, forcible));
+      this.catalogJanitorChore, region_a, region_b, forcible, user));
   }
 
   void move(final byte[] encodedRegionName,

http://git-wip-us.apache.org/repos/asf/hbase/blob/1ee07688/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java
index e08463f..1dd4c14 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java
@@ -47,6 +47,7 @@ import org.apache.hadoop.hbase.exceptions.MergeRegionException;
 import org.apache.hadoop.hbase.exceptions.UnknownProtocolException;
 import org.apache.hadoop.hbase.ipc.PriorityFunction;
 import org.apache.hadoop.hbase.ipc.QosPriority;
+import org.apache.hadoop.hbase.ipc.RpcServer;
 import org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface;
 import org.apache.hadoop.hbase.ipc.ServerRpcController;
 import org.apache.hadoop.hbase.mob.MobUtils;
@@ -539,7 +540,7 @@ public class MasterRpcServices extends RSRpcServices
     }
 
     try {
-      master.dispatchMergingRegions(regionInfoA, regionInfoB, forcible);
+      master.dispatchMergingRegions(regionInfoA, regionInfoB, forcible, RpcServer.getRequestUser());
       master.cpHost.postDispatchMerge(regionInfoA, regionInfoB);
     } catch (IOException ioe) {
       throw new ServiceException(ioe);

http://git-wip-us.apache.org/repos/asf/hbase/blob/1ee07688/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java
index ec7db0c..59c7a88 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java
@@ -36,6 +36,7 @@ import org.apache.hadoop.hbase.master.normalizer.RegionNormalizer;
 import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
 import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
 import org.apache.hadoop.hbase.quotas.MasterQuotaManager;
+import org.apache.hadoop.hbase.security.User;
 
 import com.google.protobuf.Service;
 
@@ -267,10 +268,11 @@ public interface MasterServices extends Server {
    * @param region_b region to merge
    * @param forcible true if do a compulsory merge, otherwise we will only merge
    *          two adjacent regions
+   * @param user effective user
    * @throws IOException
    */
   void dispatchMergingRegions(
-    final HRegionInfo region_a, final HRegionInfo region_b, final boolean forcible
+    final HRegionInfo region_a, final HRegionInfo region_b, final boolean forcible, final
User user
   ) throws IOException;
 
   /**
@@ -312,7 +314,7 @@ public interface MasterServices extends Server {
   public List<TableName> listTableNamesByNamespace(String name) throws IOException;
 
   /**
-   * @param table
+   * @param table the table for which last successful major compaction time is queried
    * @return the timestamp of the last successful major compaction for the passed table,
    * or 0 if no HFile resulting from a major compaction exists
    * @throws IOException

http://git-wip-us.apache.org/repos/asf/hbase/blob/1ee07688/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
index a95279c..341d51c 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
@@ -66,6 +66,7 @@ import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos.StoreSeque
 import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos.SplitLogTask.RecoveryMode;
 import org.apache.hadoop.hbase.regionserver.HRegionServer;
 import org.apache.hadoop.hbase.regionserver.RegionOpeningState;
+import org.apache.hadoop.hbase.security.User;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.hadoop.hbase.util.RetryCounter;
@@ -876,7 +877,7 @@ public class ServerManager {
    * @throws IOException
    */
   public void sendRegionsMerge(ServerName server, HRegionInfo region_a,
-      HRegionInfo region_b, boolean forcible) throws IOException {
+      HRegionInfo region_b, boolean forcible, User user) throws IOException {
     if (server == null)
       throw new NullPointerException("Passed server is null");
     if (region_a == null || region_b == null)
@@ -889,7 +890,7 @@ public class ServerManager {
           + region_b.getRegionNameAsString()
           + " failed because no RPC connection found to this server");
     }
-    ProtobufUtil.mergeRegions(admin, region_a, region_b, forcible);
+    ProtobufUtil.mergeRegions(admin, region_a, region_b, forcible, user);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hbase/blob/1ee07688/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DispatchMergingRegionHandler.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DispatchMergingRegionHandler.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DispatchMergingRegionHandler.java
index b4db108..872cf3f 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DispatchMergingRegionHandler.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DispatchMergingRegionHandler.java
@@ -37,6 +37,7 @@ import org.apache.hadoop.hbase.master.MasterServices;
 import org.apache.hadoop.hbase.master.RegionPlan;
 import org.apache.hadoop.hbase.master.RegionStates;
 import org.apache.hadoop.hbase.master.ServerManager;
+import org.apache.hadoop.hbase.security.User;
 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
 
 /**
@@ -55,16 +56,18 @@ public class DispatchMergingRegionHandler extends EventHandler {
   private HRegionInfo region_b;
   private final boolean forcible;
   private final int timeout;
+  private final User user;
 
   public DispatchMergingRegionHandler(final MasterServices services,
       final CatalogJanitor catalogJanitor, final HRegionInfo region_a,
-      final HRegionInfo region_b, final boolean forcible) {
+      final HRegionInfo region_b, final boolean forcible, final User user) {
     super(services, EventType.C_M_MERGE_REGION);
     this.masterServices = services;
     this.catalogJanitor = catalogJanitor;
     this.region_a = region_a;
     this.region_b = region_b;
     this.forcible = forcible;
+    this.user = user;
     this.timeout = server.getConfiguration().getInt(
         "hbase.master.regionmerge.timeout", 120 * 1000);
   }
@@ -148,7 +151,7 @@ public class DispatchMergingRegionHandler extends EventHandler {
       while (!masterServices.isStopped()) {
         try {
           masterServices.getServerManager().sendRegionsMerge(region_a_location,
-              region_a, region_b, forcible);
+              region_a, region_b, forcible, user);
           LOG.info("Sent merge to server " + region_a_location + " for region " +
             region_a.getEncodedName() + "," + region_b.getEncodedName() + ", focible=" +
forcible);
           break;

http://git-wip-us.apache.org/repos/asf/hbase/blob/1ee07688/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin1.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin1.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin1.java
index 6730e0a..df8f4f6 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin1.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin1.java
@@ -1254,7 +1254,8 @@ public class TestAdmin1 {
     try {
       AdminService.BlockingInterface admin = TEST_UTIL.getHBaseAdmin().getConnection()
           .getAdmin(regions.get(1).getSecond());
-      ProtobufUtil.mergeRegions(admin, regions.get(1).getFirst(), regions.get(2).getFirst(),
true);
+      ProtobufUtil.mergeRegions(admin, regions.get(1).getFirst(), regions.get(2).getFirst(),
true,
+        null);
     } catch (MergeRegionException mm) {
       gotException = true;
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/1ee07688/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java
index e26bd82..123e8b5 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java
@@ -77,6 +77,7 @@ import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.RegionActionResul
 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ResultOrException;
 import org.apache.hadoop.hbase.quotas.MasterQuotaManager;
 import org.apache.hadoop.hbase.regionserver.HStore;
+import org.apache.hadoop.hbase.security.User;
 import org.apache.hadoop.hbase.testclassification.MasterTests;
 import org.apache.hadoop.hbase.testclassification.SmallTests;
 import org.apache.hadoop.hbase.util.Bytes;
@@ -499,7 +500,7 @@ public class TestCatalogJanitor {
 
     @Override
     public void dispatchMergingRegions(HRegionInfo region_a, HRegionInfo region_b,
-        boolean forcible) throws IOException {
+        boolean forcible, User user) throws IOException {
     }
 
     @Override


Mime
View raw message