cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jun...@apache.org
Subject svn commit: r897089 - in /incubator/cassandra/trunk/src/java/org/apache/cassandra/net: ./ io/
Date Fri, 08 Jan 2010 04:18:22 GMT
Author: junrao
Date: Fri Jan  8 04:18:20 2010
New Revision: 897089

URL: http://svn.apache.org/viewvc?rev=897089&view=rev
Log:
TcpReader is slow because of using Exception handling in the normal path; patched by junrao;
reviewed by Bradon Williams and jbellis for CASSANDRA-675

Removed:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ReadNotCompleteException.java
Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/net/SelectionKeyHandler.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/net/SelectorManager.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ContentLengthState.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ContentState.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ContentStreamState.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/DoneState.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ProtocolHeaderState.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ProtocolState.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/StartState.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/TcpReader.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/net/SelectionKeyHandler.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/net/SelectionKeyHandler.java?rev=897089&r1=897088&r2=897089&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/net/SelectionKeyHandler.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/net/SelectionKeyHandler.java Fri
Jan  8 04:18:20 2010
@@ -65,17 +65,11 @@
     
     protected static void turnOnInterestOps(SelectionKey key, int ops)
     {
-        synchronized(key)
-        {
-            key.interestOps(key.interestOps() | ops);
-        }
+        SelectorManager.getSelectorManager().turnOnInterestOps(key, ops);
     }
     
     protected static void turnOffInterestOps(SelectionKey key, int ops)
     {
-        synchronized(key)
-        {
-            key.interestOps(key.interestOps() & (~ops) );
-        }
+        SelectorManager.getSelectorManager().turnOffInterestOps(key, ops);
     }
 }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/net/SelectorManager.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/net/SelectorManager.java?rev=897089&r1=897088&r2=897089&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/net/SelectorManager.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/net/SelectorManager.java Fri Jan
 8 04:18:20 2010
@@ -103,7 +103,7 @@
         {
             try
             {
-                selector.select(1);
+                selector.select();
                 doProcess();
                 synchronized(gate) {}
             }
@@ -202,4 +202,22 @@
         }
         return udpManager;
     }
+
+    protected void turnOnInterestOps(SelectionKey key, int ops)
+    {
+        synchronized(gate)
+        {
+            selector.wakeup();
+            key.interestOps(key.interestOps() | ops);
+        }
+    }
+    
+    protected void turnOffInterestOps(SelectionKey key, int ops)
+    {
+        synchronized(gate)
+        {
+            selector.wakeup();
+            key.interestOps(key.interestOps() & (~ops) );
+        }
+    }
 }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ContentLengthState.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ContentLengthState.java?rev=897089&r1=897088&r2=897089&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ContentLengthState.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ContentLengthState.java
Fri Jan  8 04:18:20 2010
@@ -35,7 +35,7 @@
         buffer_ = ByteBuffer.allocate(4);
     }
 
-    public byte[] read() throws IOException, ReadNotCompleteException
+    public byte[] read() throws IOException
     {        
         return doRead(buffer_);
     }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ContentState.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ContentState.java?rev=897089&r1=897088&r2=897089&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ContentState.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ContentState.java Fri Jan
 8 04:18:20 2010
@@ -34,7 +34,7 @@
         buffer_ = ByteBuffer.allocate(length_);
     }
 
-    public byte[] read() throws IOException, ReadNotCompleteException
+    public byte[] read() throws IOException
     {          
         return doRead(buffer_);
     }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ContentStreamState.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ContentStreamState.java?rev=897089&r1=897088&r2=897089&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ContentStreamState.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ContentStreamState.java
Fri Jan  8 04:18:20 2010
@@ -59,7 +59,7 @@
         }
     }
 
