From ddf00a509a4793bc69bf11cf10cc8155a9371f2d Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Wed, 12 Aug 2009 21:27:24 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@803716 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/cassandra/service/StorageProxy.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/java/org/apache/cassandra/service/StorageProxy.java b/src/java/org/apache/cassandra/service/StorageProxy.java index cd8e8ebd46..e43b615b41 100644 --- a/src/java/org/apache/cassandra/service/StorageProxy.java +++ b/src/java/org/apache/cassandra/service/StorageProxy.java @@ -637,7 +637,7 @@ public class StorageProxy implements StorageProxyMBean 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 @@ public class StorageProxy implements StorageProxyMBean RangeReply rangeReply = RangeReply.read(responseBody); List 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 @@ public class StorageProxy implements StorageProxyMBean 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);