wchevreuil commented on a change in pull request #78: URL: https://github.com/apache/hbase-operator-tools/pull/78#discussion_r520823960
########## File path: hbase-tools/src/main/java/org/apache/hbase/MissingRegionDirsRepairTool.java ########## @@ -0,0 +1,126 @@ +/* + * 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.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.HBaseConfiguration; +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.tool.LoadIncrementalHFiles; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.util.ToolRunner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public class MissingRegionDirsRepairTool extends Configured implements org.apache.hadoop.util.Tool { + + private static final Logger LOG = + LoggerFactory.getLogger(MissingRegionDirsRepairTool.class.getName()); + + private static final String TEMP_DIR_PREFIX = "missing_dirs_repair_"; + + private Configuration conf; + private HBCK2 hbck; + private LoadIncrementalHFiles bulkLoad; + + public MissingRegionDirsRepairTool(Configuration conf) { + this.conf=conf; + this.hbck = new HBCK2(conf); + this.bulkLoad = new LoadIncrementalHFiles(conf); + } + + @Override + public int run(String[] strings) throws Exception { + Map<TableName,List<Path>> result = hbck + .reportTablesWithMissingRegionsInMeta(null); + Path runPath = new Path(HBCKFsUtils.getRootDir(conf), + TEMP_DIR_PREFIX + System.currentTimeMillis()); + FileSystem fs = runPath.getFileSystem(conf); + LOG.info("creating temp dir at: " + runPath.getName()); + fs.mkdirs(runPath); + try(Connection conn = ConnectionFactory.createConnection(conf)) { + Admin admin = conn.getAdmin(); + result.forEach((t, p) -> { + if(!p.isEmpty()) { + Path tblPath = + new Path(runPath, new Path(t.getNameWithNamespaceInclAsString() + .replaceAll(":", "_"))); + try { + fs.mkdirs(tblPath); + Path sidelined = new Path(tblPath, "sidelined"); + fs.mkdirs(sidelined); + Path bulkload = new Path(tblPath, "bulkload"); + fs.mkdirs(bulkload); + p.stream().forEach(region -> { + try { + Path sidelinedRegionDir = new Path(sidelined, region.getName()); + fs.mkdirs(sidelinedRegionDir); + HBCKFsUtils.copyFilesParallel(fs, region, fs, sidelinedRegionDir, conf, 3); Review comment: For this copyFilesParallel method call, there wouldn't be any problems, as the sidelinedRegionDir is under the individual "missing_dirs_repair_TS" dir. But if each run gets here at different times, later runs would not find already sidelined regions. There's still possibility that same region gets sidelined by different runs, which would also bulkload the regions files again. Not ideal in terms of resources usage, but still fine for data consistency sake. I guess we can implement some sort of lock file in a given hdfs location to avoid multiple runs? ---------------------------------------------------------------- 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]