-    public byte[] read() throws IOException, ReadNotCompleteException
+    public byte[] read() throws IOException
     {        
         SocketChannel socketChannel = stream_.getStream();
         InetSocketAddress remoteAddress = (InetSocketAddress)socketChannel.socket().getRemoteSocketAddress();
@@ -70,7 +70,7 @@
             {
                 bytesRead_ += fc_.transferFrom(socketChannel, bytesRead_, ContentStreamState.count_);
                 if ( bytesRead_ != streamContext_.getExpectedBytes() )
-                    throw new ReadNotCompleteException("Specified number of bytes have not
been read from the Socket Channel");
+                    return null;
             }
             catch ( IOException ex )
             {

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/DoneState.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/DoneState.java?rev=897089&r1=897088&r2=897089&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/DoneState.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/DoneState.java Fri Jan
 8 04:18:20 2010
@@ -31,7 +31,7 @@
         bytes_ = bytes;
     }
 
-    public byte[] read() throws IOException, ReadNotCompleteException
+    public byte[] read() throws IOException
     {        
         morphState();
         return bytes_;

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ProtocolHeaderState.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ProtocolHeaderState.java?rev=897089&r1=897088&r2=897089&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ProtocolHeaderState.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ProtocolHeaderState.java
Fri Jan  8 04:18:20 2010
@@ -34,7 +34,7 @@
         buffer_ = ByteBuffer.allocate(4);
     }
 
-    public byte[] read() throws IOException, ReadNotCompleteException
+    public byte[] read() throws IOException
     {        
         return doRead(buffer_);
     }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ProtocolState.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ProtocolState.java?rev=897089&r1=897088&r2=897089&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ProtocolState.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/ProtocolState.java Fri
Jan  8 04:18:20 2010
@@ -34,7 +34,7 @@
         buffer_ = ByteBuffer.allocate(16);
     }
 
-    public byte[] read() throws IOException, ReadNotCompleteException
+    public byte[] read() throws IOException
     {        
         return doRead(buffer_);
     }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/StartState.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/StartState.java?rev=897089&r1=897088&r2=897089&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/StartState.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/StartState.java Fri Jan
 8 04:18:20 2010
@@ -31,11 +31,11 @@
         stream_ = stream;
     }
 
-    public abstract byte[] read() throws IOException, ReadNotCompleteException;
+    public abstract byte[] read() throws IOException;
     public abstract void morphState() throws IOException;
     public abstract void setContextData(Object data);
 
-    protected byte[] doRead(ByteBuffer buffer) throws IOException, ReadNotCompleteException
+    protected byte[] doRead(ByteBuffer buffer) throws IOException
     {        
         SocketChannel socketChannel = stream_.getStream();
         int bytesRead = socketChannel.read(buffer);     
@@ -48,8 +48,8 @@
             morphState();
         }
         else
-        {            
-            throw new ReadNotCompleteException("Specified number of bytes have not been read
from the Socket Channel");
+        {        
+            return null;
         }
         return new byte[0];
     }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/TcpReader.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/TcpReader.java?rev=897089&r1=897088&r2=897089&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/TcpReader.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/net/io/TcpReader.java Fri Jan
 8 04:18:20 2010
@@ -24,6 +24,7 @@
 
 import org.apache.cassandra.net.ProtocolHeader;
 import org.apache.cassandra.net.TcpConnection;
+import org.apache.commons.lang.ArrayUtils;
 
 public class TcpReader
 {
@@ -88,15 +89,13 @@
     
     public byte[] read() throws IOException
     {
-        byte[] bytes = new byte[0];      
+        byte[] bytes = ArrayUtils.EMPTY_BYTE_ARRAY;      
         while ( socketState_ != null )
-        {
-            try
-            {                                                                      
-                bytes = socketState_.read();
-            }
-            catch ( ReadNotCompleteException e )
-            {                
+        {                          
+            bytes = socketState_.read();
+            if (bytes == null)
+            {
+                bytes = ArrayUtils.EMPTY_BYTE_ARRAY;
                 break;
             }
         }



Mime
View raw message