zookeeper-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [zookeeper] anmolnar commented on a change in pull request #975: ZOOKEEPER-3410:./zkTxnLogToolkit.sh will throw the NPE and stop the process of formatting txn logs due to the data's content is null
Date Wed, 19 Jun 2019 21:17:32 GMT
anmolnar commented on a change in pull request #975: ZOOKEEPER-3410:./zkTxnLogToolkit.sh will
throw the NPE and stop the process of formatting txn logs due to the data's content is null
URL: https://github.com/apache/zookeeper/pull/975#discussion_r295527654
 
 

 ##########
 File path: zookeeper-server/src/main/java/org/apache/zookeeper/server/persistence/TxnLogToolkit.java
 ##########
 @@ -262,57 +262,63 @@ private boolean askForFix(Scanner scanner) throws TxnLogToolkitException
{
         }
     }
 
-    private void printTxn(byte[] bytes) throws IOException {
+    private void printTxn(byte[] bytes) {
         printTxn(bytes, "");
     }
 
-    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()),
-                txnStr);
-        if (prefix != null && !"".equals(prefix.trim())) {
-            System.out.print(prefix + " - ");
-        }
-        if (txns.endsWith("\n")) {
-            System.out.print(txns);
-        } else {
-            System.out.println(txns);
+    private void printTxn(byte[] bytes, String prefix) {
+        try {
+            TxnHeader hdr = new TxnHeader();
+            Record txn = SerializeUtils.deserializeTxn(bytes, hdr);
+            String txnStr;
+
+            txnStr = getFormattedTxnStr(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()),
+                    txnStr);
+            if (prefix != null && !"".equals(prefix.trim())) {
+                System.out.print(prefix + " - ");
+            }
+            if (txns.endsWith("\n")) {
+                System.out.print(txns);
+            } else {
+                System.out.println(txns);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
 
 Review comment:
   You've already fixed the 'null' reference problem, why do you catch everything here?
   If something goes wrong with a txn, probably will happen for the others too and you'll
end up flooding your console with error messages. I think it's better to full stop in case
of an unhandled error.

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


With regards,
Apache Git Services

Mime
View raw message