hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tof...@apache.org
Subject [hbase] 03/09: added root handlder and asyncadmin, etc
Date Wed, 05 Aug 2020 09:49:10 GMT
This is an automated email from the ASF dual-hosted git repository.

toffer pushed a commit to branch HBASE-11288.branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git

commit c23117e7af0eb83a93b2ee9b4cde62b74bb25917
Author: Francis Liu <toffer@apache.org>
AuthorDate: Tue Jul 28 01:26:12 2020 -0700

    added root handlder and asyncadmin, etc
---
 .../hbase/client/AsyncNonRootRegionLocator.java    |  2 +-
 .../hadoop/hbase/client/RawAsyncHBaseAdmin.java    | 38 ++++++++++++++++++--
 .../hadoop/hbase/client/TestClientNoCluster.java   | 12 +++----
 .../hadoop/hbase/master/MasterRpcServices.java     |  4 +--
 .../hadoop/hbase/regionserver/HRegionServer.java   |  5 +++
 .../hadoop/hbase/regionserver/RSRpcServices.java   |  8 +++--
 .../regionserver/handler/AssignRegionHandler.java  |  7 ++--
 .../regionserver/handler/CloseRootHandler.java     | 40 ++++++++++++++++++++++
 .../regionserver/handler/OpenRootHandler.java      | 40 ++++++++++++++++++++++
 .../handler/UnassignRegionHandler.java             |  5 +--
 10 files changed, 143 insertions(+), 18 deletions(-)

diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonRootRegionLocator.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonRootRegionLocator.java
index f082778..082085e 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonRootRegionLocator.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonRootRegionLocator.java
@@ -439,7 +439,7 @@ class AsyncNonRootRegionLocator {
       META_TABLE_NAME.equals(tableName) ? ROOT_TABLE_NAME : META_TABLE_NAME;
     if (LOG.isTraceEnabled()) {
       LOG.trace("Try locate '" + tableName + "', row='" + Bytes.toStringBinary(req.row) +
-        "', locateType=" + req.locateType + " in meta");
+        "', locateType=" + req.locateType + " in "+parentTableName);
     }
     byte[] metaStartKey;
     if (req.locateType.equals(RegionLocateType.BEFORE)) {
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
index 3b0ede9..1091ef6 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
@@ -2357,6 +2357,7 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
       return failedFuture(new IllegalArgumentException("Passed region name can't be null"));
     }
     try {
+      TableName parentTable;
       CompletableFuture<Optional<HRegionLocation>> future;
       if (RegionInfo.isEncodedRegionName(regionNameOrEncodedRegionName)) {
         String encodedName = Bytes.toString(regionNameOrEncodedRegionName);
@@ -2378,12 +2379,15 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
           future = connection.registry.getMetaRegionLocations()
             .thenApply(locs -> Stream.of(locs.getRegionLocations())
               .filter(loc -> loc.getRegion().getEncodedName().equals(encodedName)).findFirst());
+          parentTable = null;
         } else if (encodedName.length() < RegionInfo.MD5_HEX_LENGTH) {
           future = AsyncMetaTableAccessor.getRegionLocationWithEncodedName(rootTable,
             regionNameOrEncodedRegionName);
+          parentTable = ROOT_TABLE_NAME;
         } else {
           future = AsyncMetaTableAccessor.getRegionLocationWithEncodedName(metaTable,
             regionNameOrEncodedRegionName);
+          parentTable = META_TABLE_NAME;
         }
       } else {
         RegionInfo regionInfo =
@@ -2393,16 +2397,20 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
             .thenApply(locs -> Stream.of(locs.getRegionLocations())
               .filter(loc -> loc.getRegion().getReplicaId() == regionInfo.getReplicaId())
               .findFirst());
+          parentTable = null;
           //TODO francis it won't reach here once meta is split
         } else if (regionInfo.isMetaRegion())   {
           future =
             AsyncMetaTableAccessor.getRegionLocation(rootTable, regionNameOrEncodedRegionName);
+          parentTable = ROOT_TABLE_NAME;
         } else {
           future =
             AsyncMetaTableAccessor.getRegionLocation(metaTable, regionNameOrEncodedRegionName);
+          parentTable = META_TABLE_NAME;
         }
       }
 
