zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nkal...@apache.org
Subject [zookeeper] branch master updated: ZOOKEEPER-3501: unify the method:op2String()
Date Fri, 20 Sep 2019 08:06:51 GMT
This is an automated email from the ASF dual-hosted git repository.

nkalmar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new a179caa  ZOOKEEPER-3501: unify the method:op2String()
a179caa is described below

commit a179caa668882d6129ebb000ee60455de749d34f
Author: maoling <maoling199210191@sina.com>
AuthorDate: Fri Sep 20 10:06:43 2019 +0200

    ZOOKEEPER-3501: unify the method:op2String()
    
    - delete the duplicated method `op2String()` in the `TraceFormatter.java `
    - there're 30 ops in the `ZooDefs.OpCode` and they're the same order with the `Request#op2String`
for reading
    - more details in the [ZOOKEEPER-3501](https://issues.apache.org/jira/browse/ZOOKEEPER-3501)
    
    Author: maoling <maoling199210191@sina.com>
    
    Reviewers: Enrico Olivelli <eolivelli@apache.org>, Norbert Kalmar <nkalmar@apache.org>
    
    Closes #1050 from maoling/ZOOKEEPER-3501
---
 .../org/apache/zookeeper/server/LogFormatter.java  |   2 +-
 .../java/org/apache/zookeeper/server/Request.java  | 120 +++++++++++----------
 .../apache/zookeeper/server/TraceFormatter.java    |  93 +++-------------
 .../server/persistence/TxnLogToolkit.java          |   8 +-
 .../zookeeper/test/LocalSessionRequestTest.java    |   4 +-
 5 files changed, 85 insertions(+), 142 deletions(-)

diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/LogFormatter.java
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/LogFormatter.java
index fd7f0cc..459f802 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/LogFormatter.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/LogFormatter.java
@@ -104,7 +104,7 @@ public class LogFormatter {
                 + " session 0x" + Long.toHexString(hdr.getClientId())
                 + " cxid 0x" + Long.toHexString(hdr.getCxid())
                 + " zxid 0x" + Long.toHexString(hdr.getZxid())
-                + " " + TraceFormatter.op2String(hdr.getType())
+                + " " + Request.op2String(hdr.getType())
                 + " " + txn);
             if (logStream.readByte("EOR") != 'B') {
                 LOG.error("Last transaction was partial.");
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java
index 295e983..bab2194 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java
@@ -286,64 +286,68 @@ public class Request {
 
     public static String op2String(int op) {
         switch (op) {
-        case OpCode.notification:
-            return "notification";
-        case OpCode.create:
-            return "create";
-        case OpCode.create2:
-            return "create2";
-        case OpCode.createTTL:
-            return "createTtl";
-        case OpCode.createContainer:
-            return "createContainer";
-        case OpCode.setWatches:
-            return "setWatches";
-        case OpCode.delete:
-            return "delete";
-        case OpCode.deleteContainer:
-            return "deleteContainer";
-        case OpCode.exists:
-            return "exists";
-        case OpCode.getData:
-            return "getData";
-        case OpCode.check:
-            return "check";
-        case OpCode.multi:
-            return "multi";
-        case OpCode.multiRead:
-            return "multiRead";
-        case OpCode.setData:
-            return "setData";
-        case OpCode.sync:
-            return "sync:";
-        case OpCode.getACL:
-            return "getACL";
-        case OpCode.setACL:
-            return "setACL";
-        case OpCode.getChildren:
-            return "getChildren";
-        case OpCode.getAllChildrenNumber:
-            return "getAllChildrenNumber";
-        case OpCode.getChildren2:
-            return "getChildren2";
-        case OpCode.getEphemerals:
-            return "getEphemerals";
-        case OpCode.ping:
-            return "ping";
-        case OpCode.createSession:
-            return "createSession";
-        case OpCode.closeSession:
-            return "closeSession";
-        case OpCode.error:
-            return "error";
-        case OpCode.reconfig:
-            return "reconfig";
-        case OpCode.checkWatches:
-            return "checkWatches";
-        case OpCode.removeWatches:
-            return "removeWatches";
-        default:
-            return "unknown " + op;
+            case OpCode.notification:
+                return "notification";
+            case OpCode.create:
+                return "create";
+            case OpCode.delete:
+                return "delete";
+            case OpCode.exists:
+                return "exists";
+            case OpCode.getData:
+                return "getData";
+            case OpCode.setData:
+                return "setData";
+            case OpCode.getACL:
+                return "getACL";
+            case OpCode.setACL:
+                return "setACL";
+            case OpCode.getChildren:
+                return "getChildren";
+            case OpCode.sync:
+                return "sync";
+            case OpCode.ping:
+                return "ping";
+            case OpCode.getChildren2:
+                return "getChildren2";
+            case OpCode.check:
+                return "check";
+            case OpCode.multi:
+                return "multi";
+            case OpCode.create2:
+                return "create2";
+            case OpCode.reconfig:
+                return "reconfig";
+            case OpCode.checkWatches:
+                return "checkWatches";
+            case OpCode.removeWatches:
+                return "removeWatches";
+            case OpCode.createContainer:
+                return "createContainer";
+            case OpCode.deleteContainer:
+                return "deleteContainer";
+            case OpCode.createTTL:
+                return "createTtl";
+            case OpCode.multiRead:
+                return "multiRead";
+            case OpCode.auth:
+                return "auth";
+            case OpCode.setWatches:
+                return "setWatches";
+            case OpCode.sasl:
+                return "sasl";
+            case OpCode.getEphemerals:
+                return "getEphemerals";
+            case OpCode.getAllChildrenNumber:
+                return "getAllChildrenNumber";
+            case OpCode.createSession:
+                return "createSession";
+            case OpCode.closeSession:
+                return "closeSession";
+            case OpCode.error:
+                return "error";
+            default:
+                return "unknown " + op;
         }
     }
 
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/TraceFormatter.java
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/TraceFormatter.java
index 75e0e9f..36a1e68 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/TraceFormatter.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/TraceFormatter.java
@@ -28,73 +28,6 @@ import org.apache.zookeeper.ZooDefs.OpCode;
 
 public class TraceFormatter {
 
-    public static String op2String(int op) {
-        switch (op) {
-        case OpCode.notification:
-            return "notification";
-        case OpCode.create:
-            return "create";
-        case OpCode.create2:
-            return "create2";
-        case OpCode.createTTL:
-            return "createTtl";
-        case OpCode.createContainer:
-            return "createContainer";
-        case OpCode.delete:
-            return "delete";
-        case OpCode.deleteContainer:
-            return "deleteContainer";
-        case OpCode.exists:
-            return "exists";
-        case OpCode.getData:
-            return "getData";
-        case OpCode.setData:
-            return "setData";
-        case OpCode.multi:
-            return "multi";
-        case OpCode.getACL:
-            return "getACL";
-        case OpCode.setACL:
-            return "setACL";
-        case OpCode.getChildren:
-            return "getChildren";
-        case OpCode.getAllChildrenNumber:
-            return "getAllChildrenNumber";
-        case OpCode.getChildren2:
-            return "getChildren2";
-        case OpCode.getEphemerals:
-            return "getEphemerals";
-        case OpCode.ping:
-            return "ping";
-        case OpCode.createSession:
-            return "createSession";
-        case OpCode.closeSession:
-            return "closeSession";
-        case OpCode.error:
-            return "error";
-        case OpCode.reconfig:
-            return "reconfig";
-        case OpCode.check:
-            return "check";
-        case OpCode.sync:
-            return "sync";
-        case OpCode.checkWatches:
-            return "checkWatches";
-        case OpCode.removeWatches:
-            return "removeWatches";
-        case OpCode.auth:
-            return "auth";
-        case OpCode.setWatches:
-            return "setWatches";
-        case OpCode.sasl:
-            return "sasl";
-        case OpCode.multiRead:
-            return "multiRead";
-        default:
-            return "unknown " + op;
-        }
-    }
-
     /**
      * @param args
      * @throws IOException
@@ -130,16 +63,22 @@ public class TraceFormatter {
                     path = new String(b);
                 }
             }
-            System.out.println(
-                DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG).format(new
Date(time))
-                + ": " + (char) app
-                + " id=0x" + Long.toHexString(id)
-                + " cxid=" + cxid
-                + " op=" + op2String(type)
-                + " zxid=0x" + Long.toHexString(zxid)
-                + " txnType=" + txnType
-                + " len=" + len
-                + " path=" + path);
+            System.out.println(DateFormat.getDateTimeInstance(DateFormat.SHORT,
+                    DateFormat.LONG).format(new Date(time))
+                    + ": "
+                    + (char) app
+                    + " id=0x"
+                    + Long.toHexString(id)
+                    + " cxid="
+                    + cxid
+                    + " op="
+                    + Request.op2String(type)
+                    + " zxid=0x"
+                    + Long.toHexString(zxid)
+                    + " txnType="
+                    + txnType
+                    + " len="
+                    + len + " path=" + path);
         }
     }
 
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/persistence/TxnLogToolkit.java
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/persistence/TxnLogToolkit.java
index df069ed..bb95d00 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/persistence/TxnLogToolkit.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/persistence/TxnLogToolkit.java
@@ -48,7 +48,7 @@ import org.apache.jute.BinaryInputArchive;
 import org.apache.jute.BinaryOutputArchive;
 import org.apache.jute.Record;
 import org.apache.zookeeper.server.ExitCode;
-import org.apache.zookeeper.server.TraceFormatter;
+import org.apache.zookeeper.server.Request;
 import org.apache.zookeeper.server.util.LogChopper;
 import org.apache.zookeeper.server.util.SerializeUtils;
 import org.apache.zookeeper.txn.CreateContainerTxn;
@@ -291,7 +291,7 @@ public class TxnLogToolkit implements Closeable {
             Long.toHexString(hdr.getClientId()),
             Long.toHexString(hdr.getCxid()),
             Long.toHexString(hdr.getZxid()),
-            TraceFormatter.op2String(hdr.getType()),
+                Request.op2String(hdr.getType()),
             txnStr);
         if (prefix != null && !"".equals(prefix.trim())) {
             System.out.print(prefix + " - ");
@@ -337,9 +337,9 @@ public class TxnLogToolkit implements Closeable {
             for (int i = 0; i < txnList.size(); i++) {
                 Txn t = txnList.get(i);
                 if (i == 0) {
-                    txnData.append(TraceFormatter.op2String(t.getType()) + ":" + checkNullToEmpty(t.getData()));
+                    txnData.append(Request.op2String(t.getType()) + ":" + checkNullToEmpty(t.getData()));
                 } else {
-                    txnData.append(";" + TraceFormatter.op2String(t.getType()) + ":" + checkNullToEmpty(t.getData()));
+                    txnData.append(";" + Request.op2String(t.getType()) + ":" + checkNullToEmpty(t.getData()));
                 }
             }
         } else {
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/LocalSessionRequestTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/test/LocalSessionRequestTest.java
index 156a3a7..7debfbd 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/LocalSessionRequestTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/LocalSessionRequestTest.java
@@ -21,7 +21,7 @@ package org.apache.zookeeper.test;
 import static org.junit.Assert.assertFalse;
 import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.server.TraceFormatter;
+import org.apache.zookeeper.server.Request;
 import org.apache.zookeeper.server.ZKDatabase;
 import org.apache.zookeeper.server.quorum.Leader.Proposal;
 import org.apache.zookeeper.server.quorum.QuorumPeer;
@@ -83,7 +83,7 @@ public class LocalSessionRequestTest extends ZKTestCase {
         ZKDatabase db = peer.getActiveServer().getZKDatabase();
         for (Proposal p : db.getCommittedLog()) {
             assertFalse("Should not see "
-                                       + TraceFormatter.op2String(p.request.type)
+                                       + Request.op2String(p.request.type)
                                        + " request from local session 0x"
                                        + session
                                        + " on the "


Mime
View raw message