Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E3BD717E51 for ; Fri, 3 Apr 2015 02:29:13 +0000 (UTC) Received: (qmail 38298 invoked by uid 500); 3 Apr 2015 02:29:13 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 38249 invoked by uid 500); 3 Apr 2015 02:29:13 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 38238 invoked by uid 99); 3 Apr 2015 02:29:13 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Apr 2015 02:29:13 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 471ADE2F3E; Fri, 3 Apr 2015 02:29:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: enis@apache.org To: commits@hbase.apache.org Message-Id: <57c4eb1314e34d1e95b15fdad9542a8d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hbase git commit: HBASE-12891 Parallel execution for Hbck checkRegionConsistency Date: Fri, 3 Apr 2015 02:29:13 +0000 (UTC) Repository: hbase Updated Branches: refs/heads/0.98 2ec3443f0 -> 977f82d85 HBASE-12891 Parallel execution for Hbck checkRegionConsistency Signed-off-by: Enis Soztutar Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/977f82d8 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/977f82d8 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/977f82d8 Branch: refs/heads/0.98 Commit: 977f82d85e3212ecc1eb2066794314d4bef60ea5 Parents: 2ec3443 Author: Dave Latham Authored: Thu Apr 2 14:23:21 2015 -0700 Committer: Enis Soztutar Committed: Thu Apr 2 19:25:08 2015 -0700 ---------------------------------------------------------------------- .../org/apache/hadoop/hbase/util/HBaseFsck.java | 82 +++++++++++++++++--- 1 file changed, 70 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/977f82d8/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java index 4d21043..cad0ba2 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java @@ -124,8 +124,10 @@ import org.apache.zookeeper.KeeperException; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; +import com.google.common.collect.Ordering; import com.google.common.collect.TreeMultimap; import com.google.protobuf.ServiceException; @@ -1659,8 +1661,56 @@ public class HBaseFsck extends Configured { */ private void checkAndFixConsistency() throws IOException, KeeperException, InterruptedException { + List workItems = + new ArrayList(regionInfoMap.size()); for (java.util.Map.Entry e: regionInfoMap.entrySet()) { - checkRegionConsistency(e.getKey(), e.getValue()); + workItems.add(new CheckRegionConsistencyWorkItem(e.getKey(), e.getValue())); + } + checkRegionConsistencyConcurrently(workItems); + } + + /** + * Check consistency of all regions using mulitple threads concurrently. + */ + private void checkRegionConsistencyConcurrently( + final List workItems) + throws IOException, KeeperException, InterruptedException { + if (workItems.isEmpty()) { + return; // nothing to check + } + + List> workFutures = executor.invokeAll(workItems); + for(Future f: workFutures) { + try { + f.get(); + } catch(ExecutionException e1) { + LOG.warn("Could not check region consistency " , e1.getCause()); + if (e1.getCause() instanceof IOException) { + throw (IOException)e1.getCause(); + } else if (e1.getCause() instanceof KeeperException) { + throw (KeeperException)e1.getCause(); + } else if (e1.getCause() instanceof InterruptedException) { + throw (InterruptedException)e1.getCause(); + } else { + throw new IOException(e1.getCause()); + } + } + } + } + + class CheckRegionConsistencyWorkItem implements Callable { + private final String key; + private final HbckInfo hbi; + + CheckRegionConsistencyWorkItem(String key, HbckInfo hbi) { + this.key = key; + this.hbi = hbi; + } + + @Override + public synchronized Void call() throws Exception { + checkRegionConsistency(key, hbi); + return null; } } @@ -1908,16 +1958,7 @@ public class HBaseFsck extends Configured { HRegionInfo hri = hbi.getHdfsHRI(); TableInfo tableInfo = tablesInfo.get(hri.getTable()); - if (tableInfo.regionsFromMeta.isEmpty()) { - for (HbckInfo h : regionInfoMap.values()) { - if (hri.getTable().equals(h.getTableName())) { - if (h.metaEntry != null) tableInfo.regionsFromMeta - .add((HRegionInfo) h.metaEntry); - } - } - Collections.sort(tableInfo.regionsFromMeta); - } - for (HRegionInfo region : tableInfo.regionsFromMeta) { + for (HRegionInfo region : tableInfo.getRegionsFromMeta()) { if (Bytes.compareTo(region.getStartKey(), hri.getStartKey()) <= 0 && (region.getEndKey().length == 0 || Bytes.compareTo(region.getEndKey(), hri.getEndKey()) >= 0) @@ -2264,7 +2305,7 @@ public class HBaseFsck extends Configured { TreeMultimap.create(RegionSplitCalculator.BYTES_COMPARATOR, cmp); // list of regions derived from meta entries. - final List regionsFromMeta = new ArrayList(); + private ImmutableList regionsFromMeta = null; TableInfo(TableName name) { this.tableName = name; @@ -2319,6 +2360,23 @@ public class HBaseFsck extends Configured { return sc.getStarts().size() + backwards.size(); } + public synchronized ImmutableList getRegionsFromMeta() { + // lazy loaded, synchronized to ensure a single load + if (regionsFromMeta == null) { + List regions = new ArrayList(); + for (HbckInfo h : HBaseFsck.this.regionInfoMap.values()) { + if (tableName.equals(h.getTableName())) { + if (h.metaEntry != null) { + regions.add((HRegionInfo) h.metaEntry); + } + } + } + regionsFromMeta = Ordering.natural().immutableSortedCopy(regions); + } + + return regionsFromMeta; + } + private class IntegrityFixSuggester extends TableIntegrityErrorHandlerImpl { ErrorReporter errors;