diff --git a/hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java b/hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java index 87b20b4e12..932f39a94a 100644 --- a/hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java +++ b/hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java @@ -99,6 +99,7 @@ public class HBCK2 extends Configured implements org.apache.hadoop.util.Tool { private static final String VERSION = "version"; private static final String SET_REGION_STATE = "setRegionState"; private static final String SCHEDULE_RECOVERIES = "scheduleRecoveries"; + private static final String RECOVER_UNKNOWN = "recoverUnknown"; private static final String GENERATE_TABLE_INFO = "generateMissingTableDescriptorFile"; private static final String FIX_META = "fixMeta"; // TODO update this map in case of the name of a method changes in Hbck interface @@ -109,7 +110,9 @@ public class HBCK2 extends Configured implements org.apache.hadoop.util.Tool { put(SET_TABLE_STATE, Arrays.asList("setTableStateInMeta")); put(BYPASS, Arrays.asList("bypassProcedure")); put(SCHEDULE_RECOVERIES, Arrays.asList("scheduleServerCrashProcedure", - "scheduleServerCrashProcedures")); }}); + "scheduleServerCrashProcedures")); + put(RECOVER_UNKNOWN, Arrays.asList("scheduleSCPsForUnknownServers")); + }}); private static final String ADD_MISSING_REGIONS_IN_META_FOR_TABLES = "addFsRegionsMissingInMeta"; @@ -384,6 +387,10 @@ List scheduleRecoveries(Hbck hbck, String[] args) throws IOException { return hbck.scheduleServerCrashProcedure(serverNames); } + List recoverUnknown(Hbck hbck) throws IOException { + return hbck.scheduleSCPsForUnknownServers(); + } + private HBaseProtos.ServerName parseServerName(String serverName) { ServerName sn = ServerName.parseServerName(serverName); return HBaseProtos.ServerName.newBuilder().setHostName(sn.getHostname()). @@ -430,6 +437,8 @@ private static String getCommandUsage() { writer.println(); usageScheduleRecoveries(writer); writer.println(); + usageRecoverUnknown(writer); + writer.println(); usageUnassigns(writer); writer.println(); writer.close(); @@ -659,6 +668,16 @@ private static void usageScheduleRecoveries(PrintWriter writer) { writer.println(" Command support added in hbase versions 2.0.3, 2.1.2, 2.2.0 or newer."); } + private static void usageRecoverUnknown(PrintWriter writer) { + writer.println(" " + RECOVER_UNKNOWN); + writer.println(" Schedule ServerCrashProcedure(SCP) for RegionServers that are reported"); + writer.println(" as unknown."); + writer.println(" Returns the pid(s) of the created ServerCrashProcedure(s) or -1 if"); + writer.println(" no procedure created (see master logs for why not)."); + writer.println(" Command support added in hbase versions 2.2.7, 2.3.5, 2.4.3,"); + writer.println(" 2.5.0 or newer."); + } + private static void usageUnassigns(PrintWriter writer) { writer.println(" " + UNASSIGNS + " ..."); writer.println(" Options:"); @@ -894,6 +913,17 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc } break; + case RECOVER_UNKNOWN: + if (commands.length > 1) { + showErrorMessage(command + " doesn't take any arguments"); + return EXIT_FAILURE; + } + try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) { + checkFunctionSupported(connection, command); + System.out.println(toString(recoverUnknown(hbck))); + } + break; + case FIX_META: if (commands.length > 1) { showErrorMessage(command + " doesn't take any arguments"); diff --git a/hbase-hbck2/src/test/java/org/apache/hbase/TestRecoverUnknown.java b/hbase-hbck2/src/test/java/org/apache/hbase/TestRecoverUnknown.java new file mode 100644 index 0000000000..debfba1dcf --- /dev/null +++ b/hbase-hbck2/src/test/java/org/apache/hbase/TestRecoverUnknown.java @@ -0,0 +1,66 @@ +/* + * 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.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.List; + +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.client.ClusterConnection; +import org.apache.hadoop.hbase.client.Hbck; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + + +public class TestRecoverUnknown { + private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); + private HBCK2 hbck2; + + @Rule + public TestName name = new TestName(); + + @BeforeClass + public static void beforeClass() throws Exception { + TEST_UTIL.startMiniCluster(2); + } + + @AfterClass + public static void afterClass() throws Exception { + TEST_UTIL.shutdownMiniCluster(); + } + + @Before + public void before() { + this.hbck2 = new HBCK2(TEST_UTIL.getConfiguration()); + } + + @Test + public void testKnownServersNotRecovered() throws IOException { + try (ClusterConnection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) { + List pids = this.hbck2.recoverUnknown(hbck); + assertEquals(0, pids.size()); + } + } + +} diff --git a/pom.xml b/pom.xml index 3b5a64b659..529c828018 100644 --- a/pom.xml +++ b/pom.xml @@ -128,7 +128,7 @@ 1.8 ${compileSource} 3.3.3 - 2.1.6 + 2.2.7 surefire-junit47 true 8.18