[GitHub] [hbase] saintstack commented on a change in pull request #975: HBASE-23624 Add a tool to dump the procedure info in HFile

2019-12-31 Thread GitBox
saintstack commented on a change in pull request #975: HBASE-23624 Add a tool 
to dump the procedure info in HFile
URL: https://github.com/apache/hbase/pull/975#discussion_r362264646
 
 

 ##
 File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/procedure2/store/region/RegionProcedureStore.java
 ##
 @@ -112,17 +112,15 @@
 
   static final String LOGCLEANER_PLUGINS = 
"hbase.procedure.store.region.logcleaner.plugins";
 
-  private static final String DATA_DIR = "data";
-
   private static final String REPLAY_EDITS_DIR = "replay";
 
 Review comment:
   Looking over at the MTTR HFile patch, it names the recovered hfile dir 
'recovered:hfiles' instead of 'recovered.edits'. This dir could be 
recovered.wals?


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [hbase] saintstack commented on a change in pull request #975: HBASE-23624 Add a tool to dump the procedure info in HFile

2019-12-31 Thread GitBox
saintstack commented on a change in pull request #975: HBASE-23624 Add a tool 
to dump the procedure info in HFile
URL: https://github.com/apache/hbase/pull/975#discussion_r362264285
 
 

 ##
 File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/procedure2/store/region/HFileProcedurePrettyPrinter.java
 ##
 @@ -0,0 +1,174 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.procedure2.store.region;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.UncheckedIOException;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellUtil;
