hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r922377 - in /hadoop/zookeeper/trunk: ./ src/docs/src/documentation/content/xdocs/ src/java/main/org/apache/zookeeper/server/ src/java/main/org/apache/zookeeper/server/quorum/ src/java/test/org/apache/zookeeper/test/
Date Fri, 12 Mar 2010 18:26:46 GMT
Author: mahadev
Date: Fri Mar 12 18:26:45 2010
New Revision: 922377

URL: http://svn.apache.org/viewvc?rev=922377&view=rev
Log:
ZOOKEEPER-601. allow configuration of session timeout min/max bounds (phunt via mahadev)

Added:
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumZooKeeperServer.java
Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerConfig.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LearnerZooKeeperServer.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerMXBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/ObserverZooKeeperServer.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SessionTest.java

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Fri Mar 12 18:26:45 2010
@@ -355,6 +355,9 @@ IMPROVEMENTS:
 
   ZOOKEEPER-692. upgrade junit to latest version (4.8.1) (phunt via mahadev)
 
+  ZOOKEEPER-601. allow configuration of session timeout min/max bounds (phunt
+  via mahadev)
+
 NEW FEATURES:
   ZOOKEEPER-539. generate eclipse project via ant target. (phunt via mahadev)
 

Modified: hadoop/zookeeper/trunk/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml (original)
+++ hadoop/zookeeper/trunk/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml Fri Mar 12 18:26:45 2010
@@ -162,7 +162,7 @@
           <para>Create a configuration file. This file can be called anything.
           Use the following settings as a starting point:</para>
 
-          <para><computeroutput>
+          <programlisting>
 tickTime=2000
 dataDir=/var/zookeeper/
 clientPort=2181
@@ -170,7 +170,7 @@ initLimit=5
 syncLimit=2
 server.1=zoo1:2888:3888
 server.2=zoo2:2888:3888
-server.3=zoo3:2888:3888</computeroutput></para>
+server.3=zoo3:2888:3888</programlisting>
 
           <para>You can find the meanings of these and other configuration
           settings in the section <xref linkend="sc_configuration" />. A word
@@ -185,7 +185,9 @@ server.3=zoo3:2888:3888</computeroutput>
           server id to each machine by creating a file named
           <filename>myid</filename>, one for each server, which resides in
           that server's data directory, as specified by the configuration file
-          parameter <emphasis role="bold">dataDir</emphasis>. The myid file
+          parameter <emphasis role="bold">dataDir</emphasis>.</para></listitem>
+
+          <listitem><para>The myid file
           consists of a single line containing only the text of that machine's
           id. So <filename>myid</filename> of server 1 would contain the text
           "1" and nothing else. The id must be unique within the
@@ -738,7 +740,7 @@ server.3=zoo3:2888:3888</computeroutput>
              <term>clientPortBindAddress</term>
 
              <listitem>
-               <para><emphasis role="bold">New in 3.3:</emphasis> the
+               <para><emphasis role="bold">New in 3.3.0:</emphasis> the
                address (ipv4, ipv6 or hostname) to listen for client
                connections; that is, the address that clients attempt
                to connect to. This is optional, by default we bind in
@@ -749,6 +751,29 @@ server.3=zoo3:2888:3888</computeroutput>
              </listitem>
            </varlistentry>
 
+          <varlistentry>
+            <term>minSessionTimeout</term>
+            <listitem>
+              <para>(No Java system property)</para>
+
+              <para><emphasis role="bold">New in 3.3.0:</emphasis> the
+              minimum session timeout in milliseconds that the server
+              will allow the client to negotiate. Defaults to 2 times
+              the <emphasis role="bold">tickTime</emphasis>.</para>
+            </listitem>
+           </varlistentry>
+
+          <varlistentry>
+            <term>maxSessionTimeout</term>
+            <listitem>
+              <para>(No Java system property)</para>
+
+              <para><emphasis role="bold">New in 3.3.0:</emphasis> the
+              maximum session timeout in milliseconds that the server
+              will allow the client to negotiate. Defaults to 20 times
+              the <emphasis role="bold">tickTime</emphasis>.</para>
+            </listitem>
+           </varlistentry>
         </variablelist>
       </section>
 
@@ -1007,13 +1032,24 @@ server.3=zoo3:2888:3888</computeroutput>
 
       <variablelist>
         <varlistentry>
+          <term>conf</term>
+
+          <listitem>
+            <para><emphasis role="bold">New in 3.3.0:</emphasis> Print
+            details about serving configuration.</para>
+          </listitem>
+
+        </varlistentry>
+
+        <varlistentry>
           <term>cons</term>
 
           <listitem>
-            <para>List full connection/session details for all clients
-            connected to this server. Includes information on numbers
-            of packets received/sent, session id, operation latencies,
-            last operation performed, etc...</para>
+            <para><emphasis role="bold">New in 3.3.0:</emphasis> List
+            full connection/session details for all clients connected
+            to this server. Includes information on numbers of packets
+            received/sent, session id, operation latencies, last
+            operation performed, etc...</para>
           </listitem>
 
         </varlistentry>
@@ -1022,7 +1058,8 @@ server.3=zoo3:2888:3888</computeroutput>
           <term>crst</term>
 
           <listitem>
