wchevreuil commented on a change in pull request #3: Hbase 22567
URL: https://github.com/apache/hbase-operator-tools/pull/3#discussion_r300072302
 
 

 ##########
 File path: hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java
 ##########
 @@ -164,6 +177,128 @@ int setRegionState(String region, RegionState.State 
newState)
     return EXIT_FAILURE;
   }
 
+  Map<String,List<Path>> reportTablesWithMissingRegionsInMeta(String... 
nameSpaceOrTable)
+      throws Exception {
+    final StringBuilder builder = new StringBuilder();
+    Map<String,List<Path>> report;
+    try(final MetaFixer metaFixer = new MetaFixer(this.conf)){
+      List<String> names = nameSpaceOrTable != null ? 
Arrays.asList(nameSpaceOrTable) : null;
+      report = metaFixer.reportTablesMissingRegions(names);
+      builder.append("Missing Regions for each table:\n\t");
+      report.keySet().stream().forEach(table -> {
+        builder.append(table);
+        if (report.get(table).size()>0){
+          builder.append("->\n\t\t");
+          report.get(table).stream().forEach(region -> 
builder.append(region.getName())
+            .append(" "));
+        } else {
+          builder.append(" -> No missing regions");
+        }
+        builder.append("\n\t");
+      });
+    } catch (Exception e) {
+      LOG.error("Error reporting missing regions: ", e);
+      throw e;
+    }
+    System.out.println(builder);
+    return report;
+  }
+
+  List<String> addMissingRegionsInMeta(List<Path> regionsPath) throws 
IOException {
+    List<String> reAddedRegions = new ArrayList<>();
+    try(final MetaFixer metaFixer = new MetaFixer(this.conf)){
+      for(Path regionPath : regionsPath){
+        metaFixer.putRegionInfoFromHdfsInMeta(regionPath);
+        reAddedRegions.add(regionPath.getName());
+      }
+    }
+    return reAddedRegions;
+  }
+
+  int addMissingRegionsInMetaForTables(String... nameSpaceOrTable) throws 
IOException {
+    ExecutorService executorService = Executors.newFixedThreadPool(
+      nameSpaceOrTable.length > Runtime.getRuntime().availableProcessors() ?
+        Runtime.getRuntime().availableProcessors() : nameSpaceOrTable.length);
+    List<Future<List<String>>> futures = new 
ArrayList<>(nameSpaceOrTable.length);
+    final List<String> encodedRegionNames = new ArrayList<>();
+    List<ExecutionException> executionErrors = new ArrayList<>();
+    String resultText = "No regions added.";
+    int result = EXIT_SUCCESS;
+    try(final MetaFixer metaFixer = new MetaFixer(this.conf)){
+      //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<String,List<Path>> report = 
this.reportTablesWithMissingRegionsInMeta(nameSpaceOrTable);
+        for (String table : report.keySet()) {
+          final TableName tableName = TableName.valueOf(table);
+          if(admin.tableExists(tableName)) {
+            futures.add(executorService.submit(new Callable<List<String>>() {
+              @Override
+              public List<String> call() throws Exception {
+                LOG.debug("running thread for {}", table);
+                try {
+                  admin.disableTable(tableName);
+                } catch (IOException e) {
+                  LOG.debug("Failed to disable table {}, "
+                      + "is namespace table also missing regions? Continue 
anyway...", table, e);
 
 Review comment:
   > But I suppose if the disable fails and we just keep going, that is 
probably ok? What does it say when disable fails?
   
   There are some scenarios where disable will fail for sure, but we still 
should proceed, for instance, when namespace table is also affected (and on the 
cases we faced so far, this was happening). Earlier versions of this command we 
used with some customers was just printing the exception, then continuing, but 
it was confusing operators, leading them to think the program had actually 
failed, when it had not. So, I had decided to leave it as debugging log.
   
   > If this program dies in the middle of running, will we be able to rerun?
   
   It doesn't really rely on any state, so if a given run listed, say 100 
missing regions, then went re-adding those and crashed after re-inserting 50 
regions, next run would simply list the remaining 50 and iterate through those. 
I guess this would be a good test case scenario, let me add it to my backlog of 
work to be done after the most trivial ones.

----------------------------------------------------------------
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

Reply via email to