Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CB40718F54 for ; Thu, 7 Apr 2016 05:10:07 +0000 (UTC) Received: (qmail 37453 invoked by uid 500); 7 Apr 2016 05:10:07 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 37409 invoked by uid 500); 7 Apr 2016 05:10:07 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 37400 invoked by uid 99); 7 Apr 2016 05:10:07 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Apr 2016 05:10:07 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 294DDDFDEC; Thu, 7 Apr 2016 05:10:07 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jerryjch@apache.org To: commits@hbase.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: hbase git commit: HBASE-15592 Print Procedure WAL content Date: Thu, 7 Apr 2016 05:10:07 +0000 (UTC) Repository: hbase Updated Branches: refs/heads/branch-1.3 92afd3cd5 -> 2a0288dd8 HBASE-15592 Print Procedure WAL content Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/2a0288dd Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/2a0288dd Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/2a0288dd Branch: refs/heads/branch-1.3 Commit: 2a0288dd89b03230cb406a7dbc54314a8dd55ec5 Parents: 92afd3c Author: Jerry He Authored: Wed Apr 6 22:00:52 2016 -0700 Committer: Jerry He Committed: Wed Apr 6 22:08:20 2016 -0700 ---------------------------------------------------------------------- .../hadoop/hbase/procedure2/Procedure.java | 33 ++++ .../store/wal/ProcedureWALPrettyPrinter.java | 189 +++++++++++++++++++ 2 files changed, 222 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/2a0288dd/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/Procedure.java ---------------------------------------------------------------------- diff --git a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/Procedure.java b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/Procedure.java index aff2b15..781bad9 100644 --- a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/Procedure.java +++ b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/Procedure.java @@ -205,6 +205,16 @@ public abstract class Procedure implements Comparable { @Override public String toString() { + // Return the simple String presentation of the procedure. + return toStringSimpleSB().toString(); + } + + /** + * Build the StringBuilder for the simple form of + * procedure string. + * @return the StringBuilder + */ + protected StringBuilder toStringSimpleSB() { StringBuilder sb = new StringBuilder(); toStringClassDetails(sb); @@ -225,6 +235,29 @@ public abstract class Procedure implements Comparable { sb.append(" state="); toStringState(sb); + + return sb; + } + + /** + * Extend the toString() information with more procedure + * details + */ + public String toStringDetails() { + StringBuilder sb = toStringSimpleSB(); + + sb.append(" startTime="); + sb.append(getStartTime()); + + sb.append(" lastUpdate="); + sb.append(getLastUpdate()); + + if (stackIndexes != null) { + sb.append("\n"); + sb.append("stackIndexes="); + sb.append(Arrays.toString(getStackIndexes())); + } + return sb.toString(); } http://git-wip-us.apache.org/repos/asf/hbase/blob/2a0288dd/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/wal/ProcedureWALPrettyPrinter.java ---------------------------------------------------------------------- diff --git a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/wal/ProcedureWALPrettyPrinter.java b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/wal/ProcedureWALPrettyPrinter.java new file mode 100644 index 0000000..9c33ac2 --- /dev/null +++ b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/wal/ProcedureWALPrettyPrinter.java @@ -0,0 +1,189 @@ +/** + * 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.wal; + +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.PosixParser; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FSDataInputStream; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HBaseInterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceStability; +import org.apache.hadoop.hbase.procedure2.Procedure; +import org.apache.hadoop.hbase.protobuf.generated.ProcedureProtos.ProcedureWALEntry; +import org.apache.hadoop.hbase.protobuf.generated.ProcedureProtos.ProcedureWALHeader; + +/** + * ProcedureWALPrettyPrinter prints the contents of a given ProcedureWAL file + */ +@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS) +@InterfaceStability.Evolving +public class ProcedureWALPrettyPrinter { + private PrintStream out; + + public ProcedureWALPrettyPrinter() { + out = System.out; + } + + /** + * Reads a log file and outputs its contents. + * + * @param conf HBase configuration relevant to this log file + * @param p path of the log file to be read + * @throws IOException IOException + */ + public void processFile(final Configuration conf, final Path p) + throws IOException { + + FileSystem fs = p.getFileSystem(conf); + if (!fs.exists(p)) { + System.err.println("ERROR, file doesnt exist: " + p); + return; + } + if (!fs.isFile(p)) { + System.err.println(p + " is not a file"); + return; + } + + FileStatus logFile = fs.getFileStatus(p); + if (logFile.getLen() == 0) { + out.println("Zero length file: " + p); + return; + } + + out.println("Opening procedure state-log: " + p); + ProcedureWALFile log = new ProcedureWALFile(fs, logFile); + processProcedureWALFile(log); + } + + public void processProcedureWALFile(ProcedureWALFile log) throws IOException { + + log.open(); + ProcedureWALHeader header = log.getHeader(); + printHeader(header); + + FSDataInputStream stream = log.getStream(); + try { + boolean hasMore = true; + while (hasMore) { + ProcedureWALEntry entry = ProcedureWALFormat.readEntry(stream); + if (entry == null) { + out.print("No more entry, exiting with missing EOF"); + hasMore = false; + break; + } + switch (entry.getType()) { + case PROCEDURE_WAL_EOF: + hasMore = false; + break; + default: + printEntry(entry); + } + } + } catch (IOException e) { + out.print("got an exception while reading the procedure WAL " + e.getMessage()); + } + finally { + log.close(); + } + } + + private void printEntry(ProcedureWALEntry entry) throws IOException { + out.println("EntryType=" + entry.getType()); + int procCount = entry.getProcedureCount(); + for (int i = 0; i < procCount; i++) { + Procedure proc = Procedure.convert(entry.getProcedure(i)); + printProcedure(proc); + } + } + + private void printProcedure(Procedure proc) { + out.println(proc.toStringDetails()); + } + + private void printHeader(ProcedureWALHeader header) { + out.println("ProcedureWALHeader: "); + out.println(" Version: " + header.getVersion()); + out.println(" Type: " + header.getType()); + out.println(" LogId: " + header.getLogId()); + out.println(" MinProcId: " + header.getMinProcId()); + out.println(); + } + + public static void main(String[] args) throws IOException { + run(args); + } + + /** + * Pass one or more log file names and formatting options and it will dump out + * a text version of the contents on stdout. + * + * @param args + * Command line arguments + * @throws IOException + * Thrown upon file system errors etc. + */ + public static void run(String[] args) throws IOException { + // create options + Options options = new Options(); + options.addOption("h", "help", false, "Output help message"); + options.addOption("f", "file", true, "File to print"); + + List files = new ArrayList(); + + ProcedureWALPrettyPrinter printer = new ProcedureWALPrettyPrinter(); + CommandLineParser parser = new PosixParser(); + try { + CommandLine cmd = parser.parse(options, args); + + if (cmd.hasOption("f")) { + files.add(new Path(cmd.getOptionValue("f"))); + } + + if (files.size() == 0 || cmd.hasOption("h")) { + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp("ProcedureWALPrettyPrinter ", options, true); + System.exit(-1); + } + + } catch (ParseException e) { + e.printStackTrace(); + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp("ProcedureWALPrettyPrinter ", options, true); + System.exit(-1); + } + // get configuration, file system, and process the given files + Configuration conf = HBaseConfiguration.create(); + for (Path file : files) { + printer.processFile(conf, file); + } + } +}