-            <para>Reset connection/session statistics for all connections.</para>
+            <para><emphasis role="bold">New in 3.3.0:</emphasis> Reset
+            connection/session statistics for all connections.</para>
           </listitem>
         </varlistentry>
 
@@ -1070,7 +1107,8 @@ server.3=zoo3:2888:3888</computeroutput>
           <term>srvr</term>
 
           <listitem>
-            <para>Lists full details for the server.</para>
+            <para><emphasis role="bold">New in 3.3.0:</emphasis> Lists
+            full details for the server.</para>
           </listitem>
         </varlistentry>
 
@@ -1087,7 +1125,8 @@ server.3=zoo3:2888:3888</computeroutput>
           <term>wchs</term>
 
           <listitem>
-            <para>Lists brief information on watches for the server.</para>
+            <para><emphasis role="bold">New in 3.3.0:</emphasis> Lists
+            brief information on watches for the server.</para>
           </listitem>
         </varlistentry>
 
@@ -1095,10 +1134,12 @@ server.3=zoo3:2888:3888</computeroutput>
           <term>wchc</term>
 
           <listitem>
-            <para>Lists detailed information on watches for the server, by session.
-            This outputs a list of sessions(connections) with associated watches
-            (paths). Note, depending on the number of watches this operation may be
-            expensive (ie impact server performance), use it carefully.</para>
+            <para><emphasis role="bold">New in 3.3.0:</emphasis> Lists
+            detailed information on watches for the server, by
+            session.  This outputs a list of sessions(connections)
+            with associated watches (paths). Note, depending on the
+            number of watches this operation may be expensive (ie
+            impact server performance), use it carefully.</para>
           </listitem>
         </varlistentry>
 
@@ -1106,10 +1147,12 @@ server.3=zoo3:2888:3888</computeroutput>
           <term>wchp</term>
 
           <listitem>
-            <para>Lists detailed information on watches for the server, by path.
-            This outputs a list of paths (znodes) with associated sessions. Note,
-            depending on the number of watches this operation may be expensive
-            (ie impact server performance), use it carefully.</para>
+            <para><emphasis role="bold">New in 3.3.0:</emphasis> Lists
+            detailed information on watches for the server, by path.
+            This outputs a list of paths (znodes) with associated
+            sessions. Note, depending on the number of watches this
+            operation may be expensive (ie impact server performance),
+            use it carefully.</para>
           </listitem>
         </varlistentry>
       </variablelist>

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java Fri Mar 12 18:26:45 2010
@@ -115,7 +115,6 @@ public class NIOServerCnxn implements Wa
 
         int maxClientCnxns = 10;
 
-
         /**
          * Construct a new server connection factory which will accept an unlimited number
          * of concurrent connections from each client (up to the file descriptor
@@ -185,6 +184,10 @@ public class NIOServerCnxn implements Wa
             return ss.socket().getLocalPort();
         }
 
+        public int getMaxClientCnxns() {
+            return maxClientCnxns;
+        }
+
         private void addCnxn(NIOServerCnxn cnxn) {
             synchronized (cnxns) {
                 cnxns.add(cnxn);
@@ -354,6 +357,10 @@ public class NIOServerCnxn implements Wa
 
     final Factory factory;
 
+    /** The ZooKeeperServer for this connection. May be null if the server
+     * is not currently serving requests (for example if the server is not
+     * an active quorum participant.
+     */
     private final ZooKeeperServer zk;
 
     private SocketChannel sock;
@@ -719,11 +726,13 @@ public class NIOServerCnxn implements Wa
         }
         sessionTimeout = connReq.getTimeOut();
         byte passwd[] = connReq.getPasswd();
