saintstack commented on a change in pull request #14: HBASE-22843 [HBCK2] Fix 
HBCK2 after HBASE-22777 & HBASE-22758
URL: 
https://github.com/apache/hbase-operator-tools/pull/14#discussion_r314463909
 
 

 ##########
 File path: 
hbase-hbck2/src/main/java/org/apache/hbase/HBCKMetaTableAccessor.java
 ##########
 @@ -0,0 +1,133 @@
+/*
+ * 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 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;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * hbck's local version of the MetaTableAccessor from the hbase repo
+ */
+@InterfaceAudience.Private
+public class 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
+   */
+  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,
 
 Review comment:
   This sounds good. WIll be slower but that ok for fixup tool. Thanks for 
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to