+import org.apache.hadoop.hbase.HBaseInterfaceAudience;
+import org.apache.hadoop.hbase.PrivateCellUtil;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.io.hfile.CacheConfig;
+import org.apache.hadoop.hbase.io.hfile.HFile;
+import org.apache.hadoop.hbase.io.hfile.HFileScanner;
+import org.apache.hadoop.hbase.procedure2.Procedure;
+import org.apache.hadoop.hbase.procedure2.ProcedureUtil;
+import org.apache.hadoop.hbase.util.AbstractHBaseTool;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.CommonFSUtils;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.apache.yetus.audience.InterfaceStability;
+
+import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine;
+import org.apache.hbase.thirdparty.org.apache.commons.cli.Option;
+import org.apache.hbase.thirdparty.org.apache.commons.cli.OptionGroup;
+
+import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos;
+
+/**
+ * A tool to dump the procedures in the HFiles.
+ * 
+ * The different between this and {@link 
org.apache.hadoop.hbase.io.hfile.HFilePrettyPrinter} is
+ * that, this class will decode the procedure in the cell for better 
debugging. You are free to use
+ * {@link org.apache.hadoop.hbase.io.hfile.HFilePrettyPrinter} to dump the 
same file as well.
+ */
+@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS)
+@InterfaceStability.Evolving
+public class HFileProcedurePrettyPrinter extends AbstractHBaseTool {
+
+  private Long procId;
+
+  private List files = new ArrayList<>();
+
+  private final PrintStream out;
+
+  public HFileProcedurePrettyPrinter() {
+this(System.out);
+  }
+
+  public HFileProcedurePrettyPrinter(PrintStream out) {
+this.out = out;
+  }
+
+  @Override
+  protected void addOptions() {
+addOptWithArg("w", "seekToPid", "Seek to this procedure id and print this 
procedure only");
+OptionGroup files = new OptionGroup();
+files.addOption(new Option("f", "file", true,
+  "File to scan. Pass full-path; e.g. 
hdfs://a:9000/MasterProcs/master/procedure/p/xxx"));
+files.addOption(new Option("a", "all", false, "Scan the whole procedure 
region."));
+options.addOptionGroup(files);
+  }
+
+  private void addAllHFiles() throws IOException {
+Path masterProcDir =
+  new Path(CommonFSUtils.getWALRootDir(conf), 
RegionProcedureStore.MASTER_PROCEDURE_DIR);
+Path tableDir = CommonFSUtils.getTableDir(masterProcDir, 
RegionProcedureStore.TABLE_NAME);
+FileSystem fs = tableDir.getFileSystem(conf);
+Path regionDir =
+  fs.listStatus(tableDir, p -> 
RegionInfo.isEncodedRegionName(Bytes.toBytes(p.getName([0]
+.getPath();
+List regionFiles = HFile.getStoreFiles(fs, regionDir);
+files.addAll(regionFiles);
+  }
+
+  @Override
+  protected void processOptions(CommandLine cmd) {
+if (cmd.hasOption("w")) {
+  String key = cmd.getOptionValue("w");
+  if (key != null && key.length() != 0) {
+procId = Long.parseLong(key);
+  } else {
+throw new IllegalArgumentException("Invalid row is specified.");
+  }
+}
+if (cmd.hasOption("f")) {
+  files.add(new Path(cmd.getOptionValue("f")));
+}
+if (cmd.hasOption("a")) {
+  try {
+addAllHFiles();
+  } catch (IOException e) {
+throw new UncheckedIOException(e);
+  }
+}
+  }
+
+  private void printCell(Cell cell) throws IOException {
+

[GitHub] [hbase] saintstack commented on a change in pull request #975: HBASE-23624 Add a tool to dump the procedure info in HFile

2019-12-31 Thread GitBox
saintstack commented on a change in pull request #975: HBASE-23624 Add a tool 
to dump the procedure info in HFile
URL: https://github.com/apache/hbase/pull/975#discussion_r362263579
 
 

 ##
 File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/procedure2/store/region/HFileProcedurePrettyPrinter.java
 ##
 @@ -0,0 +1,174 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.procedure2.store.region;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.UncheckedIOException;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellUtil;
+import org.apache.hadoop.hbase.HBaseInterfaceAudience;
+import org.apache.hadoop.hbase.PrivateCellUtil;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.io.hfile.CacheConfig;
+import org.apache.hadoop.hbase.io.hfile.HFile;
+import org.apache.hadoop.hbase.io.hfile.HFileScanner;
+import org.apache.hadoop.hbase.procedure2.Procedure;
+import org.apache.hadoop.hbase.procedure2.ProcedureUtil;
+import org.apache.hadoop.hbase.util.AbstractHBaseTool;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.CommonFSUtils;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.apache.yetus.audience.InterfaceStability;
+
+import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine;
+import org.apache.hbase.thirdparty.org.apache.commons.cli.Option;
+import org.apache.hbase.thirdparty.org.apache.commons.cli.OptionGroup;
+
+import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos;
+
+/**
+ * A tool to dump the procedures in the HFiles.
+ * 
+ * The different between this and {@link 
org.apache.hadoop.hbase.io.hfile.HFilePrettyPrinter} is
+ * that, this class will decode the procedure in the cell for better 
debugging. You are free to use
+ * {@link org.apache.hadoop.hbase.io.hfile.HFilePrettyPrinter} to dump the 
same file as well.
 
 Review comment:
   Good


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [hbase] saintstack commented on a change in pull request #975: HBASE-23624 Add a tool to dump the procedure info in HFile

2019-12-31 Thread GitBox
saintstack commented on a change in pull request #975: HBASE-23624 Add a tool 
to dump the procedure info in HFile
URL: https://github.com/apache/hbase/pull/975#discussion_r362264026
 
 

 ##
 File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/procedure2/store/region/HFileProcedurePrettyPrinter.java
 ##
 @@ -0,0 +1,174 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.procedure2.store.region;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.UncheckedIOException;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellUtil;
+import org.apache.hadoop.hbase.HBaseInterfaceAudience;
+import org.apache.hadoop.hbase.PrivateCellUtil;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.io.hfile.CacheConfig;
+import org.apache.hadoop.hbase.io.hfile.HFile;
+import org.apache.hadoop.hbase.io.hfile.HFileScanner;
+import org.apache.hadoop.hbase.procedure2.Procedure;
+import org.apache.hadoop.hbase.procedure2.ProcedureUtil;
+import org.apache.hadoop.hbase.util.AbstractHBaseTool;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.CommonFSUtils;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.apache.yetus.audience.InterfaceStability;
+
+import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine;
+import org.apache.hbase.thirdparty.org.apache.commons.cli.Option;
+import org.apache.hbase.thirdparty.org.apache.commons.cli.OptionGroup;
+
+import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos;
+
+/**
+ * A tool to dump the procedures in the HFiles.
+ * 
+ * The different between this and {@link 
org.apache.hadoop.hbase.io.hfile.HFilePrettyPrinter} is
+ * that, this class will decode the procedure in the cell for better 
debugging. You are free to use
+ * {@link org.apache.hadoop.hbase.io.hfile.HFilePrettyPrinter} to dump the 
same file as well.
+ */
+@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS)
+@InterfaceStability.Evolving
+public class HFileProcedurePrettyPrinter extends AbstractHBaseTool {
+
+  private Long procId;
+
+  private List files = new ArrayList<>();
+
+  private final PrintStream out;
+
+  public HFileProcedurePrettyPrinter() {
+this(System.out);
+  }
+
+  public HFileProcedurePrettyPrinter(PrintStream out) {
+this.out = out;
+  }
+
+  @Override
+  protected void addOptions() {
+addOptWithArg("w", "seekToPid", "Seek to this procedure id and print this 
procedure only");
+OptionGroup files = new OptionGroup();
+files.addOption(new Option("f", "file", true,
+  "File to scan. Pass full-path; e.g. 
hdfs://a:9000/MasterProcs/master/procedure/p/xxx"));
+files.addOption(new Option("a", "all", false, "Scan the whole procedure 
region."));
 
 Review comment:
   nit: not a fan of the -f to specify file. Would rather that we pass list of 
files are arguments (rather than as an option). Could pass directory if wanted 
to print out all files.  But all of our tools take the -f so this is the 
'right' way for now. In follow-on, can change our tools so the -f gets removed.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [hbase] saintstack commented on a change in pull request #975: HBASE-23624 Add a tool to dump the procedure info in HFile

2019-12-31 Thread GitBox
saintstack commented on a change in pull request #975: HBASE-23624 Add a tool 
to dump the procedure info in HFile
URL: https://github.com/apache/hbase/pull/975#discussion_r362261050
 
 

 ##
 File path: hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java
 ##
 @@ -598,19 +598,28 @@ public static void setTimestamp(Cell cell, byte[] ts, 
int tsOffset) throws IOExc
   }
 
   /**
-   * @param cell
* @return The Key portion of the passed cell as a String.
*/
   public static String getCellKeyAsString(Cell cell) {
-StringBuilder sb = new StringBuilder(Bytes.toStringBinary(
-  cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()));
+return getCellKeyAsString(cell,
+  c -> Bytes.toStringBinary(c.getRowArray(), c.getRowOffset(), 
c.getRowLength()));
+  }
+
+  /**
+   * @param cell the cell to convert
+   * @param rowConverter used to convert the row of the cell to a string
+   * @return The Key portion of the passed cell as a String.
+   */
+  public static String getCellKeyAsString(Cell cell, Function 
rowConverter) {
 
 Review comment:
   Nice.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [hbase] saintstack commented on a change in pull request #975: HBASE-23624 Add a tool to dump the procedure info in HFile

2019-12-31 Thread GitBox
saintstack commented on a change in pull request #975: HBASE-23624 Add a tool 
to dump the procedure info in HFile
URL: https://github.com/apache/hbase/pull/975#discussion_r362263655
 
 

 ##
 File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/procedure2/store/region/HFileProcedurePrettyPrinter.java
 ##
 @@ -0,0 +1,174 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.procedure2.store.region;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.UncheckedIOException;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellUtil;
+import org.apache.hadoop.hbase.HBaseInterfaceAudience;
+import org.apache.hadoop.hbase.PrivateCellUtil;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.io.hfile.CacheConfig;
+import org.apache.hadoop.hbase.io.hfile.HFile;
+import org.apache.hadoop.hbase.io.hfile.HFileScanner;
+import org.apache.hadoop.hbase.procedure2.Procedure;
+import org.apache.hadoop.hbase.procedure2.ProcedureUtil;
+import org.apache.hadoop.hbase.util.AbstractHBaseTool;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.CommonFSUtils;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.apache.yetus.audience.InterfaceStability;
+
+import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine;
+import org.apache.hbase.thirdparty.org.apache.commons.cli.Option;
+import org.apache.hbase.thirdparty.org.apache.commons.cli.OptionGroup;
+
+import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos;
+
+/**
+ * A tool to dump the procedures in the HFiles.
+ * 
+ * The different between this and {@link 
org.apache.hadoop.hbase.io.hfile.HFilePrettyPrinter} is
+ * that, this class will decode the procedure in the cell for better 
debugging. You are free to use
+ * {@link org.apache.hadoop.hbase.io.hfile.HFilePrettyPrinter} to dump the 
same file as well.
+ */
+@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS)
+@InterfaceStability.Evolving
+public class HFileProcedurePrettyPrinter extends AbstractHBaseTool {
+
+  private Long procId;
+
+  private List files = new ArrayList<>();
+
+  private final PrintStream out;
+
+  public HFileProcedurePrettyPrinter() {
+this(System.out);
+  }
+
+  public HFileProcedurePrettyPrinter(PrintStream out) {
+this.out = out;
+  }
+
+  @Override
+  protected void addOptions() {
+addOptWithArg("w", "seekToPid", "Seek to this procedure id and print this 
procedure only");
 
 Review comment:
   Nice


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [hbase] saintstack commented on a change in pull request #975: HBASE-23624 Add a tool to dump the procedure info in HFile

2019-12-31 Thread GitBox
saintstack commented on a change in pull request #975: HBASE-23624 Add a tool 
to dump the procedure info in HFile
URL: https://github.com/apache/hbase/pull/975#discussion_r362264381
 
 

 ##
 File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/procedure2/store/region/HFileProcedurePrettyPrinter.java
 ##
 @@ -0,0 +1,174 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.procedure2.store.region;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.UncheckedIOException;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellUtil;
+import org.apache.hadoop.hbase.HBaseInterfaceAudience;
+import org.apache.hadoop.hbase.PrivateCellUtil;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.io.hfile.CacheConfig;
+import org.apache.hadoop.hbase.io.hfile.HFile;
+import org.apache.hadoop.hbase.io.hfile.HFileScanner;
+import org.apache.hadoop.hbase.procedure2.Procedure;
+import org.apache.hadoop.hbase.procedure2.ProcedureUtil;
+import org.apache.hadoop.hbase.util.AbstractHBaseTool;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.CommonFSUtils;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.apache.yetus.audience.InterfaceStability;
+
+import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine;
+import org.apache.hbase.thirdparty.org.apache.commons.cli.Option;
+import org.apache.hbase.thirdparty.org.apache.commons.cli.OptionGroup;
+
+import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos;
+
+/**
+ * A tool to dump the procedures in the HFiles.
+ * 
+ * The different between this and {@link 
org.apache.hadoop.hbase.io.hfile.HFilePrettyPrinter} is
+ * that, this class will decode the procedure in the cell for better 
debugging. You are free to use
+ * {@link org.apache.hadoop.hbase.io.hfile.HFilePrettyPrinter} to dump the 
same file as well.
+ */
+@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS)
+@InterfaceStability.Evolving
+public class HFileProcedurePrettyPrinter extends AbstractHBaseTool {
+
+  private Long procId;
+
+  private List files = new ArrayList<>();
+
+  private final PrintStream out;
+
+  public HFileProcedurePrettyPrinter() {
+this(System.out);
+  }
+
+  public HFileProcedurePrettyPrinter(PrintStream out) {
+this.out = out;
+  }
+
+  @Override
+  protected void addOptions() {
+addOptWithArg("w", "seekToPid", "Seek to this procedure id and print this 
procedure only");
+OptionGroup files = new OptionGroup();
+files.addOption(new Option("f", "file", true,
+  "File to scan. Pass full-path; e.g. 
hdfs://a:9000/MasterProcs/master/procedure/p/xxx"));
+files.addOption(new Option("a", "all", false, "Scan the whole procedure 
region."));
+options.addOptionGroup(files);
+  }
+
+  private void addAllHFiles() throws IOException {
+Path masterProcDir =
+  new Path(CommonFSUtils.getWALRootDir(conf), 
RegionProcedureStore.MASTER_PROCEDURE_DIR);
+Path tableDir = CommonFSUtils.getTableDir(masterProcDir, 
RegionProcedureStore.TABLE_NAME);
+FileSystem fs = tableDir.getFileSystem(conf);
+Path regionDir =
+  fs.listStatus(tableDir, p -> 
RegionInfo.isEncodedRegionName(Bytes.toBytes(p.getName([0]
+.getPath();
+List regionFiles = HFile.getStoreFiles(fs, regionDir);
+files.addAll(regionFiles);
+  }
+
+  @Override
+  protected void processOptions(CommandLine cmd) {
+if (cmd.hasOption("w")) {
+  String key = cmd.getOptionValue("w");
+  if (key != null && key.length() != 0) {
+procId = Long.parseLong(key);
+  } else {
+throw new IllegalArgumentException("Invalid row is specified.");
+  }
+}
+if (cmd.hasOption("f")) {
+  files.add(new Path(cmd.getOptionValue("f")));
+}
+if (cmd.hasOption("a")) {
+  try {
+addAllHFiles();
+  } catch (IOException e) {
+throw new UncheckedIOException(e);
+  }
+}
+  }
 
 Review comment:
   If no -f or -a, what happens?


[GitHub] [hbase] saintstack commented on a change in pull request #975: HBASE-23624 Add a tool to dump the procedure info in HFile

2019-12-31 Thread GitBox
saintstack commented on a change in pull request #975: HBASE-23624 Add a tool 
to dump the procedure info in HFile
URL: https://github.com/apache/hbase/pull/975#discussion_r362263467
 
 

 ##
 File path: hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java
 ##
 @@ -598,19 +598,28 @@ public static void setTimestamp(Cell cell, byte[] ts, 
int tsOffset) throws IOExc
   }
 
   /**
-   * @param cell
* @return The Key portion of the passed cell as a String.
*/
   public static String getCellKeyAsString(Cell cell) {
-StringBuilder sb = new StringBuilder(Bytes.toStringBinary(
-  cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()));
+return getCellKeyAsString(cell,
+  c -> Bytes.toStringBinary(c.getRowArray(), c.getRowOffset(), 
c.getRowLength()));
+  }
+
+  /**
+   * @param cell the cell to convert
+   * @param rowConverter used to convert the row of the cell to a string
+   * @return The Key portion of the passed cell as a String.
+   */
+  public static String getCellKeyAsString(Cell cell, Function 
rowConverter) {
+StringBuilder sb = new StringBuilder(rowConverter.apply(cell));
 sb.append('/');
-sb.append(cell.getFamilyLength() == 0? "":
-  Bytes.toStringBinary(cell.getFamilyArray(), cell.getFamilyOffset(), 
cell.getFamilyLength()));
-// KeyValue only added ':' if family is non-null.  Do same.
+sb.append(cell.getFamilyLength() == 0 ? ""
+  : Bytes.toStringBinary(cell.getFamilyArray(), cell.getFamilyOffset(),
+cell.getFamilyLength()));
+// KeyValue only added ':' if family is non-null. Do same.
 if (cell.getFamilyLength() > 0) sb.append(':');
-sb.append(cell.getQualifierLength() == 0? "":
-  Bytes.toStringBinary(cell.getQualifierArray(), cell.getQualifierOffset(),
+sb.append(cell.getQualifierLength() == 0 ? ""
+  : Bytes.toStringBinary(cell.getQualifierArray(), 
cell.getQualifierOffset(),
 
 Review comment:
   nit: I prefer the ":" on the EOL rather than these refactors. Not important.


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:
us...@infra.apache.org


With regards,
Apache Git Services