-        if (sessionTimeout < zk.tickTime * 2) {
-            sessionTimeout = zk.tickTime * 2;
-        }
-        if (sessionTimeout > zk.tickTime * 20) {
-            sessionTimeout = zk.tickTime * 20;
+        int minSessionTimeout = zk.getMinSessionTimeout();
+        if (sessionTimeout < minSessionTimeout) {
+            sessionTimeout = minSessionTimeout;
+        }
+        int maxSessionTimeout = zk.getMaxSessionTimeout();
+        if (sessionTimeout > maxSessionTimeout) {
+            sessionTimeout = maxSessionTimeout;
         }
         // We don't want to receive any packets until we are sure that the
         // session is setup
@@ -762,6 +771,13 @@ public class NIOServerCnxn implements Wa
      * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
      * Zk Admin</a>. this link is for all the commands.
      */
+    private final static int confCmd =
+        ByteBuffer.wrap("conf".getBytes()).getInt();
+
+    /*
+     * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
+     * Zk Admin</a>. this link is for all the commands.
+     */
     private final static int consCmd =
         ByteBuffer.wrap("cons".getBytes()).getInt();
 
@@ -853,6 +869,7 @@ public class NIOServerCnxn implements Wa
 
     // specify all of the commands that are available
     static {
+        cmd2String.put(confCmd, "conf");
         cmd2String.put(consCmd, "cons");
         cmd2String.put(crstCmd, "crst");
         cmd2String.put(dumpCmd, "dump");
@@ -984,6 +1001,13 @@ public class NIOServerCnxn implements Wa
                     pwriter.println(e.getValue());
                 }
                 return true;
+            } else if (len == confCmd) {
+                if (zk == null) {
+                    pwriter.println(ZK_NOT_SERVING);
+                    return true;
+                }
+                zk.dumpConf(pwriter);
+                return true;
             } else if (len == srstCmd) {
                 if (zk == null) {
                     pwriter.println(ZK_NOT_SERVING);

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerConfig.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerConfig.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerConfig.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerConfig.java Fri Mar 12 18:26:45 2010
@@ -31,11 +31,19 @@ import org.apache.zookeeper.server.quoru
  *
  */
 public class ServerConfig {
+    ////
+    //// If you update the configuration parameters be sure
+    //// to update the "conf" 4letter word
+    ////
     protected InetSocketAddress clientPortAddress;
     protected String dataDir;
     protected String dataLogDir;
     protected int tickTime = ZooKeeperServer.DEFAULT_TICK_TIME;
     protected int maxClientCnxns;
+    /** defaults to -1 if not set explicitly */
+    protected int minSessionTimeout = -1;
+    /** defaults to -1 if not set explicitly */
+    protected int maxSessionTimeout = -1;
 
     /**
      * Parse arguments for server configuration
@@ -85,6 +93,8 @@ public class ServerConfig {
       dataLogDir = config.getDataLogDir();
       tickTime = config.getTickTime();
       maxClientCnxns = config.getMaxClientCnxns();
+      minSessionTimeout = config.getMinSessionTimeout();
+      maxSessionTimeout = config.getMaxSessionTimeout();
     }
 
     public InetSocketAddress getClientPortAddress() {
@@ -94,4 +104,8 @@ public class ServerConfig {
     public String getDataLogDir() { return dataLogDir; }
     public int getTickTime() { return tickTime; }
     public int getMaxClientCnxns() { return maxClientCnxns; }
+    /** minimum session timeout in milliseconds, -1 if unset */
+    public int getMinSessionTimeout() { return minSessionTimeout; }
+    /** maximum session timeout in milliseconds, -1 if unset */
+    public int getMaxSessionTimeout() { return maxSessionTimeout; }
 }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java Fri Mar 12 18:26:45 2010
@@ -87,6 +87,10 @@ public class ZooKeeperServer implements 
 
     public static final int DEFAULT_TICK_TIME = 3000;
     protected int tickTime = DEFAULT_TICK_TIME;
+    /** value of -1 indicates unset, use default */
+    protected int minSessionTimeout = -1;
+    /** value of -1 indicates unset, use default */
+    protected int maxSessionTimeout = -1;
     protected SessionTracker sessionTracker;
     private FileTxnSnapLog txnLogFactory = null;
     private ConcurrentHashMap<Long, Integer> sessionsWithTimeouts;
@@ -134,15 +138,21 @@ public class ZooKeeperServer implements 
      * @param dataDir the directory to put the data
      * @throws IOException
      */
-    public ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime, 
+    public ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime,
+            int minSessionTimeout, int maxSessionTimeout,
             DataTreeBuilder treeBuilder, ZKDatabase zkDb) throws IOException {
         serverStats = new ServerStats(this);
         this.txnLogFactory = txnLogFactory;
         this.zkDb = zkDb;
         this.tickTime = tickTime;
+        this.minSessionTimeout = minSessionTimeout;
+        this.maxSessionTimeout = maxSessionTimeout;
         
-        LOG.info("Created server with tickTime " + tickTime + " datadir " + 
-                txnLogFactory.getDataDir() + " snapdir " + txnLogFactory.getSnapDir());
+        LOG.info("Created server with tickTime " + tickTime
+                + " minSessionTimeout " + getMinSessionTimeout()
+                + " maxSessionTimeout " + getMaxSessionTimeout()
+                + " datadir " + txnLogFactory.getDataDir()
+                + " snapdir " + txnLogFactory.getSnapDir());
     }
 
     /**
@@ -154,13 +164,34 @@ public class ZooKeeperServer implements 
      */
     public ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime,
             DataTreeBuilder treeBuilder) throws IOException {
-        this(txnLogFactory, tickTime, treeBuilder, new ZKDatabase(txnLogFactory));
+        this(txnLogFactory, tickTime, -1, -1, treeBuilder,
+                new ZKDatabase(txnLogFactory));
     }
     
     public ServerStats serverStats() {
         return serverStats;
     }
