From fc73b88a8f7e60b6c16cf9741c03198851d5f199 Mon Sep 17 00:00:00 2001 From: Umesh Agashe Date: Fri, 14 Sep 2018 14:28:00 -0700 Subject: [PATCH] HBASE-21169: Initial commit with HBCK2 tool, command line parsing, help/ usage message. --- .gitignore | 22 ++ hbase-hbck2/pom.xml | 14 +- hbase-hbck2/src/main/avro/HbaseKafkaEvent.avro | 30 --- .../java/org/apache/hadoop/hbase/HBaseFsck2.java | 285 +++++++++++++++++++++ 4 files changed, 319 insertions(+), 32 deletions(-) create mode 100644 .gitignore delete mode 100644 hbase-hbck2/src/main/avro/HbaseKafkaEvent.avro create mode 100644 hbase-hbck2/src/main/java/org/apache/hadoop/hbase/HBaseFsck2.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..0fce7d40166cb3bd024881d1f56507bedad2189f --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +/.externalToolBuilders +.project +*.settings/ +.DS_Store +.classpath +/build +/.idea/ +/logs +*target/ +*.orig +*~ +hbase-*/test +*.iws +*.iml +*.ipr +patchprocess/ +dependency-reduced-pom.xml +link_report/ +linklint-*.zip +linklint/ +.checkstyle +**/.checkstyle diff --git a/hbase-hbck2/pom.xml b/hbase-hbck2/pom.xml index 82e80c97937d24a8d9d67833ed5e619f06059eec..13073e254c489b086539b333e3d4bb036aeb5b2b 100644 --- a/hbase-hbck2/pom.xml +++ b/hbase-hbck2/pom.xml @@ -32,10 +32,20 @@ Apache HBase - HBCK2 HBCK for HBase 2+ - + + + org.apache.hbase + hbase-common + ${hbase.version} + + + org.apache.hbase + hbase-client + ${hbase.version} + + - ${project.basedir}/target/java diff --git a/hbase-hbck2/src/main/avro/HbaseKafkaEvent.avro b/hbase-hbck2/src/main/avro/HbaseKafkaEvent.avro deleted file mode 100644 index ec886274417efec7e358804d7c1a0bf16adee48c..0000000000000000000000000000000000000000 --- a/hbase-hbck2/src/main/avro/HbaseKafkaEvent.avro +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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. -*/ -{"namespace": "org.apache.hadoop.hbase.kafka", - "type": "record", - "name": "HBaseKafkaEvent", - "fields": [ - {"name": "key", "type": "bytes"}, - {"name": "timestamp", "type": "long" }, - {"name": "delete", "type": "boolean" }, - {"name": "value", "type": "bytes"}, - {"name": "qualifier", "type": "bytes"}, - {"name": "family", "type": "bytes"}, - {"name": "table", "type": "bytes"} - ] -} diff --git a/hbase-hbck2/src/main/java/org/apache/hadoop/hbase/HBaseFsck2.java b/hbase-hbck2/src/main/java/org/apache/hadoop/hbase/HBaseFsck2.java new file mode 100644 index 0000000000000000000000000000000000000000..4b47967ecc700f3754db091fc08891c12233bac1 --- /dev/null +++ b/hbase-hbck2/src/main/java/org/apache/hadoop/hbase/HBaseFsck2.java @@ -0,0 +1,285 @@ +/** + * 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.hadoop.hbase; + +import java.io.Closeable; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import org.apache.hadoop.hbase.client.TableState; +import org.apache.hadoop.hbase.master.RegionState; +import org.apache.hadoop.hbase.util.AbstractHBaseTool; +import org.apache.hadoop.hbase.util.VersionInfo; +import org.apache.log4j.Category; +import org.apache.log4j.Level; +import org.apache.yetus.audience.InterfaceAudience; +import org.apache.yetus.audience.InterfaceStability; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine; +import org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter; +import org.apache.hbase.thirdparty.org.apache.commons.cli.Option; + +@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS) +@InterfaceStability.Evolving +public class HBaseFsck2 extends AbstractHBaseTool implements Closeable { + private static final Logger LOG = LoggerFactory.getLogger(HBaseFsck2.class); + + private static long startTime = System.currentTimeMillis(); + private boolean reportOnly = true; + + private long timelag = 0; // in milliseconds + private boolean exclusive = true; // only one instance of hbck is allowed to run + + private Set tableNames = null; + private Set regionNames = null; + private Set serverNames = null; + + private boolean details = false; + private boolean verbose = false; + + private org.apache.hbase.thirdparty.org.apache.commons.cli.Options actions = + new org.apache.hbase.thirdparty.org.apache.commons.cli.Options(); + + private Set actionNames = new HashSet<>(); + + Collection regionServers = new ArrayList(); + private Map tableStates; + private Set rits; + + private boolean isExclusive() { + return !reportOnly || exclusive; + } + + private boolean isVersionSupported(final String hbaseServerVersion) { + return VersionInfo.compareVersion("2.any.any", hbaseServerVersion) < 0; + } + + private String getActionsUsage() { + /* AbstractHBaseTool uses org.apache.commons.cli for command line arg processing. In general, + the command line looks like: 'cmd [OPTIONS] [ACTIONS]'. The default printUsage() method prints + help/ usage messages for each option supported. But not for actions. Below we override + HelpFormatter#renderOptions() method to generate help/ usages messages for actions. + */ + return new HelpFormatter() { + public String getActionsUsage() { + StringBuffer sb = new StringBuffer("Actions:" + this.getNewLine()); + return renderOptions(sb, 120, actions, this.getLeftPadding(), + this.getDescPadding()).toString(); + } + + @Override + protected StringBuffer renderOptions(StringBuffer sb, int width, + org.apache.hbase.thirdparty.org.apache.commons.cli.Options options, + int leftPad, int descPad) { + String lpad = this.createPadding(leftPad); + String dpad = this.createPadding(descPad); + int max = 0; + List prefixList = new ArrayList(); + + List