You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ma...@apache.org on 2010/03/09 03:00:46 UTC

svn commit: r920617 - in /hadoop/zookeeper/trunk: CHANGES.txt src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java

Author: mahadev
Date: Tue Mar  9 02:00:46 2010
New Revision: 920617

URL: http://svn.apache.org/viewvc?rev=920617&view=rev
Log:
ZOOKEEPER-59. Synchronized block in NIOServerCnxn (flavio via mahadev)

Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=920617&r1=920616&r2=920617&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Tue Mar  9 02:00:46 2010
@@ -250,6 +250,8 @@ BUGFIXES: 
   ZOOKEEPER-689.  release build broken - ivysettings.xml not copied during
   "package" (phunt via mahadev)
 
+  ZOOKEEPER-59. Synchronized block in NIOServerCnxn (flavio via mahadev) 
+
 IMPROVEMENTS:
   ZOOKEEPER-473. cleanup junit tests to eliminate false positives due to
   "socket reuse" and failure to close client (phunt via mahadev)

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=920617&r1=920616&r2=920617&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 Tue Mar  9 02:00:46 2010
@@ -395,7 +395,8 @@ public class NIOServerCnxn implements Wa
                     return;
                 }
             }
-            synchronized (factory) {
+
+            synchronized(this.factory){
                 sk.selector().wakeup();
                 if (LOG.isTraceEnabled()) {
                     LOG.trace("Add a buffer to outgoingBuffers, sk " + sk
@@ -406,6 +407,7 @@ public class NIOServerCnxn implements Wa
                     sk.interestOps(sk.interestOps() | SelectionKey.OP_WRITE);
                 }
             }
+            
         } catch(Exception e) {
             LOG.error("Unexpected Exception: ", e);
         }
@@ -564,7 +566,8 @@ public class NIOServerCnxn implements Wa
                     // ZooLog.CLIENT_DATA_PACKET_TRACE_MASK, "after send,
                     // outgoingBuffers.size() = " + outgoingBuffers.size());
                 }
-                synchronized (this) {
+
+                synchronized(this.factory){
                     if (outgoingBuffers.size() == 0) {
                         if (!initialized
                                 && (sk.interestOps() & SelectionKey.OP_READ) == 0) {
@@ -574,7 +577,7 @@ public class NIOServerCnxn implements Wa
                                 & (~SelectionKey.OP_WRITE));
                     } else {
                         sk.interestOps(sk.interestOps()
-                                        | SelectionKey.OP_WRITE);
+                                | SelectionKey.OP_WRITE);
                     }
                 }
             }
@@ -654,19 +657,19 @@ public class NIOServerCnxn implements Wa
         }
         if (h.getXid() >= 0) {
             synchronized (this) {
-                synchronized (this.factory) {
-                    outstandingRequests++;
-                    // check throttling
-                    if (zk.getInProcess() > factory.outstandingLimit) {
-                        if (LOG.isDebugEnabled()) {
-                            LOG.debug("Throttling recv " + zk.getInProcess());
-                        }
-                        disableRecv();
-                        // following lines should not be needed since we are
-                        // already reading
-                        // } else {
-                        // enableRecv();
+                outstandingRequests++;
+            }
+            synchronized (this.factory) {        
+                // check throttling
+                if (zk.getInProcess() > factory.outstandingLimit) {
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Throttling recv " + zk.getInProcess());
                     }
+                    disableRecv();
+                    // following lines should not be needed since we are
+                    // already reading
+                    // } else {
+                    // enableRecv();
                 }
             }
         }
@@ -1312,9 +1315,11 @@ public class NIOServerCnxn implements Wa
             bb.putInt(b.length - 4).rewind();
             sendBuffer(bb);
             if (h.getXid() > 0) {
-                synchronized (this.factory) {
+                synchronized(this){
                     outstandingRequests--;
-                    // check throttling
+                }
+                // check throttling
+                synchronized (this.factory) {        
                     if (zk.getInProcess() < factory.outstandingLimit
                             || outstandingRequests < 1) {
                         sk.selector().wakeup();