infraio commented on a change in pull request #2354:
URL: https://github.com/apache/hbase/pull/2354#discussion_r484237351



##########
File path: 
hbase-client/src/main/java/org/apache/hadoop/hbase/CatalogFamilyFormat.java
##########
@@ -346,4 +347,64 @@ public static TableState getTableState(Result r) throws 
IOException {
       throw new IOException(e);
     }
   }
+
+  /**
+   * @return Deserialized values of <qualifier,regioninfo> pairs taken 
from column values that
+   *         match the regex 'info:merge.*' in array of <code>cells</code>.
+   */
+  @Nullable
+  public static Map<String, RegionInfo> getMergeRegionsWithName(Cell[] cells) {
+    if (cells == null) {
+      return null;
+    }
+    Map<String, 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 LinkedHashMap<>();
+        }
+        regionsToMerge.put(Bytes.toString(CellUtil.cloneQualifier(cell)), ri);
+      }
+    }
+    return regionsToMerge;
+  }
+
+  /**
+   * @return Deserialized regioninfo values taken from column values that 
match the regex
+   *         'info:merge.*' in array of <code>cells</code>.
+   */
+  @Nullable
+  public static List<RegionInfo> getMergeRegions(Cell[] cells) {
+    Map<String, RegionInfo> mergeRegionsWithName = 
getMergeRegionsWithName(cells);
+    return (mergeRegionsWithName == null) ? null : new 
ArrayList<>(mergeRegionsWithName.values());
+  }
+
+  /**
+   * @return True if any merge regions present in <code>cells</code>; i.e. the 
column in
+   *         <code>cell</code> matches the regex 'info:merge.*'.
+   */
+  public static boolean hasMergeRegions(Cell[] cells) {

Review comment:
       Minor suggestion. Can reduce one line code. :-)
   
   for (Cell cell : cells) {
       if (isMergeQualifierPrefix(cell)) {
           return true;
       }
   }
   return false;




----------------------------------------------------------------
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:
[email protected]


Reply via email to