ankitsinghal commented on a change in pull request #18: HBASE-22567 - HBCK2
addMissingRegionsToMeta
URL:
https://github.com/apache/hbase-operator-tools/pull/18#discussion_r320041432
##########
File path: hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java
##########
@@ -161,6 +177,130 @@ int setRegionState(ClusterConnection connection, String
region,
return EXIT_FAILURE;
}
+ Map<TableName,List<Path>> reportTablesWithMissingRegionsInMeta(String...
nameSpaceOrTable)
+ throws IOException {
+ Map<TableName,List<Path>> report;
+ try(final MetaFixer metaFixer = new MetaFixer(this.conf)){
+ List<String> names = nameSpaceOrTable != null ?
Arrays.asList(nameSpaceOrTable) : null;
+ report = metaFixer.reportTablesMissingRegions(names);
+ } catch (IOException e) {
+ LOG.error("Error reporting missing regions: ", e);
+ throw e;
+ }
+ if(LOG.isDebugEnabled()) {
+ LOG.debug(formatMissingRegionsInMetaReport(report));
+ }
+ return report;
+ }
+
+ List<String> addMissingRegionsInMeta(List<Path> regionsPath) throws
IOException {
+ List<String> reAddedRegionsEncodedNames = new ArrayList<>();
+ try(final MetaFixer metaFixer = new MetaFixer(this.conf)){
+ for(Path regionPath : regionsPath){
+ metaFixer.putRegionInfoFromHdfsInMeta(regionPath);
+ reAddedRegionsEncodedNames.add(regionPath.getName());
+ }
+ }
+ return reAddedRegionsEncodedNames;
+ }
+
+ Pair<List<String>, List<ExecutionException>>
addMissingRegionsInMetaForTables(String...
+ nameSpaceOrTable) throws IOException {
+ //TODO next block logic for parsing optional parameters can be moved to
util method for reuse
+ Options options = new Options();
+ Option disable = Option.builder("d").longOpt("force_disable").build();
+ options.addOption(disable);
+ // Parse command-line.
+ CommandLineParser parser = new DefaultParser();
+ CommandLine commandLine;
+ try {
+ commandLine = parser.parse(options, nameSpaceOrTable, false);
+ } catch (ParseException e) {
+ showErrorMessage(e.getMessage());
+ return null;
+ }
+ boolean enforceDisable = commandLine.hasOption(disable.getOpt());
+ 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);
+ 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());
+ boolean didDisable = false;
+ try {
+ admin.disableTable(tableName);
+ didDisable = true;
+ } catch (IOException e) {
Review comment:
Is it possible that table is already disabled and we get this exception? If
yes can we add a check before disabling it or handle it 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