You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by sa...@apache.org on 2019/08/15 20:00:51 UTC

[hbase-operator-tools] branch master updated: HBASE-22843 [HBCK2] Add HBCKMetaTableAccessor for hbck2

This is an automated email from the ASF dual-hosted git repository.

sakthi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase-operator-tools.git


The following commit(s) were added to refs/heads/master by this push:
     new 379b8cc  HBASE-22843 [HBCK2] Add HBCKMetaTableAccessor for hbck2
379b8cc is described below

commit 379b8ccdbdcd3d95c9bdfbaa1729b4a1f868f924
Author: Sakthi <sa...@apache.org>
AuthorDate: Thu Aug 15 13:00:47 2019 -0700

    HBASE-22843 [HBCK2] Add HBCKMetaTableAccessor for hbck2
    
    - A fix after HBASE-22777 & HBASE-22758
    
    Signed-off-by: Stack <st...@apache.org>
---
 .../org/apache/hbase/HBCKMetaTableAccessor.java    | 139 +++++++++++++++++++++
 .../java/org/apache/hbase/hbck1/HBaseFsck.java     |  16 +--
 .../org/apache/hbase/hbck1/HBaseFsckRepair.java    |   3 +-
 3 files changed, 150 insertions(+), 8 deletions(-)

diff --git a/hbase-hbck2/src/main/java/org/apache/hbase/HBCKMetaTableAccessor.java b/hbase-hbck2/src/main/java/org/apache/hbase/HBCKMetaTableAccessor.java
new file mode 100644
index 0000000..52e9313
--- /dev/null
+++ b/hbase-hbck2/src/main/java/org/apache/hbase/HBCKMetaTableAccessor.java
@@ -0,0 +1,139 @@
+/*
+ * 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.hbase;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellUtil;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.Delete;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * hbck's local version of the MetaTableAccessor from the hbase repo
+ * A Utility class to facilitate hbck2's access to Meta table.
+ */
+@InterfaceAudience.Private
+public final class HBCKMetaTableAccessor {
+
+  /**
+   * Private constructor to keep this class from being instantiated.
+   */
+  private HBCKMetaTableAccessor() {
+  }
+
+  private static final Logger LOG = LoggerFactory.getLogger(
+      HBCKMetaTableAccessor.class);
+
+  // Constants
+  private static final byte[] MERGE_QUALIFIER_PREFIX = Bytes.toBytes("merge");
+
+  public static List<RegionInfo> getMergeRegions(Cell[] cells) {
+    if (cells == null) {
+      return null;
+    }
+    List<RegionInfo> regionsToMerge = null;
+    for (Cell cell : cells) {
+      if (!isMergeQualifierPrefix(cell)) {
+        continue;
+      }
+      // Ok. This cell is that of a info:merge* column.
+      RegionInfo ri = RegionInfo
+          .parseFromOrNull(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
+      if (ri != null) {
+        if (regionsToMerge == null) {
+          regionsToMerge = new ArrayList<>();
+        }
+        regionsToMerge.add(ri);
+      }
+    }
+    return regionsToMerge;
+  }
+
+  /**
+   * Delete the passed <code>RegionInfo</code> from the <code>hbase:meta</code> table.
+   *
+   * @param connection connection we're using
+   * @param regionInfo the regionInfo to delete from the meta table
+   * @throws IOException if it's not able to delete the regionInfo
+   */
+  public static void deleteRegionInfo(Connection connection, RegionInfo regionInfo)
+      throws IOException {
+    Delete delete = new Delete(regionInfo.getRegionName());
+    delete.addFamily(HConstants.CATALOG_FAMILY, HConstants.LATEST_TIMESTAMP);
+    deleteFromMetaTable(connection, delete);
+    LOG.info("Deleted {}", regionInfo.getRegionNameAsString());
+  }
+
+  // Private helper methods
+
+  // COPIED from MetaTableAccessor.isMergeQualifierPrefix()
+  private static boolean isMergeQualifierPrefix(Cell cell) {
+    // Check to see if has family and that qualifier starts with the MERGE_QUALIFIER_PREFIX
+    return CellUtil.matchingFamily(cell, HConstants.CATALOG_FAMILY) && qualifierStartsWith(cell,
+        MERGE_QUALIFIER_PREFIX);
+  }
+
+  /**
+   * Finds if the start of the qualifier part of the Cell matches 'startsWith'
+   *
+   * COPIED from PrivateCellUtil.qualifierStartsWith()
+   * @param left       the cell with which we need to match the qualifier
+   * @param startsWith the serialized keyvalue format byte[]
+   * @return true if the qualifier have same staring characters, false otherwise
+   */
+  private static boolean qualifierStartsWith(final Cell left, final byte[] startsWith) {
+    if (startsWith == null || startsWith.length == 0) {
+      throw new IllegalArgumentException("Cannot pass an empty startsWith");
+    }
+    return Bytes
+        .equals(left.getQualifierArray(), left.getQualifierOffset(), startsWith.length, startsWith,
+            0, startsWith.length);
+  }
+
+  /**
+   * Delete the passed <code>d</code> from the <code>hbase:meta</code> table.
+   *
+   * COPIED MetaTableAccessor.deleteFromMetaTable()
+   * @param connection connection we're using
+   * @param d          Delete to add to hbase:meta
+   */
+  private static void deleteFromMetaTable(final Connection connection, final Delete d)
+      throws IOException {
+    if (connection == null) {
+      throw new NullPointerException("No connection");
+    } else if (connection.isClosed()) {
+      throw new IOException("connection is closed");
+    }
+    try (Table t = connection.getTable(TableName.META_TABLE_NAME)) {
+      List<Delete> deletes = Arrays.asList(d);
+      LOG.debug("Add {} delete to meta table", deletes);
+      t.delete(deletes);
+    }
+  }
+}
diff --git a/hbase-hbck2/src/main/java/org/apache/hbase/hbck1/HBaseFsck.java b/hbase-hbck2/src/main/java/org/apache/hbase/hbck1/HBaseFsck.java
index 4d16591..68cec0a 100644
--- a/hbase-hbck2/src/main/java/org/apache/hbase/hbck1/HBaseFsck.java
+++ b/hbase-hbck2/src/main/java/org/apache/hbase/hbck1/HBaseFsck.java
@@ -148,6 +148,7 @@ import org.apache.hadoop.ipc.RemoteException;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.util.ReflectionUtils;
 import org.apache.hadoop.util.Tool;
+import org.apache.hbase.HBCKMetaTableAccessor;
 import org.apache.yetus.audience.InterfaceAudience;
 import org.apache.yetus.audience.InterfaceStability;
 import org.apache.zookeeper.KeeperException;
@@ -3924,13 +3925,14 @@ public class HBaseFsck extends Configured implements Closeable {
               throw new IOException("Two entries in hbase:meta are same " + previous);
             }
           }