-    
+
+    public void dumpConf(PrintWriter pwriter) {
+        pwriter.print("clientPort=");
+        pwriter.println(getClientPort());
+        pwriter.print("dataDir=");
+        pwriter.println(zkDb.snapLog.getSnapDir().getAbsolutePath());
+        pwriter.print("dataLogDir=");
+        pwriter.println(zkDb.snapLog.getDataDir().getAbsolutePath());
+        pwriter.print("tickTime=");
+        pwriter.println(getTickTime());
+        pwriter.print("maxClientCnxns=");
+        pwriter.println(serverCnxnFactory.getMaxClientCnxns());
+        pwriter.print("minSessionTimeout=");
+        pwriter.println(getMinSessionTimeout());
+        pwriter.print("maxSessionTimeout=");
+        pwriter.println(getMaxSessionTimeout());
+
+        pwriter.print("serverId=");
+        pwriter.println(getServerId());
+    }
+
     /**
      * This constructor is for backward compatibility with the existing unit
      * test code.
@@ -169,7 +200,7 @@ public class ZooKeeperServer implements 
     public ZooKeeperServer(File snapDir, File logDir, int tickTime)
             throws IOException {
         this( new FileTxnSnapLog(snapDir, logDir),
-                tickTime,new BasicDataTreeBuilder());
+                tickTime, new BasicDataTreeBuilder());
     }
 
     /**
@@ -177,8 +208,12 @@ public class ZooKeeperServer implements 
      *
      * @throws IOException
      */
