You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by hu...@apache.org on 2020/06/09 22:19:43 UTC

[hbase-operator-tools] branch revert-62-HBASE-23927-no-format created (now 108e770)

This is an automated email from the ASF dual-hosted git repository.

huaxiangsun pushed a change to branch revert-62-HBASE-23927-no-format
in repository https://gitbox.apache.org/repos/asf/hbase-operator-tools.git.


      at 108e770  Revert "HBCK takes one or more files for assigns (#62)"

This branch includes the following new commits:

     new 108e770  Revert "HBCK takes one or more files for assigns (#62)"

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[hbase-operator-tools] 01/01: Revert "HBCK takes one or more files for assigns (#62)"

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

huaxiangsun pushed a commit to branch revert-62-HBASE-23927-no-format
in repository https://gitbox.apache.org/repos/asf/hbase-operator-tools.git

commit 108e770f6cfbad0f779b6671d4190adcf35db70a
Author: huaxiangsun <hu...@apache.org>
AuthorDate: Tue Jun 9 15:19:37 2020 -0700

    Revert "HBCK takes one or more files for assigns (#62)"
    
    This reverts commit aab25033ea6657a990b73bbc06ffe949c4a6282d.
---
 hbase-hbck2/README.md                              |  9 +--
 .../src/main/java/org/apache/hbase/HBCK2.java      | 41 ++---------
 .../src/test/java/org/apache/hbase/TestHBCK2.java  | 80 +++++++---------------
 3 files changed, 30 insertions(+), 100 deletions(-)

diff --git a/hbase-hbck2/README.md b/hbase-hbck2/README.md
index e7c01ff..39f3711 100644
--- a/hbase-hbck2/README.md
+++ b/hbase-hbck2/README.md
@@ -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
diff --git a/hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java b/hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java
index f1bd441..46de2ec 100644
--- a/hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java
+++ b/hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java
@@ -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 @@ public class HBCK2 extends Configured implements org.apache.hadoop.util.Tool {
     }
   }
 
-  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 @@ public class HBCK2 extends Configured implements org.apache.hadoop.util.Tool {
       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,10 +441,9 @@ public class HBCK2 extends Configured implements org.apache.hadoop.util.Tool {
   }
 
   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");
@@ -481,9 +451,6 @@ public class HBCK2 extends Configured implements org.apache.hadoop.util.Tool {
     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) {
diff --git a/hbase-hbck2/src/test/java/org/apache/hbase/TestHBCK2.java b/hbase-hbck2/src/test/java/org/apache/hbase/TestHBCK2.java
index 5fe084f..51bc7bc 100644
--- a/hbase-hbck2/src/test/java/org/apache/hbase/TestHBCK2.java
+++ b/hbase-hbck2/src/test/java/org/apache/hbase/TestHBCK2.java
@@ -22,15 +22,12 @@ import static org.junit.Assert.assertFalse;
 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 class TestHBCK2 {
             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 class TestHBCK2 {
     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 class TestHBCK2 {
   }
 
   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;