You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sl...@apache.org on 2011/05/12 17:06:49 UTC
svn commit: r1102337 - in /cassandra/branches/cassandra-0.7: CHANGES.txt
src/java/org/apache/cassandra/db/ColumnFamilyStore.java
test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
Author: slebresne
Date: Thu May 12 15:06:48 2011
New Revision: 1102337
URL: http://svn.apache.org/viewvc?rev=1102337&view=rev
Log:
Avoid wrong empty result with secondary index when limit=1
patch by slebresne; reviewed by jbellis for CASSANDRA-2628
Modified:
cassandra/branches/cassandra-0.7/CHANGES.txt
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
Modified: cassandra/branches/cassandra-0.7/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/CHANGES.txt?rev=1102337&r1=1102336&r2=1102337&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.7/CHANGES.txt Thu May 12 15:06:48 2011
@@ -22,7 +22,8 @@
* avoid using cached position of a key when GT is requested (CASSANDRA-2633)
* fix counting bloom filter true positives (CASSANDRA-2637)
* initialize local ep state prior to gossip startup if needed (CASSANDRA-2638)
-
+ * fix empty Result with secondary index when limit=1 (CASSANDRA-2628)
+
0.7.5
* improvements/fixes to PIG driver (CASSANDRA-1618, CASSANDRA-2387,
Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyStore.java?rev=1102337&r1=1102336&r2=1102337&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyStore.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyStore.java Thu May 12 15:06:48 2011
@@ -1569,12 +1569,15 @@ public class ColumnFamilyStore implement
if (logger.isDebugEnabled())
logger.debug(String.format("Scanning index %s starting with %s",
expressionString(primary), indexCFS.getComparator().getString(startKey)));
+
+ // We shouldn't fetch only 1 row as this provides buggy paging in case the first row doesn't satisfy all clauses
+ int count = Math.max(clause.count, 2);
QueryFilter indexFilter = QueryFilter.getSliceFilter(indexKey,
new QueryPath(indexCFS.getColumnFamilyName()),
startKey,
ByteBufferUtil.EMPTY_BYTE_BUFFER,
false,
- clause.count);
+ count);
ColumnFamily indexRow = indexCFS.getColumnFamily(indexFilter);
logger.debug("fetched {}", indexRow);
if (indexRow == null)
Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java?rev=1102337&r1=1102336&r2=1102337&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java (original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java Thu May 12 15:06:48 2011
@@ -355,6 +355,45 @@ public class ColumnFamilyStoreTest exten
}
+ // See CASSANDRA-2628
+ @Test
+ public void testIndexScanWithLimitOne() throws IOException
+ {
+ RowMutation rm;
+
+ rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("kk1"));
+ rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(1L), 0);
+ rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 0);
+ rm.apply();
+
+ rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("kk2"));
+ rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(2L), 0);
+ rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 0);
+ rm.apply();
+
+ rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("kk3"));
+ rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(2L), 0);
+ rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 0);
+ rm.apply();
+
+ rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("kk4"));
+ rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(2L), 0);
+ rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 0);
+ rm.apply();
+
+ // basic single-expression query
+ IndexExpression expr1 = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(1L));
+ IndexExpression expr2 = new IndexExpression(ByteBufferUtil.bytes("notbirthdate"), IndexOperator.GT, ByteBufferUtil.bytes(1L));
+ IndexClause clause = new IndexClause(Arrays.asList(new IndexExpression[]{ expr1, expr2 }), ByteBufferUtil.EMPTY_BYTE_BUFFER, 1);
+ IFilter filter = new IdentityQueryFilter();
+ IPartitioner p = StorageService.getPartitioner();
+ Range range = new Range(p.getMinimumToken(), p.getMinimumToken());
+ List<Row> rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").scan(clause, range, filter);
+
+ assert rows != null;
+ assert rows.size() == 1 : StringUtils.join(rows, ",");
+ }
+
@Test
public void testIndexCreate() throws IOException, ConfigurationException, InterruptedException, ExecutionException
{