You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2009/08/12 23:27:25 UTC

svn commit: r803716 - /incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java

Author: jbellis
Date: Wed Aug 12 21:27:24 2009
New Revision: 803716

URL: http://svn.apache.org/viewvc?rev=803716&view=rev
Log:
give up on trying to optimize startWith -- it's basically impossible when replication factor > 1 b/c of the range wrap point.
patch by jbellis; tested by Mark Robson for CASSANDRA-348

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java?rev=803716&r1=803715&r2=803716&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java Wed Aug 12 21:27:24 2009
@@ -637,7 +637,7 @@
             IAsyncResult iar = MessagingService.getMessagingInstance().sendRR(message, endPoint);
 
             // read response
-            byte[] responseBody = new byte[0];
+            byte[] responseBody;
             try
             {
                 responseBody = iar.get(DatabaseDescriptor.getRpcTimeout(), TimeUnit.MILLISECONDS);
@@ -649,6 +649,7 @@
             RangeReply rangeReply = RangeReply.read(responseBody);
             List<String> rangeKeys = rangeReply.keys;
 
+            // combine keys from most recent response with the others seen so far
             if (rangeKeys.size() > 0)
             {
                 if (allKeys.size() > 0)
@@ -693,15 +694,14 @@
                 break;
             }
 
-            // the first endpoint contains the range from the last endpoint, up to and including its own token.
-            // so it will include both the smallest keys, and the largest.  if that is what we just scanned,
-            // leave startWith unchanged.  Otherwise, start with the largest key found.
-            String newStartWith = endPoint.equals(wrapEndpoint)
-                                ? rawCommand.startWith
-                                : allKeys.size() > 0 ? allKeys.get(allKeys.size() - 1) : command.startWith;
+            // set up the next query --
+            // it's tempting to try to optimize this by starting with the last key seen for the next node,
+            // but that won't work when you have a replication factor of more than one--any node, not just
+            // the one holding the keys where the range wraps, could include both the smallest keys, and the largest,
+            // so starting with the largest in our scan of the next node means we'd never see keys from the middle.
             endPoint = tokenMetadata.getNextEndpoint(endPoint); // TODO move this into the Strategies & modify for RackAwareStrategy
             int maxResults = endPoint == wrapEndpoint ? rawCommand.maxResults : rawCommand.maxResults - allKeys.size();
-            command = new RangeCommand(command.table, command.columnFamily, newStartWith, command.stopAt, maxResults);
+            command = new RangeCommand(command.table, command.columnFamily, command.startWith, command.stopAt, maxResults);
         } while (!endPoint.equals(startEndpoint));
 
         rangeStats.add(System.currentTimeMillis() - startTime);