in hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java [999:1198]
private int doCommandLine(CommandLine commandLine, Options options) throws IOException {
// Now process command.
String[] commands = commandLine.getArgs();
String command = commands[0];
switch (command) {
// Case handlers all have same format. Check first that the server supports
// the feature FIRST, then move to process the command.
case SET_TABLE_STATE:
if (commands.length < 2) {
showErrorMessage(command +
" takes tablename and state arguments: e.g. user ENABLED, or a list of input files");
return EXIT_FAILURE;
}
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
checkFunctionSupported(connection, command);
setTableState(hbck, purgeFirst(commands));
}
break;
case ASSIGNS:
if (commands.length < 2) {
showErrorMessage(command + " takes one or more encoded region names");
return EXIT_FAILURE;
}
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
checkFunctionSupported(connection, command);
System.out.println(assigns(hbck, purgeFirst(commands)));
}
break;
case BYPASS:
if (commands.length < 2) {
showErrorMessage(command + " takes one or more pids");
return EXIT_FAILURE;
}
// bypass does the connection setup and the checkFunctionSupported down
// inside in the bypass method delaying connection setup until last
// moment. It does this because it has another set of command options
// to process and wants to do that before setting up connection.
// This is why it is not like the other command processings.
List<Boolean> bs = bypass(purgeFirst(commands));
if (bs == null) {
// Something went wrong w/ the parse and command didn't run.
return EXIT_FAILURE;
}
System.out.println(toString(bs));
break;
case UNASSIGNS:
if (commands.length < 2) {
showErrorMessage(command + " takes one or more encoded region names");
return EXIT_FAILURE;
}
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
checkFunctionSupported(connection, command);
System.out.println(toString(unassigns(hbck, purgeFirst(commands))));
}
break;
case SET_REGION_STATE:
if (commands.length < 2) {
showErrorMessage(command + " takes region encoded name and state arguments: e.g. "
+ "35f30b0ce922c34bf5c284eff33ba8b3 CLOSING, or a list of input files");
return EXIT_FAILURE;
}
try (ClusterConnection connection = connect()) {
checkHBCKSupport(connection, command);
return setRegionState(connection, purgeFirst(commands));
}
case FILESYSTEM:
try (ClusterConnection connection = connect()) {
checkHBCKSupport(connection, command);
try (FileSystemFsck fsfsck = new FileSystemFsck(getConf())) {
Pair<CommandLine, List<String>> pair =
parseCommandWithFixAndInputOptions(purgeFirst(commands));
return fsfsck.fsck(pair.getSecond(),
pair.getFirst().hasOption("f"))!= 0? EXIT_FAILURE : EXIT_SUCCESS;
}
}
case REPLICATION:
try (ClusterConnection connection = connect()) {
checkHBCKSupport(connection, command, "2.1.1", "2.2.0", "3.0.0");
try (ReplicationFsck replicationFsck = new ReplicationFsck(getConf())) {
Pair<CommandLine, List<String>> pair =
parseCommandWithFixAndInputOptions(purgeFirst(commands));
return replicationFsck.fsck(pair.getSecond(),
pair.getFirst().hasOption("f")) != 0? EXIT_FAILURE : EXIT_SUCCESS;
}
}
case SCHEDULE_RECOVERIES:
if (commands.length < 2) {
showErrorMessage(command + " takes one or more serverNames");
return EXIT_FAILURE;
}
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
checkFunctionSupported(connection, command);
System.out.println(toString(scheduleRecoveries(hbck, purgeFirst(commands))));
}
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");
return EXIT_FAILURE;
}
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
checkFunctionSupported(connection, command);
hbck.fixMeta();
System.out.println("Server-side processing of fixMeta triggered.");
}
break;
case ADD_MISSING_REGIONS_IN_META_FOR_TABLES:
if(commands.length < 2){
showErrorMessage(command + " takes one or more table names.");
return EXIT_FAILURE;
}
List<Future<List<String>>> addedRegions =
addMissingRegionsInMetaForTables(purgeFirst(commands));
List<String> regionNames = new ArrayList<>();
List<Exception> errors = new ArrayList<>();
for(Future<List<String>> f : addedRegions){
try {
regionNames.addAll(f.get());
} catch (InterruptedException | ExecutionException e) {
errors.add(e);
}
}
System.out.println(formatReAddedRegionsMessage(regionNames,
errors));
break;
case REPORT_MISSING_REGIONS_IN_META:
try {
Map<TableName,List<Path>> report =
reportTablesWithMissingRegionsInMeta(purgeFirst(commands));
System.out.println(formatMissingRegionsInMetaReport(report));
} catch (Exception e) {
return EXIT_FAILURE;
}
break;
case EXTRA_REGIONS_IN_META:
try {
Map<TableName,List<String>> report =
extraRegionsInMeta(purgeFirst(commands));
System.out.println(formatExtraRegionsReport(report));
} catch (Exception e) {
return EXIT_FAILURE;
}
break;
case GENERATE_TABLE_INFO:
List<String> tableNames = Arrays.asList(purgeFirst(commands));
MissingTableDescriptorGenerator tableInfoGenerator =
new MissingTableDescriptorGenerator(getConf());
try (ClusterConnection connection = connect()) {
tableInfoGenerator
.generateTableDescriptorFileIfMissing(connection.getAdmin(), tableNames);
} catch (IOException e) {
showErrorMessage(e.getMessage());
return EXIT_FAILURE;
}
break;
case REGIONINFO_MISMATCH:
// `commands` includes the `regionInfoMismatch` argument.
if (commands.length > 2) {
showErrorMessage(command + " takes one optional argument, got more than one.");
return EXIT_FAILURE;
}
try {
regionInfoMismatch(commands);
} catch (Exception e) {
e.printStackTrace();
return EXIT_FAILURE;
}
break;
default:
showErrorMessage("Unsupported command: " + command);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}