You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2019/09/17 04:35:32 UTC

[GitHub] [hbase] anoopsjohn commented on a change in pull request #600: HBASE-22460 : Reopen regions with very high Store Ref Counts

anoopsjohn commented on a change in pull request #600: HBASE-22460 : Reopen regions with very high Store Ref Counts
URL: https://github.com/apache/hbase/pull/600#discussion_r324977535
 
 

 ##########
 File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionsRecoveryChore.java
 ##########
 @@ -0,0 +1,154 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.ClusterMetrics;
+import org.apache.hadoop.hbase.RegionMetrics;
+import org.apache.hadoop.hbase.ScheduledChore;
+import org.apache.hadoop.hbase.ServerMetrics;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.Stoppable;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.PerClientRandomNonceGenerator;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hbase.thirdparty.org.apache.commons.collections4.MapUtils;
+
+/**
+ * This chore, every time it runs, will try to recover regions with high store ref count
+ * by reopening them
+ */
+@InterfaceAudience.Private
+public class RegionsRecoveryChore extends ScheduledChore {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RegionsRecoveryChore.class);
+
+  private static final String REGIONS_RECOVERY_CHORE_NAME = "RegionsRecoveryChore";
+
+  private static final String REGIONS_RECOVERY_INTERVAL =
+    "hbase.master.regions.recovery.interval";
+  private static final String STORE_REF_COUNT_THRESHOLD = "hbase.regions.recovery.store.count";
+
+  private static final int DEFAULT_REGIONS_RECOVERY_INTERVAL = 1200 * 1000; // Default 20 min ?
+  private static final int DEFAULT_STORE_REF_COUNT_THRESHOLD = 256;
+
+  private static final String ERROR_REOPEN_REIONS_MSG =
+    "Error reopening regions with high storeRefCount. ";
+
+  private final HMaster hMaster;
+  private final int storeRefCountThreshold;
+
+  private static final PerClientRandomNonceGenerator NONCE_GENERATOR =
+    PerClientRandomNonceGenerator.get();
+
+  /**
+   * Construct RegionsRecoveryChore with provided params
+   *
+   * @param stopper When {@link Stoppable#isStopped()} is true, this chore will cancel and cleanup
+   * @param configuration The configuration params to be used
+   * @param hMaster HMaster instance to initiate RegionTableRegions
+   */
+  RegionsRecoveryChore(final Stoppable stopper, final Configuration configuration,
+      final HMaster hMaster) {
+
+    super(REGIONS_RECOVERY_CHORE_NAME, stopper, configuration.getInt(REGIONS_RECOVERY_INTERVAL,
+      DEFAULT_REGIONS_RECOVERY_INTERVAL));
+    this.hMaster = hMaster;
+    this.storeRefCountThreshold = configuration.getInt(STORE_REF_COUNT_THRESHOLD,
+      DEFAULT_STORE_REF_COUNT_THRESHOLD);
+
+  }
+
+  @Override
+  protected void chore() {
+    if (LOG.isTraceEnabled()) {
+      LOG.trace("Starting up Regions Recovery by reopening regions based on storeRefCount...");
+    }
+    try {
+      final ClusterMetrics clusterMetrics = hMaster.getClusterMetrics();
+      final Map<ServerName, ServerMetrics> serverMetricsMap =
+        clusterMetrics.getLiveServerMetrics();
+      final Map<TableName, List<byte[]>> tableToReopenRegionsMap =
+        getTableToRegionsByRefCount(serverMetricsMap);
+      if (MapUtils.isNotEmpty(tableToReopenRegionsMap)) {
+        tableToReopenRegionsMap.forEach((tableName, regionNames) -> {
+          try {
+            LOG.warn("Reopening regions due to high refCount. TableName: {} , noOfRegions: {}",
+              tableName, regionNames.size());
+            hMaster.reopenRegions(tableName, regionNames, NONCE_GENERATOR.getNonceGroup(),
+              NONCE_GENERATOR.newNonce());
+          } catch (IOException e) {
+            LOG.error("{} tableName: {}, regionNames: {}", ERROR_REOPEN_REIONS_MSG,
+              tableName, regionNames, e);
+          }
+        });
+      }
+    } catch (Exception e) {
+      LOG.error("Error while reopening regions based on storeRefCount threshold", e);
+    }
+    if (LOG.isTraceEnabled()) {
+      LOG.trace("Exiting Regions Recovery by reopening regions based on storeRefCount...");
+    }
+  }
+
+  private Map<TableName, List<byte[]>> getTableToRegionsByRefCount(
+      final Map<ServerName, ServerMetrics> serverMetricsMap) {
+
+    final Map<TableName, List<byte[]>> tableToReopenRegionsMap = new HashMap<>();
+    for (ServerMetrics serverMetrics : serverMetricsMap.values()) {
+      Map<byte[], RegionMetrics> regionMetricsMap = serverMetrics.getRegionMetrics();
+      for (RegionMetrics regionMetrics : regionMetricsMap.values()) {
+        final int regionStoreRefCount = regionMetrics.getStoreRefCount();
 
 Review comment:
   This count is the sum of ref count of all HFiles under each of the CF in this region right?  So the sum is not just a factor of many refs on a file. It is a function of number of hfiles under this region. What is it is having so many files at a time and each of that having say <10 active refs. So 250 is obviously not a correct number IMO.  Is there a way we can see refs per HFile?  No need to know ref counts on each of the HFile.  Max number may be enough.  I believe this decision should be made based on the so many ref counts on a file rather than sum of. Thoughts?

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


With regards,
Apache Git Services