zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iv...@apache.org
Subject svn commit: r1339607 - in /zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto: NIOServerFactory.java PerChannelBookieClient.java
Date Thu, 17 May 2012 14:05:03 GMT
Author: ivank
Date: Thu May 17 14:05:02 2012
New Revision: 1339607

URL: http://svn.apache.org/viewvc?rev=1339607&view=rev
Log:
BOOKKEEPER-224: Fix findbugs in bookkeeper-server component [missing changes] (ivank)

Modified:
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/NIOServerFactory.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/NIOServerFactory.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/NIOServerFactory.java?rev=1339607&r1=1339606&r2=1339607&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/NIOServerFactory.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/NIOServerFactory.java
Thu May 17 14:05:02 2012
@@ -485,9 +485,8 @@ public class NIOServerFactory extends Th
         }
 
         private class CnxnStats {
-            int packetsSent = 0;
-
-            int packetsReceived = 0;
+            long packetsSent = 0;
+            long packetsReceived = 0;
 
             /**
              * The number of requests that have been submitted but not yet

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java?rev=1339607&r1=1339606&r2=1339607&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java
Thu May 17 14:05:02 2012
@@ -90,13 +90,13 @@ public class PerChannelBookieClient exte
      * because they are always updated under a lock
      */
     Queue<GenericCallback<Void>> pendingOps = new ArrayDeque<GenericCallback<Void>>();
-    Channel channel = null;
+    volatile Channel channel = null;
 
     private enum ConnectionState {
         DISCONNECTED, CONNECTING, CONNECTED
             };
 
-    private ConnectionState state;
+    private volatile ConnectionState state;
     private final ClientConfiguration conf;
 
     public PerChannelBookieClient(OrderedSafeExecutor executor, ClientSocketChannelFactory
channelFactory,
@@ -174,29 +174,38 @@ public class PerChannelBookieClient exte
     void connectIfNeededAndDoOp(GenericCallback<Void> op) {
         boolean doOpNow;
 
-        synchronized (this) {
-            if (channel != null && state == ConnectionState.CONNECTED) {
-                doOpNow = true;
-            } else {
-                // if reached here, channel is either null (first connection
-                // attempt),
-                // or the channel is disconnected
-                doOpNow = false;
-
-                // connection attempt is still in progress, queue up this
-                // op. Op will be executed when connection attempt either
-                // fails
-                // or
-                // succeeds
-                pendingOps.add(op);
+        // common case without lock first
+        if (channel != null && state == ConnectionState.CONNECTED) {
+            doOpNow = true;
+        } else {
+
+            synchronized (this) {
+                // check again under lock
+                if (channel != null && state == ConnectionState.CONNECTED) {
+                    doOpNow = true;
+                } else {
 
-                connect();
+                    // if reached here, channel is either null (first connection
+                    // attempt),
+                    // or the channel is disconnected
+                    doOpNow = false;
+
+                    // connection attempt is still in progress, queue up this
+                    // op. Op will be executed when connection attempt either
+                    // fails
+                    // or
+                    // succeeds
+                    pendingOps.add(op);
+
+                    connect();
+                }
             }
         }
 
         if (doOpNow) {
             op.operationComplete(BKException.Code.OK, null);
         }
+
     }
 
     /**



Mime
View raw message