joshelser commented on a change in pull request #46: HBASE-23562 [operator tools] Add a RegionsMerge tool that allows for … URL: https://github.com/apache/hbase-operator-tools/pull/46#discussion_r389992344
########## File path: hbase-tools/src/main/java/org/apache/hbase/RegionsMerger.java ########## @@ -0,0 +1,259 @@ +/* + * 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 static org.apache.hadoop.hbase.HConstants.CATALOG_FAMILY; +import static org.apache.hadoop.hbase.HConstants.REGIONINFO_QUALIFIER; +import static org.apache.hadoop.hbase.HConstants.STATE_QUALIFIER; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Future; +import java.util.concurrent.atomic.LongAdder; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.conf.Configured; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.CompareOperator; +import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.Admin; +import org.apache.hadoop.hbase.client.Connection; +import org.apache.hadoop.hbase.client.ConnectionFactory; +import org.apache.hadoop.hbase.client.RegionInfo; +import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.client.ResultScanner; +import org.apache.hadoop.hbase.client.Scan; +import org.apache.hadoop.hbase.client.Table; +import org.apache.hadoop.hbase.filter.FilterList; +import org.apache.hadoop.hbase.filter.RowFilter; +import org.apache.hadoop.hbase.filter.SingleColumnValueFilter; +import org.apache.hadoop.hbase.filter.SubstringComparator; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * HBase maintenance tool for merging regions of a specific table, until a target number of regions + * for the table is reached, or no more merges can complete due to limit in resulting merged + * region size. + */ +public class RegionsMerger extends Configured implements org.apache.hadoop.util.Tool { + + private static final Logger LOG = LoggerFactory.getLogger(RegionsMerger.class.getName()); + public static final String RESULTING_REGION_UPPER_MARK = "hbase.tools.merge.upper.mark"; + public static final String SLEEP = "hbase.tools.merge.sleep"; + public static final String MAX_ROUNDS_IDDLE = "hbase.tools.max.iterations.blocked"; + + private final Configuration conf; + private final FileSystem fs; + private final double resultSizeThreshold; + private final int sleepBetweenCycles; + private final long maxRoundsStuck; + + public RegionsMerger(Configuration conf) throws IOException { + this.conf = conf; + Path basePath = new Path(conf.get(HConstants.HBASE_DIR)); + fs = basePath.getFileSystem(conf); + resultSizeThreshold = this.conf.getDouble(RESULTING_REGION_UPPER_MARK, 0.9) * + this.conf.getLong(HConstants.HREGION_MAX_FILESIZE, HConstants.DEFAULT_MAX_FILE_SIZE); + sleepBetweenCycles = this.conf.getInt(SLEEP, 2000); + this.maxRoundsStuck = this.conf.getInt(MAX_ROUNDS_IDDLE, 10); + } + + private Path getTablePath(TableName table){ + Path basePath = new Path(conf.get(HConstants.HBASE_DIR)); + basePath = new Path(basePath, "data"); + Path tablePath = new Path(basePath, table.getNamespaceAsString()); + return new Path(tablePath, table.getNameAsString()); + } + + private long sumSizeInFS(Path parentPath) throws IOException { Review comment: This has the potential to bash the Namenode. To make space quotas work, each RegionServer will already report the sizes of regions to the Master. However, this isn't guaranteed to be up to date, nor is this exposed over RPC. I can't think of anything else which would (potentially) less impactful on the Namenode, so maybe we just watch this and make sure users are aware that they need to not run lots of these all at the same time. ---------------------------------------------------------------- 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] With regards, Apache Git Services