-          PairOfSameType<RegionInfo> mergeRegions = MetaTableAccessor.getMergeRegions(result);
-          for (RegionInfo mergeRegion : new RegionInfo[] {
-              mergeRegions.getFirst(), mergeRegions.getSecond() }) {
-            if (mergeRegion != null) {
-              // This region is already been merged
-              HbckInfo hbInfo = getOrCreateInfo(mergeRegion.getEncodedName());
-              hbInfo.setMerged(true);
+          List<RegionInfo> mergeParents = HBCKMetaTableAccessor.getMergeRegions(result.rawCells());
+          if (mergeParents != null) {
+            for (RegionInfo mergeRegion : mergeParents) {
+              if (mergeRegion != null) {
+                // This region is already being merged
+                HbckInfo hbInfo = getOrCreateInfo(mergeRegion.getEncodedName());
+                hbInfo.setMerged(true);
+              }
             }
           }
 
diff --git a/hbase-hbck2/src/main/java/org/apache/hbase/hbck1/HBaseFsckRepair.java b/hbase-hbck2/src/main/java/org/apache/hbase/hbck1/HBaseFsckRepair.java
index a501029..ef47c55 100644
--- a/hbase-hbck2/src/main/java/org/apache/hbase/hbck1/HBaseFsckRepair.java
+++ b/hbase-hbck2/src/main/java/org/apache/hbase/hbck1/HBaseFsckRepair.java
@@ -43,6 +43,7 @@ import org.apache.hadoop.hbase.master.RegionState;
 import org.apache.hadoop.hbase.master.ServerManager;
 import org.apache.hadoop.hbase.regionserver.HRegion;
 import org.apache.hadoop.hbase.util.FSUtils;
+import org.apache.hbase.HBCKMetaTableAccessor;
 import org.apache.zookeeper.KeeperException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -200,6 +201,6 @@ public final class HBaseFsckRepair {
    */
   public static void removeParentInMeta(Configuration conf, RegionInfo hri) throws IOException {
     Connection conn = ConnectionFactory.createConnection(conf);
-    MetaTableAccessor.deleteRegion(conn, hri);
+    HBCKMetaTableAccessor.deleteRegionInfo(conn, hri);
   }
 }