From commits-return-6998-archive-asf-public=cust-asf.ponee.io@zookeeper.apache.org Wed Sep 12 13:32:30 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id E8ACE180630 for ; Wed, 12 Sep 2018 13:32:29 +0200 (CEST) Received: (qmail 84397 invoked by uid 500); 12 Sep 2018 11:32:29 -0000 Mailing-List: contact commits-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zookeeper.apache.org Delivered-To: mailing list commits@zookeeper.apache.org Received: (qmail 84386 invoked by uid 99); 12 Sep 2018 11:32:29 -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; Wed, 12 Sep 2018 11:32:29 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DDB9ADFF2E; Wed, 12 Sep 2018 11:32:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: andor@apache.org To: commits@zookeeper.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: zookeeper git commit: ZOOKEEPER-1823: zkTxnLogToolkit -dump should support printing transaction data as a string Date: Wed, 12 Sep 2018 11:32:28 +0000 (UTC) Repository: zookeeper Updated Branches: refs/heads/branch-3.5 14d0aaab8 -> 78976f6aa ZOOKEEPER-1823: zkTxnLogToolkit -dump should support printing transaction data as a string - It would be a useful addition for debuggling to show transaction data as strings with a option `-s ` - update the usage string to `USAGE: LogFormatter [-s] log_file` and add a short description for the `-s ` option - for the issue [michim](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=michim) mentioned has been resolved,the test evidence has been included in the jira(Notice:we cannot `split(",")[1]` to replace the node data,because the node path can be like this `"/mao,ling"`) - more details in [ZOOKEEPER-1823](https://issues.apache.org/jira/browse/ZOOKEEPER-1823).Thanks [rgs](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=rgs) for the origin work Author: maoling Reviewers: andor@apache.org Closes #613 from maoling/ZOOKEEPER-1823 and squashes the following commits: 82c375b0 [maoling] change the desc of -d option in the code ba3ee65a [maoling] transport this improment to TxnLogToolkit 96939873 [maoling] Revert "ZOOKEEPER-1823:LogFormatter should support printing transaction data as a string" 298428ea [maoling] ZOOKEEPER-1823:LogFormatter should support printing transaction data as a string (cherry picked from commit 14870ddd4b87afe3af497ec0569ce439c0488053) Signed-off-by: Andor Molnar Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/78976f6a Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/78976f6a Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/78976f6a Branch: refs/heads/branch-3.5 Commit: 78976f6aaec45b188f6c271710973f6383d33d59 Parents: 14d0aaa Author: maoling Authored: Wed Sep 12 13:32:07 2018 +0200 Committer: Andor Molnar Committed: Wed Sep 12 13:32:21 2018 +0200 ---------------------------------------------------------------------- .../server/persistence/TxnLogToolkit.java | 44 +++++++++++++++++++- .../content/xdocs/zookeeperAdmin.xml | 2 +- 2 files changed, 43 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zookeeper/blob/78976f6a/src/java/main/org/apache/zookeeper/server/persistence/TxnLogToolkit.java ---------------------------------------------------------------------- diff --git a/src/java/main/org/apache/zookeeper/server/persistence/TxnLogToolkit.java b/src/java/main/org/apache/zookeeper/server/persistence/TxnLogToolkit.java index 887d98b..e47d55b 100644 --- a/src/java/main/org/apache/zookeeper/server/persistence/TxnLogToolkit.java +++ b/src/java/main/org/apache/zookeeper/server/persistence/TxnLogToolkit.java @@ -30,6 +30,10 @@ import org.apache.jute.BinaryOutputArchive; import org.apache.jute.Record; import org.apache.zookeeper.server.TraceFormatter; import org.apache.zookeeper.server.util.SerializeUtils; +import org.apache.zookeeper.txn.CreateContainerTxn; +import org.apache.zookeeper.txn.CreateTTLTxn; +import org.apache.zookeeper.txn.CreateTxn; +import org.apache.zookeeper.txn.SetDataTxn; import org.apache.zookeeper.txn.TxnHeader; import java.io.Closeable; @@ -221,13 +225,14 @@ public class TxnLogToolkit implements Closeable { private void printTxn(byte[] bytes, String prefix) throws IOException { TxnHeader hdr = new TxnHeader(); Record txn = SerializeUtils.deserializeTxn(bytes, hdr); + String txnStr = getDataStrFromTxn(txn); String txns = String.format("%s session 0x%s cxid 0x%s zxid 0x%s %s %s", DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG).format(new Date(hdr.getTime())), Long.toHexString(hdr.getClientId()), Long.toHexString(hdr.getCxid()), Long.toHexString(hdr.getZxid()), TraceFormatter.op2String(hdr.getType()), - txn); + txnStr); if (prefix != null && !"".equals(prefix.trim())) { System.out.print(prefix + " - "); } @@ -238,6 +243,41 @@ public class TxnLogToolkit implements Closeable { } } + /** + * get transaction log data string with node's data as a string + * @param txn + * @return + */ + private static String getDataStrFromTxn(Record txn) { + StringBuilder txnData = new StringBuilder(); + if (txn == null) { + return txnData.toString(); + } + if (txn instanceof CreateTxn) { + CreateTxn createTxn = ((CreateTxn) txn); + txnData.append(createTxn.getPath() + "," + new String(createTxn.getData())) + .append("," + createTxn.getAcl() + "," + createTxn.getEphemeral()) + .append("," + createTxn.getParentCVersion()); + } else if (txn instanceof SetDataTxn) { + SetDataTxn setDataTxn = ((SetDataTxn) txn); + txnData.append(setDataTxn.getPath() + "," + new String(setDataTxn.getData())) + .append("," + setDataTxn.getVersion()); + } else if (txn instanceof CreateContainerTxn) { + CreateContainerTxn createContainerTxn = ((CreateContainerTxn) txn); + txnData.append(createContainerTxn.getPath() + "," + new String(createContainerTxn.getData())) + .append("," + createContainerTxn.getAcl() + "," + createContainerTxn.getParentCVersion()); + } else if (txn instanceof CreateTTLTxn) { + CreateTTLTxn createTTLTxn = ((CreateTTLTxn) txn); + txnData.append(createTTLTxn.getPath() + "," + new String(createTTLTxn.getData())) + .append("," + createTTLTxn.getAcl() + "," + createTTLTxn.getParentCVersion()) + .append("," + createTTLTxn.getTtl()); + } else { + txnData.append(txn.toString()); + } + + return txnData.toString(); + } + private void openTxnLogFile() throws FileNotFoundException { txnFis = new FileInputStream(txnLogFile); logStream = BinaryInputArchive.getArchive(txnFis); @@ -273,7 +313,7 @@ public class TxnLogToolkit implements Closeable { Option quietOpt = new Option("v", "verbose", false, "Be verbose in recovery mode: print all entries, not just fixed ones."); options.addOption(quietOpt); - Option dumpOpt = new Option("d", "dump", false, "Dump mode. Dump all entries of the log file. (this is the default)"); + Option dumpOpt = new Option("d", "dump", false, "Dump mode. Dump all entries of the log file with printing the content of a nodepath (default)"); options.addOption(dumpOpt); Option forceOpt = new Option("y", "yes", false, "Non-interactive mode: repair all CRC errors without asking"); http://git-wip-us.apache.org/repos/asf/zookeeper/blob/78976f6a/zookeeper-docs/src/documentation/content/xdocs/zookeeperAdmin.xml ---------------------------------------------------------------------- diff --git a/zookeeper-docs/src/documentation/content/xdocs/zookeeperAdmin.xml b/zookeeper-docs/src/documentation/content/xdocs/zookeeperAdmin.xml index 8de0a66..d82e234 100644 --- a/zookeeper-docs/src/documentation/content/xdocs/zookeeperAdmin.xml +++ b/zookeeper-docs/src/documentation/content/xdocs/zookeeperAdmin.xml @@ -2170,7 +2170,7 @@ server.3=zoo3:2888:3888 $ bin/zkTxnLogToolkit.sh usage: TxnLogToolkit [-dhrv] txn_log_file_name - -d,--dump Dump mode. Dump all entries of the log file. (this is the default) + -d,--dump Dump mode. Dump all entries of the log file with printing the content of a nodepath (default) -h,--help Print help message -r,--recover Recovery mode. Re-calculate CRC for broken entries. -v,--verbose Be verbose in recovery mode: print all entries, not just fixed ones.