You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by an...@apache.org on 2018/09/12 11:32:12 UTC
zookeeper git commit: ZOOKEEPER-1823: zkTxnLogToolkit -dump should
support printing transaction data as a string
Repository: zookeeper
Updated Branches:
refs/heads/master 6651a126c -> 14870ddd4
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 <ma...@sina.com>
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
Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/14870ddd
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/14870ddd
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/14870ddd
Branch: refs/heads/master
Commit: 14870ddd4b87afe3af497ec0569ce439c0488053
Parents: 6651a12
Author: maoling <ma...@sina.com>
Authored: Wed Sep 12 13:32:07 2018 +0200
Committer: Andor Molnar <an...@apache.org>
Committed: Wed Sep 12 13:32:07 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/14870ddd/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 7adaf25..496b9a4 100644
--- a/src/java/main/org/apache/zookeeper/server/persistence/TxnLogToolkit.java
+++ b/src/java/main/org/apache/zookeeper/server/persistence/TxnLogToolkit.java
@@ -31,6 +31,10 @@ import org.apache.jute.Record;
import org.apache.zookeeper.server.ExitCode;
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;
@@ -222,13 +226,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 + " - ");
}
@@ -239,6 +244,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);
@@ -274,7 +314,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/14870ddd/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 ade4e74..50143d4 100644
--- a/zookeeper-docs/src/documentation/content/xdocs/zookeeperAdmin.xml
+++ b/zookeeper-docs/src/documentation/content/xdocs/zookeeperAdmin.xml
@@ -2273,7 +2273,7 @@ server.3=zoo3:2888:3888</programlisting>
$ 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.