+      final TableName finalParentTable = parentTable;
       CompletableFuture<HRegionLocation> returnedFuture = new CompletableFuture<>();
       addListener(future, (location, err) -> {
         if (err != null) {
@@ -2410,9 +2418,33 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
           return;
         }
         if (!location.isPresent() || location.get().getRegion() == null) {
-          returnedFuture.completeExceptionally(
-            new UnknownRegionException("Invalid region name or encoded region name: " +
-              Bytes.toStringBinary(regionNameOrEncodedRegionName)));
+          if (META_TABLE_NAME.equals(finalParentTable)) {
+            if (LOG.isDebugEnabled()) {
+              LOG.debug(
+                "Didn't find encoded name in hbase:meta, trying hbase:root for region :"
+
+                  Bytes.toStringBinary(regionNameOrEncodedRegionName));
+            }
+            CompletableFuture<Optional<HRegionLocation>> innerfuture =
+              AsyncMetaTableAccessor.getRegionLocationWithEncodedName(rootTable,
+                regionNameOrEncodedRegionName);
+            addListener(innerfuture, (innerlocation, innererr) -> {
+              if (innererr != null) {
+                returnedFuture.completeExceptionally(innererr);
+                return;
+              }
+              if (!innerlocation.isPresent() || innerlocation.get().getRegion() == null)
{
+                returnedFuture.completeExceptionally(new UnknownRegionException(
+                  "Invalid region name or encoded region name: " +
+                    Bytes.toStringBinary(regionNameOrEncodedRegionName)));
+              } else {
+                returnedFuture.complete(innerlocation.get());
+              }
+            });
+          } else {
+            returnedFuture.completeExceptionally(new UnknownRegionException(
+              "Invalid region name or encoded region name: " +
+                Bytes.toStringBinary(regionNameOrEncodedRegionName)));
+          }
         } else {
           returnedFuture.complete(location.get());
         }
diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java
b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java
index 4150484..aa21636 100644
--- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java
+++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java
@@ -137,7 +137,7 @@ public class TestClientNoCluster extends Configured implements Tool {
     @Override
     public CompletableFuture<RegionLocations> getMetaRegionLocations() {
       return CompletableFuture.completedFuture(new RegionLocations(
-          new HRegionLocation(RegionInfoBuilder.FIRST_META_REGIONINFO, META_HOST)));
+          new HRegionLocation(RegionInfoBuilder.ROOT_REGIONINFO, META_HOST)));
     }
 
     @Override
@@ -157,7 +157,7 @@ public class TestClientNoCluster extends Configured implements Tool {
     // This override mocks up our exists/get call to throw a RegionServerStoppedException.
     localConfig.set("hbase.client.connection.impl", RpcTimeoutConnection.class.getName());
     Connection connection = ConnectionFactory.createConnection(localConfig);
-    Table table = connection.getTable(TableName.META_TABLE_NAME);
+    Table table = connection.getTable(TableName.ROOT_TABLE_NAME);
     Throwable t = null;
     LOG.info("Start");
     try {
@@ -196,7 +196,7 @@ public class TestClientNoCluster extends Configured implements Tool {
     // all ten of them -- and we'll get the RetriesExhaustedException exception.
     localConfig.setInt(HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT, pause - 1);
     Connection connection = ConnectionFactory.createConnection(localConfig);
-    Table table = connection.getTable(TableName.META_TABLE_NAME);
+    Table table = connection.getTable(TableName.ROOT_TABLE_NAME);
     Throwable t = null;
     try {
       // An exists call turns into a get w/ a flag.
@@ -232,7 +232,7 @@ public class TestClientNoCluster extends Configured implements Tool {
     // means we'll have to do a bunch more mocking.  Tests that go against meta only should
be
     // good for a bit of testing.
     Connection connection = ConnectionFactory.createConnection(this.conf);
-    Table table = connection.getTable(TableName.META_TABLE_NAME);
+    Table table = connection.getTable(TableName.ROOT_TABLE_NAME);
     ResultScanner scanner = table.getScanner(HConstants.CATALOG_FAMILY);
     try {
       Result result = null;
@@ -254,7 +254,7 @@ public class TestClientNoCluster extends Configured implements Tool {
     // means we'll have to do a bunch more mocking.  Tests that go against meta only should
be
     // good for a bit of testing.
     Connection connection = ConnectionFactory.createConnection(conf);
-    Table table = connection.getTable(TableName.META_TABLE_NAME);
+    Table table = connection.getTable(TableName.ROOT_TABLE_NAME);
     ResultScanner scanner = table.getScanner(HConstants.CATALOG_FAMILY);
     try {
       Result result = null;
@@ -276,7 +276,7 @@ public class TestClientNoCluster extends Configured implements Tool {
     // means we'll have to do a bunch more mocking. Tests that go against meta only should
be
     // good for a bit of testing.
     Connection connection = ConnectionFactory.createConnection(testConf);
-    Table table = connection.getTable(TableName.META_TABLE_NAME);
+    Table table = connection.getTable(TableName.ROOT_TABLE_NAME);
     connection.close();
     try {
       Get get = new Get(Bytes.toBytes("dummyRow"));
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 f1111e1..a5988d3 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
@@ -1672,8 +1672,8 @@ public class MasterRpcServices extends RSRpcServices implements
       }
       Pair<RegionInfo, ServerName> pair =
         MetaTableAccessor.getRegion(master.getConnection(), regionName);
-      if (Bytes.equals(RegionInfoBuilder.FIRST_META_REGIONINFO.getRegionName(), regionName))
{
-        pair = new Pair<>(RegionInfoBuilder.FIRST_META_REGIONINFO,
+      if (Bytes.equals(RegionInfoBuilder.ROOT_REGIONINFO.getRegionName(), regionName)) {
+        pair = new Pair<>(RegionInfoBuilder.ROOT_REGIONINFO,
           MetaTableLocator.getRootRegionLocation(master.getZooKeeper()));
       }
       if (pair == null) {
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
index 18147e5..00ba4c0 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
@@ -1190,6 +1190,7 @@ public class HRegionServer extends Thread implements
     LOG.info("Exiting; stopping=" + this.serverName + "; zookeeper connection closed.");
   }
 
+  //TODO francis update this
   private boolean containsMetaTableRegions() {
     return onlineRegions.containsKey(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedName());
   }
@@ -1981,12 +1982,16 @@ public class HRegionServer extends Thread implements
     // Start executor services
     this.executorService.startExecutorService(ExecutorType.RS_OPEN_REGION,
         conf.getInt("hbase.regionserver.executor.openregion.threads", 3));
+    this.executorService.startExecutorService(ExecutorType.RS_OPEN_ROOT,
+      conf.getInt("hbase.regionserver.executor.openmeta.threads", 1));
     this.executorService.startExecutorService(ExecutorType.RS_OPEN_META,
         conf.getInt("hbase.regionserver.executor.openmeta.threads", 1));
     this.executorService.startExecutorService(ExecutorType.RS_OPEN_PRIORITY_REGION,
         conf.getInt("hbase.regionserver.executor.openpriorityregion.threads", 3));
     this.executorService.startExecutorService(ExecutorType.RS_CLOSE_REGION,
         conf.getInt("hbase.regionserver.executor.closeregion.threads", 3));
+    this.executorService.startExecutorService(ExecutorType.RS_CLOSE_ROOT,
+      conf.getInt("hbase.regionserver.executor.closemeta.threads", 1));
     this.executorService.startExecutorService(ExecutorType.RS_CLOSE_META,
         conf.getInt("hbase.regionserver.executor.closemeta.threads", 1));
     if (conf.getBoolean(StoreScanner.STORESCANNER_PARALLEL_SEEK_ENABLE, false)) {
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
index cbca1a5..f15c662 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
@@ -130,6 +130,7 @@ import org.apache.hadoop.hbase.regionserver.handler.AssignRegionHandler;
 import org.apache.hadoop.hbase.regionserver.handler.OpenMetaHandler;
 import org.apache.hadoop.hbase.regionserver.handler.OpenPriorityRegionHandler;
 import org.apache.hadoop.hbase.regionserver.handler.OpenRegionHandler;
+import org.apache.hadoop.hbase.regionserver.handler.OpenRootHandler;
 import org.apache.hadoop.hbase.regionserver.handler.UnassignRegionHandler;
 import org.apache.hadoop.hbase.namequeues.NamedQueueRecorder;
 import org.apache.hadoop.hbase.security.Superusers;
@@ -2150,9 +2151,12 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
           if (regionServer.executorService == null) {
             LOG.info("No executor executorService; skipping open request");
           } else {
-            if (region.isMetaRegion()) {
+            if (region.isRootRegion()) {
+              regionServer.executorService.submit(new OpenRootHandler(
+                regionServer, regionServer, region, htd, masterSystemTime));
+            } else if (region.isMetaRegion()) {
               regionServer.executorService.submit(new OpenMetaHandler(
-              regionServer, regionServer, region, htd, masterSystemTime));
+                regionServer, regionServer, region, htd, masterSystemTime));
             } else {
               if (regionOpenInfo.getFavoredNodesCount() > 0) {
                 regionServer.updateRegionFavoredNodesMapping(region.getEncodedName(),
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/AssignRegionHandler.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/AssignRegionHandler.java
index 3474bf9..1bc264a 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/AssignRegionHandler.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/AssignRegionHandler.java
@@ -167,8 +167,11 @@ public class AssignRegionHandler extends EventHandler {
   public static AssignRegionHandler create(HRegionServer server, RegionInfo regionInfo,
       long openProcId, TableDescriptor tableDesc, long masterSystemTime) {
     EventType eventType;
-    if (regionInfo.isMetaRegion()) {
-      eventType = EventType.M_RS_CLOSE_META;
+
+    if (regionInfo.isRootRegion()) {
+      eventType = EventType.M_RS_CLOSE_ROOT;
+    } else if (regionInfo.isMetaRegion()) {
+        eventType = EventType.M_RS_CLOSE_META;
     } else if (regionInfo.getTable().isSystemTable() ||
       (tableDesc != null && tableDesc.getPriority() >= HConstants.ADMIN_QOS))
{
       eventType = EventType.M_RS_OPEN_PRIORITY_REGION;
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRootHandler.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRootHandler.java
new file mode 100644
index 0000000..bb87613
--- /dev/null
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRootHandler.java
@@ -0,0 +1,40 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.regionserver.handler;
+
+import org.apache.hadoop.hbase.Server;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.executor.EventType;
+import org.apache.hadoop.hbase.regionserver.RegionServerServices;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * Handles closing of the meta region on a region server.
+ */
+@InterfaceAudience.Private
+public class CloseRootHandler extends CloseRegionHandler {
+
+  // Called when regionserver determines its to go down; not master orchestrated
+  public CloseRootHandler(final Server server,
+                          final RegionServerServices rsServices,
+                          final RegionInfo regionInfo,
+                          final boolean abort) {
+    super(server, rsServices, regionInfo, abort, EventType.M_RS_CLOSE_ROOT, null);
+  }
+}
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRootHandler.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRootHandler.java
new file mode 100644
index 0000000..7a06733
--- /dev/null
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRootHandler.java
@@ -0,0 +1,40 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.regionserver.handler;
+
+import org.apache.hadoop.hbase.Server;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.client.TableDescriptor;
+import org.apache.hadoop.hbase.executor.EventType;
+import org.apache.hadoop.hbase.regionserver.RegionServerServices;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * Handles opening of a meta region on a region server.
+ * <p>
+ * This is executed after receiving an OPEN RPC from the master for meta.
+ */
+@InterfaceAudience.Private
+public class OpenRootHandler extends OpenRegionHandler {
+  public OpenRootHandler(final Server server,
+                         final RegionServerServices rsServices, RegionInfo regionInfo,
+                         final TableDescriptor htd, long masterSystemTime) {
+    super(server, rsServices, regionInfo, htd, masterSystemTime, EventType.M_RS_OPEN_ROOT);
+  }
+}
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/UnassignRegionHandler.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/UnassignRegionHandler.java
index 8b275d0..c15e309 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/UnassignRegionHandler.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/UnassignRegionHandler.java
@@ -145,8 +145,9 @@ public class UnassignRegionHandler extends EventHandler {
     // if we put the handler into a wrong executor.
     Region region = server.getRegion(encodedName);
     EventType eventType =
-      region != null && region.getRegionInfo().isMetaRegion() ? EventType.M_RS_CLOSE_META
-        : EventType.M_RS_CLOSE_REGION;
+      region != null && region.getRegionInfo().isRootRegion() ?
+        EventType.M_RS_CLOSE_ROOT : region.getRegionInfo().isMetaRegion() ?
+          EventType.M_RS_CLOSE_META : EventType.M_RS_CLOSE_REGION;
     return new UnassignRegionHandler(server, encodedName, closeProcId, abort, destination,
       eventType);
   }


Mime
View raw message