Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";
Expand Down Expand Up @@ -384,6 +387,10 @@ List<Long> scheduleRecoveries(Hbck hbck, String[] args) throws IOException {
return hbck.scheduleServerCrashProcedure(serverNames);
}

List<Long> 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()).
Expand Down Expand Up @@ -430,6 +437,8 @@ private static String getCommandUsage() {
writer.println();
usageScheduleRecoveries(writer);
writer.println();
usageRecoverUnknown(writer);
writer.println();
usageUnassigns(writer);
writer.println();
writer.close();
Expand Down Expand Up @@ -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 + " <ENCODED_REGIONNAME>...");
writer.println(" Options:");
Expand Down Expand Up @@ -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");
Expand Down
66 changes: 66 additions & 0 deletions hbase-hbck2/src/test/java/org/apache/hbase/TestRecoverUnknown.java
Original file line number Diff line number Diff line change
@@ -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<Long> pids = this.hbck2.recoverUnknown(hbck);
assertEquals(0, pids.size());
}
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<compileSource>1.8</compileSource>
<java.min.version>${compileSource}</java.min.version>
<maven.min.version>3.3.3</maven.min.version>
<hbase.version>2.1.6</hbase.version>
<hbase.version>2.2.7</hbase.version>
<surefire.provider>surefire-junit47</surefire.provider>
<test.output.tofile>true</test.output.tofile>
<checkstyle.version>8.18</checkstyle.version>
Expand Down