浏览代码

ZOOKEEPER-214. add new "stat reset" command to server admin port. (pat via mahadev)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@729131 13f79535-47bb-0310-9956-ffa450edef68
Mahadev Konar 16 年之前
父节点
当前提交
2f3b513b44

+ 3 - 0
CHANGES.txt

@@ -91,6 +91,9 @@ via mahadev)
    ZOOKEEPER-256. support use of JMX to manage log4j configuration at runtime.
    ZOOKEEPER-256. support use of JMX to manage log4j configuration at runtime.
 (pat via mahadev)
 (pat via mahadev)
 
 
+   ZOOKEEPER-214. add new "stat reset" command to server admin port. (pat via
+mahadev)
+
 Release 3.0.0 - 2008-10-21
 Release 3.0.0 - 2008-10-21
 
 
 Non-backward compatible changes:
 Non-backward compatible changes:

+ 14 - 6
docs/zookeeperAdmin.html

@@ -1122,6 +1122,14 @@ server.3=zoo3:2888:3888</span>
 </dd>
 </dd>
 
 
         
         
+<dt>
+<term>srst</term>
+</dt>
+<dd>
+<p>Reset statistics returned by stat command.</p>
+</dd>
+
+        
 <dt>
 <dt>
 <term>stat</term>
 <term>stat</term>
 </dt>
 </dt>
@@ -1136,7 +1144,7 @@ server.3=zoo3:2888:3888</span>
 <pre class="code">$ echo ruok | nc 127.0.0.1 5111
 <pre class="code">$ echo ruok | nc 127.0.0.1 5111
 imok
 imok
 </pre>
 </pre>
-<a name="N10388"></a><a name="sc_dataFileManagement"></a>
+<a name="N1038F"></a><a name="sc_dataFileManagement"></a>
 <h3 class="h4">Data File Management</h3>
 <h3 class="h4">Data File Management</h3>
 <p>ZooKeeper stores its data in a data directory and its transaction
 <p>ZooKeeper stores its data in a data directory and its transaction
       log in a transaction log directory. By default these two directories are
       log in a transaction log directory. By default these two directories are
@@ -1144,7 +1152,7 @@ imok
       transaction log files in a separate directory than the data files.
       transaction log files in a separate directory than the data files.
       Throughput increases and latency decreases when transaction logs reside
       Throughput increases and latency decreases when transaction logs reside
       on a dedicated log devices.</p>
       on a dedicated log devices.</p>
-<a name="N10391"></a><a name="The+Data+Directory"></a>
+<a name="N10398"></a><a name="The+Data+Directory"></a>
 <h4>The Data Directory</h4>
 <h4>The Data Directory</h4>
 <p>This directory has two files in it:</p>
 <p>This directory has two files in it:</p>
 <ul>
 <ul>
@@ -1190,14 +1198,14 @@ imok
         idempotent nature of its updates. By replaying the transaction log
         idempotent nature of its updates. By replaying the transaction log
         against fuzzy snapshots ZooKeeper gets the state of the system at the
         against fuzzy snapshots ZooKeeper gets the state of the system at the
         end of the log.</p>
         end of the log.</p>
-<a name="N103CD"></a><a name="The+Log+Directory"></a>
+<a name="N103D4"></a><a name="The+Log+Directory"></a>
 <h4>The Log Directory</h4>
 <h4>The Log Directory</h4>
 <p>The Log Directory contains the ZooKeeper transaction logs.
 <p>The Log Directory contains the ZooKeeper transaction logs.
         Before any update takes place, ZooKeeper ensures that the transaction
         Before any update takes place, ZooKeeper ensures that the transaction
         that represents the update is written to non-volatile storage. A new
         that represents the update is written to non-volatile storage. A new
         log file is started each time a snapshot is begun. The log file's
         log file is started each time a snapshot is begun. The log file's
         suffix is the first zxid written to that log.</p>
         suffix is the first zxid written to that log.</p>
-<a name="N103D7"></a><a name="File+Management"></a>
+<a name="N103DE"></a><a name="File+Management"></a>
 <h4>File Management</h4>
 <h4>File Management</h4>
 <p>The format of snapshot and log files does not change between
 <p>The format of snapshot and log files does not change between
         standalone ZooKeeper servers and different configurations of
         standalone ZooKeeper servers and different configurations of
@@ -1214,7 +1222,7 @@ imok
         needs the latest complete fuzzy snapshot and the log files from the
         needs the latest complete fuzzy snapshot and the log files from the
         start of that snapshot. The PurgeTxnLog utility implements a simple
         start of that snapshot. The PurgeTxnLog utility implements a simple
         retention policy that administrators can use.</p>
         retention policy that administrators can use.</p>
-<a name="N103E8"></a><a name="sc_commonProblems"></a>
+<a name="N103EF"></a><a name="sc_commonProblems"></a>
 <h3 class="h4">Things to Avoid</h3>
 <h3 class="h4">Things to Avoid</h3>
 <p>Here are some common problems you can avoid by configuring
 <p>Here are some common problems you can avoid by configuring
       ZooKeeper correctly:</p>
       ZooKeeper correctly:</p>
