Skip to content
Permalink
Browse files
Revert "HBCK takes one or more files for assigns (#62)" (#63)
This reverts commit aab2503.
  • Loading branch information
huaxiangsun committed Jun 9, 2020
1 parent aab2503 commit dd206ffdbdfa78bae3dfcc5753b8aeaea1bceb29
Showing 3 changed files with 30 additions and 100 deletions.
@@ -124,20 +124,17 @@ Command:
SEE ALSO: reportMissingRegionsInMeta
SEE ALSO: fixMeta
assigns [OPTIONS] <ENCODED_REGIONNAME/INPUTFILES_FOR_REGIONNAMES>...
assigns [OPTIONS] <ENCODED_REGIONNAME>...
Options:
-o,--override override ownership by another procedure
-i,--inputFiles take one or more encoded region names
A 'raw' assign that can be used even during Master initialization (if
the -skip flag is specified). Skirts Coprocessors. Pass one or more
encoded region names. 1588230740 is the hard-coded name for the
hbase:meta region and de00010733901a05f5a2a3a382e27dd4 is an example of
what a user-space encoded region name looks like. For example:
$ HBCK2 assigns 1588230740 de00010733901a05f5a2a3a382e27dd4
$ HBCK2 assign 1588230740 de00010733901a05f5a2a3a382e27dd4
Returns the pid(s) of the created AssignProcedure(s) or -1 if none.
If -i or --inputFiles is specified, pass one or more input file names.
Each file contains encoded region names, one per line. For example:
$ HBCK2 assigns -i fileName1 fileName2
bypass [OPTIONS] <PID>...
Options:
-o,--override override if procedure is running/stuck
@@ -17,9 +17,6 @@
*/
package org.apache.hbase;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
@@ -90,6 +87,7 @@ public class HBCK2 extends Configured implements org.apache.hadoop.util.Tool {
static final int EXIT_FAILURE = 1;
// Commands
private static final String SET_TABLE_STATE = "setTableState";
private static final String ASSIGNS = "assigns";
private static final String UNASSIGNS = "unassigns";
private static final String BYPASS = "bypass";
private static final String FILESYSTEM = "filesystem";
@@ -111,10 +109,7 @@ public class HBCK2 extends Configured implements org.apache.hadoop.util.Tool {
private static final String ADD_MISSING_REGIONS_IN_META_FOR_TABLES =
"addFsRegionsMissingInMeta";
private static final String REPORT_MISSING_REGIONS_IN_META = "reportMissingRegionsInMeta";

static final String EXTRA_REGIONS_IN_META = "extraRegionsInMeta";
static final String ASSIGNS = "assigns";

private Configuration conf;
static final String [] MINIMUM_HBCK2_VERSION = {"2.0.3", "2.1.1", "2.2.0", "3.0.0"};
private boolean skipCheck = false;
@@ -285,12 +280,10 @@ List<Future<List<String>>> addMissingRegionsInMetaForTables(String...
}
}

List<Long> assigns(Hbck hbck, String[] args) throws IOException {
List<Long> assigns(Hbck hbck, String [] args) throws IOException {
Options options = new Options();
Option override = Option.builder("o").longOpt("override").build();
Option inputFile = Option.builder("i").longOpt("inputFiles").build();
options.addOption(override);
options.addOption(inputFile);
// Parse command-line.
CommandLineParser parser = new DefaultParser();
CommandLine commandLine;
@@ -301,29 +294,7 @@ List<Long> assigns(Hbck hbck, String[] args) throws IOException {
return null;
}
boolean overrideFlag = commandLine.hasOption(override.getOpt());

List<String> argList = commandLine.getArgList();
if (!commandLine.hasOption(inputFile.getOpt())) {
return hbck.assigns(argList, overrideFlag);
} else {
List<String> assignmentList = new ArrayList<>();
for (String filePath : argList) {
try {
File file = new File(filePath);
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String regionName;
while ((regionName = bufferedReader.readLine()) != null) {
assignmentList.add(regionName.trim());
}
fileReader.close();
} catch (IOException e) {
LOG.error("Error on input file: ", filePath);
throw e;
}
}
return hbck.assigns(assignmentList, overrideFlag);
}
return hbck.assigns(commandLine.getArgList(), overrideFlag);
}

List<Long> unassigns(Hbck hbck, String [] args) throws IOException {
@@ -470,20 +441,16 @@ private static void usageAddFsRegionsMissingInMeta(PrintWriter writer) {
}

private static void usageAssigns(PrintWriter writer) {
writer.println(" " + ASSIGNS + " [OPTIONS] <ENCODED_REGIONNAME/INPUTFILES_FOR_REGIONNAMES>...");
writer.println(" " + ASSIGNS + " [OPTIONS] <ENCODED_REGIONNAME>...");
writer.println(" Options:");
writer.println(" -o,--override override ownership by another procedure");
writer.println(" -i,--inputFiles take one or more files of encoded region names");
writer.println(" A 'raw' assign that can be used even during Master initialization (if");
writer.println(" the -skip flag is specified). Skirts Coprocessors. Pass one or more");
writer.println(" encoded region names. 1588230740 is the hard-coded name for the");
writer.println(" hbase:meta region and de00010733901a05f5a2a3a382e27dd4 is an example of");
writer.println(" what a user-space encoded region name looks like. For example:");
writer.println(" $ HBCK2 assigns 1588230740 de00010733901a05f5a2a3a382e27dd4");
writer.println(" Returns the pid(s) of the created AssignProcedure(s) or -1 if none.");
writer.println(" If -i or --inputFiles is specified, pass one or more input file names.");
writer.println(" Each file contains encoded region names, one per line. For example:");
writer.println(" $ HBCK2 assigns -i fileName1 fileName2");
}

private static void usageBypass(PrintWriter writer) {
@@ -22,15 +22,12 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
@@ -130,40 +127,32 @@ public void testAssigns() throws IOException {
getRegionStates().getRegionState(ri.getEncodedName());
LOG.info("RS: {}", rs.toString());
}
String [] regionStrsArray =
regions.stream().map(RegionInfo::getEncodedName).collect(Collectors.toList())
.toArray(new String[] {});

List<String> regionStrs =
regions.stream().map(RegionInfo::getEncodedName).collect(Collectors.toList());
String [] regionStrsArray = regionStrs.toArray(new String[] {});
try (ClusterConnection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
unassigns(regions, regionStrsArray);
List<Long> pids = this.hbck2.assigns(hbck, regionStrsArray);
List<Long> pids = this.hbck2.unassigns(hbck, regionStrsArray);
waitOnPids(pids);
for (RegionInfo ri : regions) {
RegionState rs = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager().
getRegionStates().getRegionState(ri.getEncodedName());
LOG.info("RS: {}", rs.toString());
assertTrue(rs.toString(), rs.isClosed());
}
pids = this.hbck2.assigns(hbck, regionStrsArray);
waitOnPids(pids);
validateOpen(regions);
for (RegionInfo ri : regions) {
RegionState rs = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager().
getRegionStates().getRegionState(ri.getEncodedName());
LOG.info("RS: {}", rs.toString());
assertTrue(rs.toString(), rs.isOpened());
}
// What happens if crappy region list passed?
pids = this.hbck2.assigns(hbck, Arrays.stream(new String[]{"a", "some rubbish name"}).
collect(Collectors.toList()).toArray(new String[]{}));
collect(Collectors.toList()).toArray(new String[]{}));
for (long pid : pids) {
assertEquals(org.apache.hadoop.hbase.procedure2.Procedure.NO_PROC_ID, pid);
}

// test input files
unassigns(regions, regionStrsArray);
String testFile = "inputForAssignsTest";
FileOutputStream output = new FileOutputStream(testFile, false);
for (String regionStr : regionStrsArray) {
output.write((regionStr + System.lineSeparator()).getBytes());
}
output.close();
String result = testRunWithArgs(new String[] {HBCK2.ASSIGNS, "-i", testFile});
Scanner scanner = new Scanner(result).useDelimiter("[\\D]+");
pids = new ArrayList<>();
while (scanner.hasNext()) {
pids.add(scanner.nextLong());
}
scanner.close();
//pids = this.hbck2.assigns(hbck, new String[] {"-i", testFile});
waitOnPids(pids);
validateOpen(regions);
}
}
}
@@ -277,29 +266,6 @@ public void testFormatReportMissingInMetaOneMissing() throws IOException {
assertTrue(result.contains(expectedResult));
}

private void unassigns(List<RegionInfo> regions, String[] regionStrsArray) throws IOException {
try (ClusterConnection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
List<Long> pids = this.hbck2.unassigns(hbck, regionStrsArray);
waitOnPids(pids);
}
for (RegionInfo ri : regions) {
RegionState rs = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager().
getRegionStates().getRegionState(ri.getEncodedName());
LOG.info("RS: {}", rs.toString());
assertTrue(rs.toString(), rs.isClosed());
}
}


private void validateOpen(List<RegionInfo> regions) {
for (RegionInfo ri : regions) {
RegionState rs = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager().
getRegionStates().getRegionState(ri.getEncodedName());
LOG.info("RS: {}", rs.toString());
assertTrue(rs.toString(), rs.isOpened());
}
}

private String testFormatMissingRegionsInMetaReport()
throws IOException {
HBCK2 hbck = new HBCK2(TEST_UTIL.getConfiguration());
@@ -553,18 +519,18 @@ public void testFunctionNotSupported() throws IOException {
}

private String testFormatExtraRegionsInMetaReport() throws IOException {
return testRunWithArgs(new String[]{HBCK2.EXTRA_REGIONS_IN_META });
return testFormatExtraRegionsInMeta(new String[]{HBCK2.EXTRA_REGIONS_IN_META });
}

private String testFormatExtraRegionsInMetaFix(String table) throws IOException {
if(table!=null) {
return testRunWithArgs(new String[] {HBCK2.EXTRA_REGIONS_IN_META, "-f", table});
return testFormatExtraRegionsInMeta(new String[] {HBCK2.EXTRA_REGIONS_IN_META, "-f", table});
} else {
return testRunWithArgs(new String[] {HBCK2.EXTRA_REGIONS_IN_META, "-f"});
return testFormatExtraRegionsInMeta(new String[] {HBCK2.EXTRA_REGIONS_IN_META, "-f"});
}
}

private String testRunWithArgs(String[] args) throws IOException {
private String testFormatExtraRegionsInMeta(String[] args) throws IOException {
HBCK2 hbck = new HBCK2(TEST_UTIL.getConfiguration());
final StringBuilder builder = new StringBuilder();
PrintStream originalOS = System.out;

0 comments on commit dd206ff

Please sign in to comment.