huaxiangsun commented on a change in pull request #2584:
URL: https://github.com/apache/hbase/pull/2584#discussion_r514583501



##########
File path: 
hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java
##########
@@ -196,8 +202,43 @@ private boolean tryComplete(LocateRequest req, 
CompletableFuture<RegionLocations
       MAX_CONCURRENT_LOCATE_REQUEST_PER_TABLE, 
DEFAULT_MAX_CONCURRENT_LOCATE_REQUEST_PER_TABLE);
     this.locatePrefetchLimit =
       conn.getConfiguration().getInt(LOCATE_PREFETCH_LIMIT, 
DEFAULT_LOCATE_PREFETCH_LIMIT);
-    this.useMetaReplicas =
-      conn.getConfiguration().getBoolean(USE_META_REPLICAS, 
DEFAULT_USE_META_REPLICAS);
+
+    // Get the region locator's meta replica mode.
+    this.metaReplicaMode = CatalogReplicaMode.valueOf(conn.getConfiguration()
+      .get(LOCATOR_META_REPLICAS_MODE, CatalogReplicaMode.None.toString()));
+
+    switch (this.metaReplicaMode) {
+      case LoadBalance:
+        String replicaSelectorClass = conn.getConfiguration().
+          get(RegionLocator.LOCATOR_META_REPLICAS_MODE_LOADBALANCE_SELECTOR,
+          CatalogReplicaLoadBalanceSimpleSelector.class.getName());
+
+        this.metaReplicaSelector = 
CatalogReplicaLoadBalanceSelectorFactory.createSelector(
+          replicaSelectorClass, META_TABLE_NAME, conn, () -> {
+            int numOfReplicas = 1;
+            try {
+              RegionLocations metaLocations = 
conn.registry.getMetaRegionLocations().get(
+                GET_META_LOCATIONS_TIMEOUT, TimeUnit.MILLISECONDS);
+              numOfReplicas = metaLocations.size();
+            } catch (Exception e) {
+              LOG.error("Failed to get table {}'s region replication, ", 
META_TABLE_NAME, e);
+            }
+            return numOfReplicas;
+          });
+        break;
+      case None:
+        // If user does not configure LOCATOR_META_REPLICAS_MODE, let's check 
the legacy config.
+        if (this.metaReplicaMode == CatalogReplicaMode.None) {
+          boolean useMetaReplicas = 
conn.getConfiguration().getBoolean(USE_META_REPLICAS,
+            DEFAULT_USE_META_REPLICAS);
+          if (useMetaReplicas) {
+            this.metaReplicaMode = CatalogReplicaMode.HedgedRead;

Review comment:
       The whole purpose is to set up the metaReplicaMode. In case of 
LoadBalance mode, it needs to create CatalogSelector. In case of HedgedRead, 
there is nothing to be done. None is not HedgedRead, it means that there is no 
metaReplicaMode configured. In this case, it still needs to check if 
USE_META_REPLICAS is configured or not, if USE_META_REPLICAS is configured, it 
needs to set metaReplicaMode to HedgedRead. HedgedRead is the previous 
USE_META_REPLICAS. default branch is added to avoid warning from some java 
checking.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to