@@ -1268,7 +1276,7 @@ imok
 </dd>
 </dd>
       
       
 </dl>
 </dl>
-<a name="N1040C"></a><a name="sc_bestPractices"></a>
+<a name="N10413"></a><a name="sc_bestPractices"></a>
 <h3 class="h4">Best Practices</h3>
 <h3 class="h4">Best Practices</h3>
 <p>For best results, take note of the following list of good
 <p>For best results, take note of the following list of good
       Zookeeper practices. <em>[tbd...]</em>
       Zookeeper practices. <em>[tbd...]</em>

文件差异内容过多而无法显示
+ 3 - 3
docs/zookeeperAdmin.pdf


+ 8 - 0
src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml

@@ -809,6 +809,14 @@ server.3=zoo3:2888:3888</computeroutput></para>
           </listitem>
           </listitem>
         </varlistentry>
         </varlistentry>
 
 
+        <varlistentry>
+          <term>srst</term>
+
+          <listitem>
+            <para>Reset statistics returned by stat command.</para>
+          </listitem>
+        </varlistentry>
+
         <varlistentry>
         <varlistentry>
           <term>stat</term>
           <term>stat</term>
 
 

+ 26 - 0
src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java

@@ -526,13 +526,20 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
             // We take advantage of the limited size of the length to look
             // We take advantage of the limited size of the length to look
             // for cmds. They are all 4-bytes which fits inside of an int
             // for cmds. They are all 4-bytes which fits inside of an int
             if (len == ruokCmd) {
             if (len == ruokCmd) {
+                LOG.info("Processing ruok command from " 
+                        + sock.socket().getRemoteSocketAddress());
+
                 sendBuffer(imok.duplicate());
                 sendBuffer(imok.duplicate());
                 sendBuffer(NIOServerCnxn.closeConn);
                 sendBuffer(NIOServerCnxn.closeConn);
                 k.interestOps(SelectionKey.OP_WRITE);
                 k.interestOps(SelectionKey.OP_WRITE);
                 return;
                 return;
             } else if (len == killCmd) {
             } else if (len == killCmd) {
+                LOG.info("Processing kill command from " 
+                        + sock.socket().getRemoteSocketAddress());
                 System.exit(0);
                 System.exit(0);
             } else if (len == getTraceMaskCmd) {
             } else if (len == getTraceMaskCmd) {
+                LOG.info("Processing getracemask command from " 
+                        + sock.socket().getRemoteSocketAddress());
                 long traceMask = ZooTrace.getTextTraceLevel();
                 long traceMask = ZooTrace.getTextTraceLevel();
                 ByteBuffer resp = ByteBuffer.allocate(8);
                 ByteBuffer resp = ByteBuffer.allocate(8);
                 resp.putLong(traceMask);
                 resp.putLong(traceMask);
@@ -542,6 +549,8 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
                 k.interestOps(SelectionKey.OP_WRITE);
                 k.interestOps(SelectionKey.OP_WRITE);
                 return;
                 return;
             } else if (len == setTraceMaskCmd) {
             } else if (len == setTraceMaskCmd) {
+                LOG.info("Processing settracemask command from " 
+                        + sock.socket().getRemoteSocketAddress());
                 incomingBuffer = ByteBuffer.allocate(8);
                 incomingBuffer = ByteBuffer.allocate(8);
 
 
                 int rc = sock.read(incomingBuffer);
                 int rc = sock.read(incomingBuffer);
@@ -560,6 +569,8 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
                 k.interestOps(SelectionKey.OP_WRITE);
                 k.interestOps(SelectionKey.OP_WRITE);
                 return;
                 return;
             } else if (len == dumpCmd) {
             } else if (len == dumpCmd) {
+                LOG.info("Processing dump command from " 
+                        + sock.socket().getRemoteSocketAddress());
                 if (zk == null) {
                 if (zk == null) {
                     sendBuffer(ByteBuffer.wrap("ZooKeeper not active \n"
                     sendBuffer(ByteBuffer.wrap("ZooKeeper not active \n"
                             .getBytes()));
                             .getBytes()));
@@ -574,6 +585,8 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
                 k.interestOps(SelectionKey.OP_WRITE);
                 k.interestOps(SelectionKey.OP_WRITE);
                 return;
                 return;
             } else if (len == reqsCmd) {
             } else if (len == reqsCmd) {
+                LOG.info("Processing reqs command from " 
+                        + sock.socket().getRemoteSocketAddress());
                 StringBuffer sb = new StringBuffer();
                 StringBuffer sb = new StringBuffer();
                 sb.append("Requests:\n");
                 sb.append("Requests:\n");
                 synchronized (outstanding) {
                 synchronized (outstanding) {
@@ -586,6 +599,8 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
                 k.interestOps(SelectionKey.OP_WRITE);
                 k.interestOps(SelectionKey.OP_WRITE);
                 return;
                 return;
             } else if (len == statCmd) {
             } else if (len == statCmd) {
+                LOG.info("Processing stat command from " 
+                        + sock.socket().getRemoteSocketAddress());
                 StringBuffer sb = new StringBuffer();
                 StringBuffer sb = new StringBuffer();
                 if(zk!=null){
                 if(zk!=null){
                     sb.append("Zookeeper version: ").append(Version.getFullVersion())
                     sb.append("Zookeeper version: ").append(Version.getFullVersion())
@@ -607,6 +622,8 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
                 k.interestOps(SelectionKey.OP_WRITE);
                 k.interestOps(SelectionKey.OP_WRITE);
                 return;
                 return;
             } else if (len == enviCmd) {
             } else if (len == enviCmd) {
+                LOG.info("Processing envi command from " 
+                        + sock.socket().getRemoteSocketAddress());
                 StringBuffer sb = new StringBuffer();
                 StringBuffer sb = new StringBuffer();
                 
                 
                 List<Environment.Entry> env = Environment.list();
                 List<Environment.Entry> env = Environment.list();
@@ -620,6 +637,15 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
                 sendBuffer(ByteBuffer.wrap(sb.toString().getBytes()));
                 sendBuffer(ByteBuffer.wrap(sb.toString().getBytes()));
                 k.interestOps(SelectionKey.OP_WRITE);
                 k.interestOps(SelectionKey.OP_WRITE);
                 return;
                 return;
+            } else if (len == srstCmd) {
+                LOG.info("Processing srst command from " 
+                        + sock.socket().getRemoteSocketAddress());
+                ServerStats stats = ServerStats.getInstance();
+                stats.reset();
+
+                sendBuffer(ByteBuffer.wrap("Stats reset.\n".getBytes()));
+                k.interestOps(SelectionKey.OP_WRITE);
+                return;
             }
             }
         }
         }
         if (len < 0 || len > BinaryInputArchive.maxBuffer) {
         if (len < 0 || len > BinaryInputArchive.maxBuffer) {

+ 13 - 6
src/java/main/org/apache/zookeeper/server/ServerCnxn.java

@@ -31,24 +31,31 @@ import org.apache.zookeeper.proto.ReplyHeader;
 import org.apache.zookeeper.proto.WatcherEvent;
 import org.apache.zookeeper.proto.WatcherEvent;
 
 
 public interface ServerCnxn extends Watcher {
 public interface ServerCnxn extends Watcher {
+    
+    /**
+     * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
+     * Zk Admin</a>. this link is for all the commands.
+     */
     final static int killCmd = ByteBuffer.wrap("kill".getBytes()).getInt();
     final static int killCmd = ByteBuffer.wrap("kill".getBytes()).getInt();
-
+    
     final static int ruokCmd = ByteBuffer.wrap("ruok".getBytes()).getInt();
     final static int ruokCmd = ByteBuffer.wrap("ruok".getBytes()).getInt();
 
 
     final static int dumpCmd = ByteBuffer.wrap("dump".getBytes()).getInt();
     final static int dumpCmd = ByteBuffer.wrap("dump".getBytes()).getInt();
-
+    
     final static int statCmd = ByteBuffer.wrap("stat".getBytes()).getInt();
     final static int statCmd = ByteBuffer.wrap("stat".getBytes()).getInt();
-
+    
     final static int reqsCmd = ByteBuffer.wrap("reqs".getBytes()).getInt();
     final static int reqsCmd = ByteBuffer.wrap("reqs".getBytes()).getInt();
 
 
     final static int setTraceMaskCmd = ByteBuffer.wrap("stmk".getBytes())
     final static int setTraceMaskCmd = ByteBuffer.wrap("stmk".getBytes())
             .getInt();
             .getInt();
-
+    
     final static int getTraceMaskCmd = ByteBuffer.wrap("gtmk".getBytes())
     final static int getTraceMaskCmd = ByteBuffer.wrap("gtmk".getBytes())
             .getInt();
             .getInt();
-
+    
     final static int enviCmd = ByteBuffer.wrap("envi".getBytes()).getInt();
     final static int enviCmd = ByteBuffer.wrap("envi".getBytes()).getInt();
-
+    
+    final static int srstCmd = ByteBuffer.wrap("srst".getBytes()).getInt();
+    
     final static ByteBuffer imok = ByteBuffer.wrap("imok".getBytes());
     final static ByteBuffer imok = ByteBuffer.wrap("imok".getBytes());
 
 
     public abstract int getSessionTimeout();
     public abstract int getSessionTimeout();

+ 5 - 0
src/java/main/org/apache/zookeeper/server/ServerStats.java

@@ -136,5 +136,10 @@ public class ServerStats {
     synchronized public void resetRequestCounters(){
     synchronized public void resetRequestCounters(){
         packetsReceived=packetsSent=0;
         packetsReceived=packetsSent=0;
     }
     }
+    
+    synchronized public void reset() {
+        resetLatency();
+        resetRequestCounters();
+    }
 
 
 }
 }

部分文件因为文件数量过多而无法显示