saintstack commented on a change in pull request #2095:
URL: https://github.com/apache/hbase/pull/2095#discussion_r458460907



##########
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetaLocationCache.java
##########
@@ -0,0 +1,163 @@
+/**
+ * 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.master;
+
+import static org.apache.hadoop.hbase.client.ConnectionUtils.locateRow;
+import static org.apache.hadoop.hbase.client.ConnectionUtils.locateRowBefore;
+import static org.apache.hadoop.hbase.util.FutureUtils.addListener;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import org.apache.hadoop.hbase.HRegionLocation;
+import org.apache.hadoop.hbase.RegionLocations;
+import org.apache.hadoop.hbase.ScheduledChore;
+import org.apache.hadoop.hbase.Stoppable;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.AsyncClusterConnection;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.client.RegionLocateType;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import 
org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
+
+/**
+ * A cache of meta region locations.
+ */
+@InterfaceAudience.Private
+class MetaLocationCache implements Stoppable {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(MetaLocationCache.class);
+
+  @VisibleForTesting
+  static final String SYNC_INTERVAL_SECONDS =
+    "hbase.master.meta-location-cache.sync-interval-seconds";
+
+  // default sync every 1 second.
+  @VisibleForTesting
+  static final int DEFAULT_SYNC_INTERVAL_SECONDS = 1;
+
+  private static final String FETCH_TIMEOUT_MS =
+    "hbase.master.meta-location-cache.fetch-timeout-ms";
+
+  // default timeout 1 second
+  private static final int DEFAULT_FETCH_TIMEOUT_MS = 1000;
+
+  private static final class CacheHolder {
+
+    final NavigableMap<byte[], RegionLocations> cache;
+
+    final List<HRegionLocation> all;
+
+    CacheHolder(List<HRegionLocation> all) {
+      this.all = Collections.unmodifiableList(all);
+      NavigableMap<byte[], SortedSet<HRegionLocation>> startKeyToLocs =
+        new TreeMap<>(Bytes.BYTES_COMPARATOR);
+      for (HRegionLocation loc : all) {
+        if (loc.getRegion().isSplitParent()) {
+          continue;
+        }
+        startKeyToLocs.computeIfAbsent(loc.getRegion().getStartKey(),
+          k -> new TreeSet<>((l1, l2) -> 
l1.getRegion().compareTo(l2.getRegion()))).add(loc);
+      }
+      this.cache = 
startKeyToLocs.entrySet().stream().collect(Collectors.collectingAndThen(
+        Collectors.toMap(Map.Entry::getKey, e -> new 
RegionLocations(e.getValue()), (u, v) -> {
+          throw new IllegalStateException();
+        }, () -> new TreeMap<>(Bytes.BYTES_COMPARATOR)), 
Collections::unmodifiableNavigableMap));

Review comment:
       Whats the start key look like then in ROOT? Does it not have tablename 
as prefix with ',' separators? Don't you want "TABLENAME<SPACE>,...." to sort 
after "TABLENAME,...."?




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to