wchevreuil commented on a change in pull request #18: HBASE-22567 - HBCK2
addMissingRegionsToMeta
URL:
https://github.com/apache/hbase-operator-tools/pull/18#discussion_r319950621
##########
File path: hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java
##########
@@ -164,6 +178,102 @@ int setRegionState(String region, RegionState.State
newState)
return EXIT_FAILURE;
}
+ Map<TableName,List<Path>> reportTablesWithMissingRegionsInMeta(String...
nameSpaceOrTable)
+ throws Exception {
+ 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 (Exception 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) {
+ 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(Connection conn = ConnectionFactory.createConnection(this.conf);
+ 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());
+ try {
+ admin.disableTable(tableName);
+ } catch (IOException e) {
+ LOG.debug("Failed to disable table {}, "
+ + "is namespace table also missing regions? Continue
anyway...",
+ tableName.getNameWithNamespaceInclAsString(), e);
+ }
+ List<String> reAddedRegions =
addMissingRegionsInMeta(report.get(tableName));
+ try {
+ admin.enableTable(tableName);
+ } catch (IOException e) {
+ LOG.debug("Failed enabling table {}. It might be that
namespace table "
+ + "region is also missing.\n"
+ + "After this command finishes, please make sure on this
table state.",
+ tableName.getNameWithNamespaceInclAsString(), e);
+ }
+ return reAddedRegions;
+ }
+ }));
+ } 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 (Exception ie){
+ LOG.error("ERROR executing thread: ", ie);
+ } finally {
+ executorService.shutdown();
Review comment:
I guess we only reach this point if all threads had finished and returned
the call for
[_f.get()_](https://github.com/wchevreuil/hbase-operator-tools/blob/HBASE-22567-rebased/hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java#L257)
or some other major error happened before we started spawn up threads for each
ns:tbl, so didn't think it should be a concern.
----------------------------------------------------------------
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