-    public ZooKeeperServer(FileTxnSnapLog txnLogFactory,DataTreeBuilder treeBuilder) throws IOException {
-        this(txnLogFactory, DEFAULT_TICK_TIME, treeBuilder, new ZKDatabase(txnLogFactory));
+    public ZooKeeperServer(FileTxnSnapLog txnLogFactory,
+            DataTreeBuilder treeBuilder)
+        throws IOException
+    {
+        this(txnLogFactory, DEFAULT_TICK_TIME, -1, -1, treeBuilder,
+                new ZKDatabase(txnLogFactory));
     }
 
     /**
@@ -622,9 +657,28 @@ public class ZooKeeperServer implements 
     }
 
     public void setTickTime(int tickTime) {
+        LOG.info("tickTime set to " + tickTime);
         this.tickTime = tickTime;
     }
 
+    public int getMinSessionTimeout() {
+        return minSessionTimeout == -1 ? tickTime * 2 : minSessionTimeout;
+    }
+
+    public void setMinSessionTimeout(int min) {
+        LOG.info("minSessionTimeout set to " + min);
+        this.minSessionTimeout = min;
+    }
+
+    public int getMaxSessionTimeout() {
+        return maxSessionTimeout == -1 ? tickTime * 20 : maxSessionTimeout;
+    }
+
+    public void setMaxSessionTimeout(int max) {
+        LOG.info("maxSessionTimeout set to " + max);
+        this.maxSessionTimeout = max;
+    }
+
     public int getClientPort() {
         return serverCnxnFactory != null ? serverCnxnFactory.ss.socket().getLocalPort() : -1;
     }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java Fri Mar 12 18:26:45 2010
@@ -89,6 +89,35 @@ public class ZooKeeperServerBean impleme
         zks.setTickTime(tickTime);
     }
 
+    public int getMaxClientCnxnsPerHost() {
+        NIOServerCnxn.Factory fac = zks.getServerCnxnFactory();
+        if (fac == null) {
+            return -1;
+        }
+        return fac.getMaxClientCnxns();
+    }
+
+    public void setMaxClientCnxnsPerHost(int max) {
+        // if fac is null the exception will be propagated to the client
+        zks.getServerCnxnFactory().maxClientCnxns = max;
+    }
+
+    public int getMinSessionTimeout() {
+        return zks.getMinSessionTimeout();
+    }
+
+    public void setMinSessionTimeout(int min) {
+        zks.setMinSessionTimeout(min);
+    }
+
+    public int getMaxSessionTimeout() {
+        return zks.getMaxSessionTimeout();
+    }
+
+    public void setMaxSessionTimeout(int max) {
+        zks.setMaxSessionTimeout(max);
+    }
+
     
     public long getPacketsReceived() {
         return zks.serverStats().getPacketsReceived();

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java Fri Mar 12 18:26:45 2010
@@ -59,14 +59,38 @@ public interface ZooKeeperServerMXBean {
      */
     public long getOutstandingRequests();
     /**
-     * Current TickTime of server
+     * Current TickTime of server in milliseconds
      */
     public int getTickTime();
     /**
-     * Set TickTime of server
+     * Set TickTime of server in milliseconds
      */
     public void setTickTime(int tickTime);
 
+    /** Current maxClientCnxns allowed from a particular host */
+    public int getMaxClientCnxnsPerHost();
+
+    /** Set maxClientCnxns allowed from a particular host */
+    public void setMaxClientCnxnsPerHost(int max);
+
+    /**
+     * Current minSessionTimeout of the server in milliseconds
+     */
+    public int getMinSessionTimeout();
+    /**
+     * Set minSessionTimeout of server in milliseconds
+     */
+    public void setMinSessionTimeout(int min);
+
+    /**
+     * Current maxSessionTimeout of the server in milliseconds
+     */
+    public int getMaxSessionTimeout();
+    /**
+     * Set maxSessionTimeout of server in milliseconds
+     */
+    public void setMaxSessionTimeout(int max);
+
     /**
      * Reset packet and latency statistics 
      */

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java Fri Mar 12 18:26:45 2010
@@ -103,8 +103,10 @@ public class ZooKeeperServerMain {
                    File(config.dataLogDir), new File(config.dataDir));
             zkServer.setTxnLogFactory(ftxn);
             zkServer.setTickTime(config.tickTime);
-            cnxnFactory = new NIOServerCnxn.Factory(
-                    config.getClientPortAddress(), config.getMaxClientCnxns());
+            zkServer.setMinSessionTimeout(config.minSessionTimeout);
+            zkServer.setMaxSessionTimeout(config.maxSessionTimeout);
+            cnxnFactory = new NIOServerCnxn.Factory(config.getClientPortAddress(),
+                    config.getMaxClientCnxns());
             cnxnFactory.startup(zkServer);
             cnxnFactory.join();
             if (zkServer.isRunning()) {

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java Fri Mar 12 18:26:45 2010
@@ -40,7 +40,8 @@ import org.apache.zookeeper.txn.TxnHeade
  * A SyncRequestProcessor is also spawned off to log proposals from the leader.
  */
 public class FollowerZooKeeperServer extends LearnerZooKeeperServer {
-    private static final Logger LOG = Logger.getLogger(FollowerZooKeeperServer.class);
+    private static final Logger LOG =
+        Logger.getLogger(FollowerZooKeeperServer.class);
 
     CommitProcessor commitProcessor;
 
@@ -58,8 +59,8 @@ public class FollowerZooKeeperServer ext
      */
     FollowerZooKeeperServer(FileTxnSnapLog logFactory,QuorumPeer self,
             DataTreeBuilder treeBuilder, ZKDatabase zkDb) throws IOException {
-        super(logFactory, self.tickTime,treeBuilder, zkDb);
-        this.self = self;        
+        super(logFactory, self.tickTime, self.minSessionTimeout,
+                self.maxSessionTimeout, treeBuilder, zkDb, self);
         this.pendingSyncs = new ConcurrentLinkedQueue<Request>();
     }
 

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java Fri Mar 12 18:26:45 2010
@@ -29,7 +29,6 @@ import org.apache.zookeeper.server.Reque
 import org.apache.zookeeper.server.ServerCnxn;
 import org.apache.zookeeper.server.SessionTrackerImpl;
 import org.apache.zookeeper.server.ZKDatabase;
-import org.apache.zookeeper.server.ZooKeeperServer;
 import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
 
 /**
@@ -39,9 +38,7 @@ import org.apache.zookeeper.server.persi
  * CommitProcessor -> Leader.ToBeAppliedRequestProcessor ->
  * FinalRequestProcessor
  */
-public class LeaderZooKeeperServer extends ZooKeeperServer {
-    private QuorumPeer self;
-    
+public class LeaderZooKeeperServer extends QuorumZooKeeperServer {
     CommitProcessor commitProcessor;
 
     /**
@@ -49,10 +46,10 @@ public class LeaderZooKeeperServer exten
      * @param dataDir
      * @throws IOException
      */
-    LeaderZooKeeperServer(FileTxnSnapLog logFactory,QuorumPeer self,
+    LeaderZooKeeperServer(FileTxnSnapLog logFactory, QuorumPeer self,
             DataTreeBuilder treeBuilder, ZKDatabase zkDb) throws IOException {
-        super(logFactory, self.tickTime,treeBuilder, zkDb);
-        this.self = self;
+        super(logFactory, self.tickTime, self.minSessionTimeout,
+                self.maxSessionTimeout, treeBuilder, zkDb, self);
     }
 
     public Leader getLeader(){
@@ -155,6 +152,15 @@ public class LeaderZooKeeperServer exten
         return "leader";
     }
 
+    /**
+     * Returns the id of the associated QuorumPeer, which will do for a unique
+     * id of this server. 
+     */
+    @Override
+    public long getServerId() {
+        return self.getId();
+    }    
+    
     @Override
     protected void revalidateSession(ServerCnxn cnxn, long sessionId,
         int sessionTimeout) throws IOException, InterruptedException {

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LearnerZooKeeperServer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LearnerZooKeeperServer.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LearnerZooKeeperServer.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LearnerZooKeeperServer.java Fri Mar 12 18:26:45 2010
@@ -22,23 +22,22 @@ import java.util.HashMap;
 
 import org.apache.zookeeper.jmx.MBeanRegistry;
 import org.apache.zookeeper.server.DataTreeBean;
-import org.apache.zookeeper.server.Request;
 import org.apache.zookeeper.server.ServerCnxn;
 import org.apache.zookeeper.server.ZKDatabase;
-import org.apache.zookeeper.server.ZooKeeperServer;
 import org.apache.zookeeper.server.ZooKeeperServerBean;
 import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
 
 /**
  * Parent class for all ZooKeeperServers for Learners 
  */
-public abstract class LearnerZooKeeperServer extends ZooKeeperServer {    
-    
-    protected QuorumPeer self;
-    
+public abstract class LearnerZooKeeperServer extends QuorumZooKeeperServer {    
     public LearnerZooKeeperServer(FileTxnSnapLog logFactory, int tickTime,
-            DataTreeBuilder treeBuilder, ZKDatabase zkDb) throws IOException {
-        super(logFactory,tickTime,treeBuilder, zkDb);
+            int minSessionTimeout, int maxSessionTimeout,
+            DataTreeBuilder treeBuilder, ZKDatabase zkDb, QuorumPeer self)
+        throws IOException
+    {
+        super(logFactory, tickTime, minSessionTimeout, maxSessionTimeout,
+                treeBuilder, zkDb, self);
     }
 
     /**
@@ -65,6 +64,7 @@ public abstract class LearnerZooKeeperSe
      * Returns the id of the associated QuorumPeer, which will do for a unique
      * id of this server. 
      */
+    @Override
     public long getServerId() {
         return self.getId();
     }    

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerBean.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerBean.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerBean.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerBean.java Fri Mar 12 18:26:45 2010
@@ -18,6 +18,7 @@
 
 package org.apache.zookeeper.server.quorum;
 
+import org.apache.zookeeper.server.NIOServerCnxn;
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 
 /**
@@ -42,6 +43,22 @@ public class LocalPeerBean extends Serve
         return peer.getTickTime();
     }
     
+    public int getMaxClientCnxnsPerHost() {
+        NIOServerCnxn.Factory fac = peer.getCnxnFactory();
+        if (fac == null) {
+            return -1;
+        }
+        return fac.getMaxClientCnxns();
+    }
+
+    public int getMinSessionTimeout() {
+        return peer.getMinSessionTimeout();
+    }
+    
+    public int getMaxSessionTimeout() {
+        return peer.getMaxSessionTimeout();
+    }
+    
     public int getInitLimit() {
         return peer.getInitLimit();
     }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerMXBean.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerMXBean.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerMXBean.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerMXBean.java Fri Mar 12 18:26:45 2010
@@ -31,6 +31,19 @@ public interface LocalPeerMXBean extends
      */
     public int getTickTime();
     
+    /** Current maxClientCnxns allowed from a particular host */
+    public int getMaxClientCnxnsPerHost();
+
+    /**
+     * @return the minimum number of milliseconds allowed for a session timeout
+     */
+    public int getMinSessionTimeout();
+    
+    /**
+     * @return the maximum number of milliseconds allowed for a session timeout
+     */
+    public int getMaxSessionTimeout();
+    
     /**
      * @return the number of ticks that the initial sync phase can take
      */

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/ObserverZooKeeperServer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/ObserverZooKeeperServer.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/ObserverZooKeeperServer.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/ObserverZooKeeperServer.java Fri Mar 12 18:26:45 2010
@@ -34,7 +34,8 @@ import org.apache.zookeeper.server.persi
  *
  */
 public class ObserverZooKeeperServer extends LearnerZooKeeperServer {
-    private static final Logger LOG = Logger.getLogger(ObserverZooKeeperServer.class);        
+    private static final Logger LOG =
+        Logger.getLogger(ObserverZooKeeperServer.class);        
     
     /*
      * Request processors
@@ -50,8 +51,8 @@ public class ObserverZooKeeperServer ext
         
     ObserverZooKeeperServer(FileTxnSnapLog logFactory, QuorumPeer self,
             DataTreeBuilder treeBuilder, ZKDatabase zkDb) throws IOException {
-        super(logFactory, self.tickTime, treeBuilder, zkDb);
-        this.self = self;        
+        super(logFactory, self.tickTime, self.minSessionTimeout,
+                self.maxSessionTimeout, treeBuilder, zkDb, self);
     }
     
     public Observer getObserver() {

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java Fri Mar 12 18:26:45 2010
@@ -202,23 +202,35 @@ public class QuorumPeer extends Thread i
     /**
      * The number of milliseconds of each tick
      */
-    int tickTime;
+    protected int tickTime;
+
+    /**
+     * Minimum number of milliseconds to allow for session timeout.
+     * A value of -1 indicates unset, use default.
+     */
+    protected int minSessionTimeout = -1;
+
+    /**
+     * Maximum number of milliseconds to allow for session timeout.
+     * A value of -1 indicates unset, use default.
+     */
+    protected int maxSessionTimeout = -1;
 
     /**
      * The number of ticks that the initial synchronization phase can take
      */
-    int initLimit;
+    protected int initLimit;
 
     /**
      * The number of ticks that can pass between sending a request and getting
      * an acknowledgment
      */
-    int syncLimit;
+    protected int syncLimit;
 
     /**
      * The current tick
      */
-    int tick;
+    protected int tick;
 
     /**
      * This class simply responds to requests for the current leader of this
@@ -788,9 +800,32 @@ public class QuorumPeer extends Thread i
      * Set the number of milliseconds of each tick
      */
     public void setTickTime(int tickTime) {
+        LOG.info("tickTime set to " + tickTime);
         this.tickTime = tickTime;
     }
 
+    /** minimum session timeout in milliseconds */
+    public int getMinSessionTimeout() {
+        return minSessionTimeout == -1 ? tickTime * 2 : minSessionTimeout;
+    }
+
+    /** minimum session timeout in milliseconds */
+    public void setMinSessionTimeout(int min) {
+        LOG.info("minSessionTimeout set to " + min);
+        this.minSessionTimeout = min;
+    }
+
+    /** maximum session timeout in milliseconds */
+    public int getMaxSessionTimeout() {
+        return maxSessionTimeout == -1 ? tickTime * 20 : maxSessionTimeout;
+    }
+
+    /** minimum session timeout in milliseconds */
+    public void setMaxSessionTimeout(int max) {
+        LOG.info("maxSessionTimeout set to " + max);
+        this.maxSessionTimeout = max;
+    }
+
     /**
      * Get the number of ticks that the initial synchronization phase can take
      */
@@ -802,6 +837,7 @@ public class QuorumPeer extends Thread i
      * Set the number of ticks that the initial synchronization phase can take
      */
     public void setInitLimit(int initLimit) {
+        LOG.info("initLimit set to " + initLimit);
         this.initLimit = initLimit;
     }
 

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java Fri Mar 12 18:26:45 2010
@@ -33,11 +33,11 @@ import java.util.Map.Entry;
 
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.server.ZooKeeperServer;
-import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
 import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType;
-import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
-import org.apache.zookeeper.server.quorum.flexible.QuorumMaj;
+import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
 import org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical;
+import org.apache.zookeeper.server.quorum.flexible.QuorumMaj;
+import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
 
 public class QuorumPeerConfig {
     private static final Logger LOG = Logger.getLogger(QuorumPeerConfig.class);
@@ -46,12 +46,16 @@ public class QuorumPeerConfig {
     protected String dataDir;
     protected String dataLogDir;
     protected int tickTime = ZooKeeperServer.DEFAULT_TICK_TIME;
+    protected int maxClientCnxns = 10;
+    /** defaults to -1 if not set explicitly */
+    protected int minSessionTimeout = -1;
+    /** defaults to -1 if not set explicitly */
+    protected int maxSessionTimeout = -1;
 
     protected int initLimit;
     protected int syncLimit;
     protected int electionAlg = 3;
     protected int electionPort = 2182;
-    protected int maxClientCnxns = 10;
     protected final HashMap<Long,QuorumServer> servers =
         new HashMap<Long, QuorumServer>();
     protected final HashMap<Long,QuorumServer> observers =
@@ -130,14 +134,18 @@ public class QuorumPeerConfig {
                 clientPortAddress = value.trim();
             } else if (key.equals("tickTime")) {
                 tickTime = Integer.parseInt(value);
+            } else if (key.equals("maxClientCnxns")) {
+                maxClientCnxns = Integer.parseInt(value);
+            } else if (key.equals("minSessionTimeout")) {
+                minSessionTimeout = Integer.parseInt(value);
+            } else if (key.equals("maxSessionTimeout")) {
+                maxSessionTimeout = Integer.parseInt(value);
             } else if (key.equals("initLimit")) {
                 initLimit = Integer.parseInt(value);
             } else if (key.equals("syncLimit")) {
                 syncLimit = Integer.parseInt(value);
             } else if (key.equals("electionAlg")) {
                 electionAlg = Integer.parseInt(value);
-            } else if (key.equals("maxClientCnxns")) {
-                maxClientCnxns = Integer.parseInt(value);
             } else if (key.equals("peerType")) {
                 if (value.toLowerCase().equals("observer")) {
                     peerType = LearnerType.OBSERVER;
@@ -229,6 +237,10 @@ public class QuorumPeerConfig {
         if (tickTime == 0) {
             throw new IllegalArgumentException("tickTime is not set");
         }
+        if (minSessionTimeout > maxSessionTimeout) {
+            throw new IllegalArgumentException(
+                    "minSessionTimeout must not be larger than maxSessionTimeout");
+        }
         if (servers.size() > 1) {
             if (initLimit == 0) {
                 throw new IllegalArgumentException("initLimit is not set");
@@ -305,14 +317,16 @@ public class QuorumPeerConfig {
     public String getDataDir() { return dataDir; }
     public String getDataLogDir() { return dataLogDir; }
     public int getTickTime() { return tickTime; }
+    public int getMaxClientCnxns() { return maxClientCnxns; }
+    public int getMinSessionTimeout() { return minSessionTimeout; }
+    public int getMaxSessionTimeout() { return maxSessionTimeout; }
 
     public int getInitLimit() { return initLimit; }
     public int getSyncLimit() { return syncLimit; }
     public int getElectionAlg() { return electionAlg; }
-    public int getElectionPort() { return electionPort; }
-    public int getMaxClientCnxns() { return maxClientCnxns; }
-
-    public QuorumVerifier getQuorumVerifier() {
+    public int getElectionPort() { return electionPort; }    
+    
+    public QuorumVerifier getQuorumVerifier() {   
         return quorumVerifier;
     }
 

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java Fri Mar 12 18:26:45 2010
@@ -131,6 +131,8 @@ public class QuorumPeerMain {
           quorumPeer.setElectionType(config.getElectionAlg());
           quorumPeer.setMyid(config.getServerId());
           quorumPeer.setTickTime(config.getTickTime());
+          quorumPeer.setMinSessionTimeout(config.getMinSessionTimeout());
+          quorumPeer.setMaxSessionTimeout(config.getMaxSessionTimeout());
           quorumPeer.setInitLimit(config.getInitLimit());
           quorumPeer.setSyncLimit(config.getSyncLimit());
           quorumPeer.setQuorumVerifier(config.getQuorumVerifier());

Added: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumZooKeeperServer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumZooKeeperServer.java?rev=922377&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumZooKeeperServer.java (added)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumZooKeeperServer.java Fri Mar 12 18:26:45 2010
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zookeeper.server.quorum;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.apache.zookeeper.server.ZKDatabase;
+import org.apache.zookeeper.server.ZooKeeperServer;
+import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
+
+/**
+ * Abstract base class for all ZooKeeperServers that participate in
+ * a quorum.
+ */
+public abstract class QuorumZooKeeperServer extends ZooKeeperServer {
+    protected final QuorumPeer self;
+
+    protected QuorumZooKeeperServer(FileTxnSnapLog logFactory, int tickTime,
+            int minSessionTimeout, int maxSessionTimeout,
+            DataTreeBuilder treeBuilder, ZKDatabase zkDb, QuorumPeer self)
+        throws IOException
+    {
+        super(logFactory, tickTime, minSessionTimeout, maxSessionTimeout,
+                treeBuilder, zkDb);
+        this.self = self;
+    }
+
+    @Override
+    public void dumpConf(PrintWriter pwriter) {
+        super.dumpConf(pwriter);
+
+        pwriter.print("initLimit=");
+        pwriter.println(self.getInitLimit());
+        pwriter.print("syncLimit=");
+        pwriter.println(self.getSyncLimit());
+        pwriter.print("electionAlg=");
+        pwriter.println(self.getElectionType());
+        pwriter.print("electionPort=");
+        pwriter.println(self.quorumPeers.get(self.getId()).electionAddr
+                .getPort());
+        pwriter.print("quorumPort=");
+        pwriter.println(self.quorumPeers.get(self.getId()).addr.getPort());
+        pwriter.print("peerType=");
+        pwriter.println(self.getPeerType().ordinal());
+    }
+}

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java Fri Mar 12 18:26:45 2010
@@ -29,14 +29,14 @@ public class FourLetterWordsQuorumTest e
     protected static final Logger LOG =
         Logger.getLogger(FourLetterWordsQuorumTest.class);
 
-    /** Test the various four letter words
-     * ruok,envi,stat,srvr,cons,dump,srst,crst */
+    /** Test the various four letter words */
     @Test
     public void testFourLetterWords() throws Exception {
         String servers[] = hostPort.split(",");
         for (String hp : servers) {
             verify(hp, "ruok", "imok");
             verify(hp, "envi", "java.version");
+            verify(hp, "conf", "clientPort");
             verify(hp, "stat", "Outstanding");
             verify(hp, "srvr", "Outstanding");
             verify(hp, "cons", "queued");
@@ -74,6 +74,7 @@ public class FourLetterWordsQuorumTest e
 
             verify(hp, "ruok", "imok");
             verify(hp, "envi", "java.version");
+            verify(hp, "conf", "clientPort");
             verify(hp, "stat", "Outstanding");
             verify(hp, "srvr", "Outstanding");
             verify(hp, "cons", "queued");

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java Fri Mar 12 18:26:45 2010
@@ -28,12 +28,12 @@ public class FourLetterWordsTest extends
     protected static final Logger LOG =
         Logger.getLogger(FourLetterWordsTest.class);
 
-    /** Test the various four letter words
-     * ruok,envi,stat,srvr,cons,dump,srst,crst */
+    /** Test the various four letter words */
     @Test
     public void testFourLetterWords() throws Exception {
         verify("ruok", "imok");
         verify("envi", "java.version");
+        verify("conf", "clientPort");
         verify("stat", "Outstanding");
         verify("srvr", "Outstanding");
         verify("cons", "queued");
@@ -71,6 +71,7 @@ public class FourLetterWordsTest extends
 
         verify("ruok", "imok");
         verify("envi", "java.version");
+        verify("conf", "clientPort");
         verify("stat", "Outstanding");
         verify("srvr", "Outstanding");
         verify("cons", "queued");

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SessionTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SessionTest.java?rev=922377&r1=922376&r2=922377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SessionTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SessionTest.java Fri Mar 12 18:26:45 2010
@@ -333,4 +333,36 @@ public class SessionTest extends TestCas
         }
     }
 
+    @Test
+    public void testMinMaxSessionTimeout() throws Exception {
+        // override the defaults
+        final int MINSESS = 20000;
+        final int MAXSESS = 240000;
+        ZooKeeperServer zs = serverFactory.getZooKeeperServer();
+        zs.setMinSessionTimeout(MINSESS);
+        zs.setMaxSessionTimeout(MAXSESS);
+
+        // validate typical case - requested == negotiated
+        int timeout = 120000;
+        DisconnectableZooKeeper zk = createClient(timeout);
+        assertEquals(timeout, zk.getSessionTimeout());
+        // make sure tostring works in both cases
+        LOG.info(zk.toString());
+        zk.close();
+        LOG.info(zk.toString());
+
+        // validate lower limit
+        zk = createClient(MINSESS/2);
+        assertEquals(MINSESS, zk.getSessionTimeout());
+        LOG.info(zk.toString());
+        zk.close();
+        LOG.info(zk.toString());
+
+        // validate upper limit
+        zk = createClient(MAXSESS * 2);
+        assertEquals(MAXSESS, zk.getSessionTimeout());
+        LOG.info(zk.toString());
+        zk.close();
+        LOG.info(zk.toString());
+    }
 }



Mime
View raw message