wchevreuil commented on a change in pull request #45: HBASE-23371 [HBCK2]
Provide client side method for removing ghost regions in meta.
URL:
https://github.com/apache/hbase-operator-tools/pull/45#discussion_r370142574
##########
File path: hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java
##########
@@ -191,76 +189,63 @@ int setRegionState(ClusterConnection connection, String
region,
return report;
}
- List<String> addMissingRegionsInMeta(List<Path> regionsPath) throws
IOException {
- List<String> reAddedRegionsEncodedNames = new ArrayList<>();
+ Map<TableName, List<String>> extraRegionsInMeta(String[] args)
+ throws Exception {
+ Options options = new Options();
+ Option fixOption = Option.builder("f").longOpt("fix").build();
+ options.addOption(fixOption);
+ // Parse command-line.
+ CommandLineParser parser = new DefaultParser();
+ CommandLine commandLine;
+ commandLine = parser.parse(options, args, false);
+ boolean fix = commandLine.hasOption(fixOption.getOpt());
+ Map<TableName, List<String>> result = new HashMap<>();
try (final FsRegionsMetaRecoverer fsRegionsMetaRecoverer =
- new FsRegionsMetaRecoverer(this.conf)) {
- for(Path regionPath : regionsPath){
- fsRegionsMetaRecoverer.putRegionInfoFromHdfsInMeta(regionPath);
- reAddedRegionsEncodedNames.add(regionPath.getName());
+ new FsRegionsMetaRecoverer(this.conf)) {
+ List<String> namespacesTables =
formatNameSpaceTableParam(commandLine.getArgs());
+ Map<TableName, List<RegionInfo>> reportMap =
+ fsRegionsMetaRecoverer.reportTablesExtraRegions(namespacesTables);
+ final List<String> toFix = new ArrayList<>();
+ reportMap.entrySet().forEach( e -> {
+ result.put(e.getKey(),
+
e.getValue().stream().map(r->r.getEncodedName()).collect(Collectors.toList()));
+ if(fix && e.getValue().size()>0){
+ toFix.add(e.getKey().getNameWithNamespaceInclAsString());
+ }
+ });
+ if(fix) {
+ Pair<List<String>, List<ExecutionException>> removeResult =
+ fsRegionsMetaRecoverer.removeExtraRegionsFromMetaForTables(toFix);
+ if(removeResult!=null) {
+
System.out.println(formatRemovedRegionsMessage(removeResult.getFirst(),
+ removeResult.getSecond()));
+ }
}
+ } catch (IOException e) {
+ LOG.error("Error on checking extra regions: ", e);
+ throw e;
}
- return reAddedRegionsEncodedNames;
+ if(LOG.isDebugEnabled()) {
+ LOG.debug(formatExtraRegionsReport(result));
+ }
+ return result;
+ }
+
+ private List<String> formatNameSpaceTableParam(String... nameSpaceOrTable) {
+ return nameSpaceOrTable != null ? Arrays.asList(nameSpaceOrTable) : null;
}
Pair<List<String>, List<ExecutionException>>
addMissingRegionsInMetaForTables(String...
nameSpaceOrTable) throws IOException {
- ExecutorService executorService = Executors.newFixedThreadPool(
- (nameSpaceOrTable == null ||
- nameSpaceOrTable.length > Runtime.getRuntime().availableProcessors()) ?
- Runtime.getRuntime().availableProcessors() :
- nameSpaceOrTable.length);
- List<Future<List<String>>> futures =
- new ArrayList<>(nameSpaceOrTable == null ? 1 :
nameSpaceOrTable.length);
- final List<String> readdedRegionNames = new ArrayList<>();
- List<ExecutionException> executionErrors = new ArrayList<>();
- try {
- //reducing number of retries in case disable fails due to namespace
table region also missing
- this.conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
- try(ClusterConnection conn = connect();
- final Admin admin = conn.getAdmin()) {
- Map<TableName,List<Path>> report =
reportTablesWithMissingRegionsInMeta(nameSpaceOrTable);
- if(report.size() < 1) {
- LOG.info("\nNo missing regions in meta are found. Worth using " +
- "reportMissingRegionsInMeta first.\nYou are likely passing
non-existent " +
- "namespace or table. Note that table names should include
the namespace " +
- "portion even for tables in the default namespace. " +
- "See also the command usage.\n");
- }
- for (TableName tableName : report.keySet()) {
- if(admin.tableExists(tableName)) {
- futures.add(executorService.submit(new Callable<List<String>>() {
- @Override
- public List<String> call() throws Exception {
- LOG.debug("running thread for {}",
tableName.getNameWithNamespaceInclAsString());
- return addMissingRegionsInMeta(report.get(tableName));
- }
- }));
- } else {
- LOG.warn("Table {} does not exist! Skipping...",
- tableName.getNameWithNamespaceInclAsString());
- }
- }
- for(Future<List<String>> f : futures){
- try {
- readdedRegionNames.addAll(f.get());
- } catch (ExecutionException e){
- //we want to allow potential running threads to finish, so we
collect execution
- //errors and show those later
- LOG.debug("Caught execution error: ", e);
- executionErrors.add(e);
- }
- }
- }
- } catch (IOException | InterruptedException e) {
- LOG.error("ERROR executing thread: ", e);
- throw new IOException(e);
- } finally {
- executorService.shutdown();
- }
Pair<List<String>, List<ExecutionException>> result = new Pair<>();
- result.setFirst(readdedRegionNames);
- result.setSecond(executionErrors);
+ try (final FsRegionsMetaRecoverer fsRegionsMetaRecoverer =
+ new FsRegionsMetaRecoverer(this.conf)) {
+ result = fsRegionsMetaRecoverer.addMissingRegionsInMetaForTables(
+ formatNameSpaceTableParam(nameSpaceOrTable));
+ } catch (IOException e) {
+ LOG.error("Error adding missing regions: ", e);
Review comment:
We don't have how to know for which of the passed namespace or table we are
really erroring here, so ain't sure adding the list of all passed
namespaces/tables would add much value here.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services