cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [1/3] git commit: FBUtilities.singleton() should use the CF comparator
Date Thu, 06 Mar 2014 09:06:59 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk b173ce207 -> 800c62f3b


FBUtilities.singleton() should use the CF comparator

patch by slebresne; reviewed by thobbs for CASSANDRA-6778


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/773fade9
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/773fade9
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/773fade9

Branch: refs/heads/trunk
Commit: 773fade9aee009170c7062d174f2b78211061fce
Parents: 2492308
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Thu Mar 6 08:54:32 2014 +0100
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Thu Mar 6 08:56:08 2014 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cql3/statements/ColumnGroupMap.java         |  4 +-
 .../cql3/statements/SelectStatement.java        |  7 +-
 .../org/apache/cassandra/db/SystemKeyspace.java |  2 +-
 .../cassandra/db/filter/NamesQueryFilter.java   |  4 +-
 .../apache/cassandra/db/filter/QueryFilter.java |  8 ---
 .../org/apache/cassandra/utils/FBUtilities.java |  6 +-
 .../apache/cassandra/db/LongKeyspaceTest.java   |  3 +-
 .../unit/org/apache/cassandra/SchemaLoader.java |  3 +-
 .../org/apache/cassandra/config/DefsTest.java   |  7 +-
 .../cassandra/db/CollationControllerTest.java   |  5 +-
 .../cassandra/db/ColumnFamilyStoreTest.java     | 67 +++++++++++++++++---
 .../org/apache/cassandra/db/KeyspaceTest.java   |  7 +-
 .../apache/cassandra/db/ReadMessageTest.java    |  4 +-
 .../db/RecoveryManagerTruncateTest.java         |  3 +-
 .../apache/cassandra/db/RemoveColumnTest.java   |  3 +-
 .../cassandra/io/sstable/LegacySSTableTest.java |  4 +-
 .../cassandra/tools/SSTableExportTest.java      |  8 ++-
 18 files changed, 102 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 19cedd8..d697e3f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -33,6 +33,7 @@
  * Fix UPDATE updating PRIMARY KEY columns implicitly (CASSANDRA-6782)
  * Fix IllegalArgumentException when updating from 1.2 with SuperColumns
    (CASSANDRA-6733)
+ * FBUtilities.singleton() should use the CF comparator (CASSANDRA-6778)
 Merged from 1.2:
  * Add CMSClassUnloadingEnabled JVM option (CASSANDRA-6541)
  * Catch memtable flush exceptions during shutdown (CASSANDRA-6735)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/src/java/org/apache/cassandra/cql3/statements/ColumnGroupMap.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/ColumnGroupMap.java b/src/java/org/apache/cassandra/cql3/statements/ColumnGroupMap.java
index 5c3fcb9..1c9a346 100644
--- a/src/java/org/apache/cassandra/cql3/statements/ColumnGroupMap.java
+++ b/src/java/org/apache/cassandra/cql3/statements/ColumnGroupMap.java
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.cassandra.db.Column;
+import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.db.marshal.CompositeType;
 import org.apache.cassandra.utils.Pair;
 
@@ -155,7 +156,8 @@ public class ColumnGroupMap
         {
             for (int i = 0; i < idx; i++)
             {
-                if (!c[i].equals(previous[i]))
+                AbstractType<?> comp = composite.types.get(i);
+                if (comp.compare(c[i], previous[i]) != 0)
                     return false;
             }
             return true;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index 5a9d3d9..100383f 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -717,7 +717,7 @@ public class SelectStatement implements CQLStatement, MeasurableForPreparedCache
     {
         if (cfDef.isCompact)
         {
-            return FBUtilities.singleton(builder.build());
+            return FBUtilities.singleton(builder.build(), cfDef.cfm.comparator);
         }
         else
         {
@@ -994,10 +994,11 @@ public class SelectStatement implements CQLStatement, MeasurableForPreparedCache
                 }
                 else if (sliceRestriction != null)
                 {
+                    Comparator<ByteBuffer> comp = cfDef.cfm.comparator;
                     // For dynamic CF, the column could be out of the requested bounds, filter
here
-                    if (!sliceRestriction.isInclusive(Bound.START) && c.name().equals(sliceRestriction.bound(Bound.START,
variables)))
+                    if (!sliceRestriction.isInclusive(Bound.START) && comp.compare(c.name(),
sliceRestriction.bound(Bound.START, variables)) == 0)
                         continue;
-                    if (!sliceRestriction.isInclusive(Bound.END) && c.name().equals(sliceRestriction.bound(Bound.END,
variables)))
+                    if (!sliceRestriction.isInclusive(Bound.END) && comp.compare(c.name(),
sliceRestriction.bound(Bound.END, variables)) == 0)
                         continue;
                 }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/src/java/org/apache/cassandra/db/SystemKeyspace.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/SystemKeyspace.java b/src/java/org/apache/cassandra/db/SystemKeyspace.java
index 910f025..15d8538 100644
--- a/src/java/org/apache/cassandra/db/SystemKeyspace.java
+++ b/src/java/org/apache/cassandra/db/SystemKeyspace.java
@@ -621,7 +621,7 @@ public class SystemKeyspace
         ColumnFamilyStore cfs = Keyspace.open(Keyspace.SYSTEM_KS).getColumnFamilyStore(INDEX_CF);
         QueryFilter filter = QueryFilter.getNamesFilter(decorate(ByteBufferUtil.bytes(keyspaceName)),
                                                         INDEX_CF,
-                                                        ByteBufferUtil.bytes(indexName),
+                                                        FBUtilities.singleton(ByteBufferUtil.bytes(indexName),
cfs.getComparator()),
                                                         System.currentTimeMillis());
         return ColumnFamilyStore.removeDeleted(cfs.getColumnFamily(filter), Integer.MAX_VALUE)
!= null;
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/src/java/org/apache/cassandra/db/filter/NamesQueryFilter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/filter/NamesQueryFilter.java b/src/java/org/apache/cassandra/db/filter/NamesQueryFilter.java
index f65bf3a..4ff8091 100644
--- a/src/java/org/apache/cassandra/db/filter/NamesQueryFilter.java
+++ b/src/java/org/apache/cassandra/db/filter/NamesQueryFilter.java
@@ -60,9 +60,9 @@ public class NamesQueryFilter implements IDiskAtomFilter
         this.countCQL3Rows = countCQL3Rows;
     }
 
-    public NamesQueryFilter(ByteBuffer column)
+    public NamesQueryFilter(ByteBuffer column, Comparator<ByteBuffer> comparator)
     {
-        this(FBUtilities.singleton(column));
+        this(FBUtilities.singleton(column, comparator));
     }
 
     public NamesQueryFilter cloneShallow()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/src/java/org/apache/cassandra/db/filter/QueryFilter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/filter/QueryFilter.java b/src/java/org/apache/cassandra/db/filter/QueryFilter.java
index 4f71f3a..7136ae8 100644
--- a/src/java/org/apache/cassandra/db/filter/QueryFilter.java
+++ b/src/java/org/apache/cassandra/db/filter/QueryFilter.java
@@ -223,14 +223,6 @@ public class QueryFilter
         return new QueryFilter(key, cfName, new NamesQueryFilter(columns), timestamp);
     }
 
-    /**
-     * convenience method for creating a name filter matching a single column
-     */
-    public static QueryFilter getNamesFilter(DecoratedKey key, String cfName, ByteBuffer
column, long timestamp)
-    {
-        return new QueryFilter(key, cfName, new NamesQueryFilter(column), timestamp);
-    }
-
     @Override
     public String toString()
     {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/src/java/org/apache/cassandra/utils/FBUtilities.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/FBUtilities.java b/src/java/org/apache/cassandra/utils/FBUtilities.java
index 579f5fa..b8260b2 100644
--- a/src/java/org/apache/cassandra/utils/FBUtilities.java
+++ b/src/java/org/apache/cassandra/utils/FBUtilities.java
@@ -504,9 +504,11 @@ public class FBUtilities
         }
     }
 
-    public static <T extends Comparable> SortedSet<T> singleton(T column)
+    public static <T> SortedSet<T> singleton(T column, Comparator<T> comparator)
     {
-        return new TreeSet<T>(Arrays.asList(column));
+        TreeSet<T> s = new TreeSet<>(comparator);
+        s.add(column);
+        return s;
     }
 
     public static String toString(Map<?,?> map)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/test/long/org/apache/cassandra/db/LongKeyspaceTest.java
----------------------------------------------------------------------
diff --git a/test/long/org/apache/cassandra/db/LongKeyspaceTest.java b/test/long/org/apache/cassandra/db/LongKeyspaceTest.java
index b1ef690..1a472d6 100644
--- a/test/long/org/apache/cassandra/db/LongKeyspaceTest.java
+++ b/test/long/org/apache/cassandra/db/LongKeyspaceTest.java
@@ -27,6 +27,7 @@ import static org.apache.cassandra.Util.column;
 
 import org.apache.cassandra.Util;
 import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.FBUtilities;
 
 
 public class LongKeyspaceTest extends SchemaLoader
@@ -58,7 +59,7 @@ public class LongKeyspaceTest extends SchemaLoader
                     {
                         cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(Util.dk("key"
+ i),
                                                                                 "Standard1",
-                                                                                ByteBufferUtil.bytes("c"
+ j),
+                                                                                FBUtilities.singleton(ByteBufferUtil.bytes("c"
+ j), cfStore.getComparator()),
                                                                                 System.currentTimeMillis()));
                         KeyspaceTest.assertColumns(cf, "c" + j);
                     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/test/unit/org/apache/cassandra/SchemaLoader.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/SchemaLoader.java b/test/unit/org/apache/cassandra/SchemaLoader.java
index d554a8c..058e1e3 100644
--- a/test/unit/org/apache/cassandra/SchemaLoader.java
+++ b/test/unit/org/apache/cassandra/SchemaLoader.java
@@ -46,6 +46,7 @@ import org.apache.cassandra.locator.SimpleStrategy;
 import org.apache.cassandra.service.MigrationManager;
 import org.apache.cassandra.thrift.IndexType;
 import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.FBUtilities;
 
 public class SchemaLoader
 {
@@ -446,7 +447,7 @@ public class SchemaLoader
         for (int i = offset; i < offset + numberOfRows; i++)
         {
             DecoratedKey key = Util.dk("key" + i);
-            store.getColumnFamily(QueryFilter.getNamesFilter(key, columnFamily, ByteBufferUtil.bytes("col"
+ i), System.currentTimeMillis()));
+            store.getColumnFamily(QueryFilter.getNamesFilter(key, columnFamily, FBUtilities.singleton(ByteBufferUtil.bytes("col"
+ i), store.getComparator()), System.currentTimeMillis()));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/test/unit/org/apache/cassandra/config/DefsTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/config/DefsTest.java b/test/unit/org/apache/cassandra/config/DefsTest.java
index 79c9b33..943745a 100644
--- a/test/unit/org/apache/cassandra/config/DefsTest.java
+++ b/test/unit/org/apache/cassandra/config/DefsTest.java
@@ -41,6 +41,7 @@ import org.apache.cassandra.locator.SimpleStrategy;
 import org.apache.cassandra.service.MigrationManager;
 import org.apache.cassandra.thrift.IndexType;
 import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.FBUtilities;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -179,7 +180,7 @@ public class DefsTest extends SchemaLoader
         assert store != null;
         store.forceBlockingFlush();
 
-        ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, cf, ByteBufferUtil.bytes("col0"),
System.currentTimeMillis()));
+        ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, cf, FBUtilities.singleton(ByteBufferUtil.bytes("col0"),
store.getComparator()), System.currentTimeMillis()));
         assert cfam.getColumn(ByteBufferUtil.bytes("col0")) != null;
         Column col = cfam.getColumn(ByteBufferUtil.bytes("col0"));
         assert ByteBufferUtil.bytes("value0").equals(col.value());
@@ -252,7 +253,7 @@ public class DefsTest extends SchemaLoader
         assert store != null;
         store.forceBlockingFlush();
 
-        ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, newCf.cfName,
ByteBufferUtil.bytes("col0"), System.currentTimeMillis()));
+        ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, newCf.cfName,
FBUtilities.singleton(ByteBufferUtil.bytes("col0"), store.getComparator()), System.currentTimeMillis()));
         assert cfam.getColumn(ByteBufferUtil.bytes("col0")) != null;
         Column col = cfam.getColumn(ByteBufferUtil.bytes("col0"));
         assert ByteBufferUtil.bytes("value0").equals(col.value());
@@ -360,7 +361,7 @@ public class DefsTest extends SchemaLoader
         assert store != null;
         store.forceBlockingFlush();
 
-        ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, newCf.cfName,
ByteBufferUtil.bytes("col0"), System.currentTimeMillis()));
+        ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, newCf.cfName,
FBUtilities.singleton(ByteBufferUtil.bytes("col0"), store.getComparator()), System.currentTimeMillis()));
         assert cfam.getColumn(ByteBufferUtil.bytes("col0")) != null;
         Column col = cfam.getColumn(ByteBufferUtil.bytes("col0"));
         assert ByteBufferUtil.bytes("value0").equals(col.value());

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/test/unit/org/apache/cassandra/db/CollationControllerTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/CollationControllerTest.java b/test/unit/org/apache/cassandra/db/CollationControllerTest.java
index 8763a41..721dfae 100644
--- a/test/unit/org/apache/cassandra/db/CollationControllerTest.java
+++ b/test/unit/org/apache/cassandra/db/CollationControllerTest.java
@@ -28,6 +28,7 @@ import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.Util;
 import org.apache.cassandra.db.filter.QueryFilter;
 import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.FBUtilities;
 import org.junit.Test;
 
 import org.apache.cassandra.io.sstable.SSTableReader;
@@ -70,7 +71,7 @@ public class CollationControllerTest extends SchemaLoader
 
         // A NamesQueryFilter goes down one code path (through collectTimeOrderedData())
         // It should only iterate the last flushed sstable, since it probably contains the
most recent value for Column1
-        QueryFilter filter = QueryFilter.getNamesFilter(dk, cfs.name, ByteBufferUtil.bytes("Column1"),
System.currentTimeMillis());
+        QueryFilter filter = QueryFilter.getNamesFilter(dk, cfs.name, FBUtilities.singleton(ByteBufferUtil.bytes("Column1"),
cfs.getComparator()), System.currentTimeMillis());
         CollationController controller = new CollationController(cfs, filter, Integer.MIN_VALUE);
         controller.getTopLevelColumns();
         assertEquals(1, controller.getSstablesIterated());
@@ -113,7 +114,7 @@ public class CollationControllerTest extends SchemaLoader
         long queryAt = System.currentTimeMillis() + 1000;
         int gcBefore = cfs.gcBefore(queryAt);
 
-        filter = QueryFilter.getNamesFilter(dk, cfs.name, cellName, queryAt);
+        filter = QueryFilter.getNamesFilter(dk, cfs.name, FBUtilities.singleton(cellName,
cfs.getComparator()), queryAt);
         CollationController controller = new CollationController(cfs, filter, gcBefore);
         assert ColumnFamilyStore.removeDeleted(controller.getTopLevelColumns(), gcBefore)
== null;
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java b/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
index 65b1708..2edf6a8 100644
--- a/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
+++ b/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
@@ -52,6 +52,7 @@ import org.apache.cassandra.io.sstable.*;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.thrift.*;
 import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.Pair;
 import org.apache.cassandra.utils.WrappedRunnable;
 
@@ -94,7 +95,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         cfs.forceBlockingFlush();
 
         cfs.getRecentSSTablesPerReadHistogram(); // resets counts
-        cfs.getColumnFamily(QueryFilter.getNamesFilter(Util.dk("key1"), "Standard1", ByteBufferUtil.bytes("Column1"),
System.currentTimeMillis()));
+        cfs.getColumnFamily(QueryFilter.getNamesFilter(Util.dk("key1"), "Standard1", FBUtilities.singleton(ByteBufferUtil.bytes("Column1"),
cfs.getComparator()), System.currentTimeMillis()));
         assertEquals(1, cfs.getRecentSSTablesPerReadHistogram()[0]);
     }
 
@@ -148,7 +149,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
 
                 QueryFilter namesFilter = QueryFilter.getNamesFilter(Util.dk("key1"),
                                                                      "Standard2",
-                                                                     ByteBufferUtil.bytes("a"),
+                                                                     FBUtilities.singleton(ByteBufferUtil.bytes("a"),
store.getComparator()),
                                                                      System.currentTimeMillis());
                 cf = store.getColumnFamily(namesFilter);
                 assert cf.isMarkedForDelete();
@@ -167,7 +168,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         IPartitioner p = StorageService.getPartitioner();
         List<Row> result = cfs.getRangeSlice(Util.range(p, "key1", "key2"),
                                              null,
-                                             new NamesQueryFilter(ByteBufferUtil.bytes("asdf")),
+                                             new NamesQueryFilter(FBUtilities.singleton(ByteBufferUtil.bytes("asdf"),
cfs.getComparator())),
                                              10);
         assertEquals(1, result.size());
         assert result.get(0).key.key.equals(ByteBufferUtil.bytes("key2"));
@@ -198,13 +199,15 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(3L), 0);
         rm.apply();
 
+        ColumnFamilyStore store = Keyspace.open("Keyspace1").getColumnFamilyStore("Indexed1");
+
         // basic single-expression query
         IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ,
ByteBufferUtil.bytes(1L));
         List<IndexExpression> clause = Arrays.asList(expr);
         IDiskAtomFilter filter = new IdentityQueryFilter();
         IPartitioner p = StorageService.getPartitioner();
         Range<RowPosition> range = Util.range("", "");
-        List<Row> rows = Keyspace.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range,
clause, filter, 100);
+        List<Row> rows = store.search(range, clause, filter, 100);
 
         assert rows != null;
         assert rows.size() == 2 : StringUtils.join(rows, ",");
@@ -221,14 +224,14 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         // add a second expression
         IndexExpression expr2 = new IndexExpression(ByteBufferUtil.bytes("notbirthdate"),
IndexOperator.GTE, ByteBufferUtil.bytes(2L));
         clause = Arrays.asList(expr, expr2);
-        rows = Keyspace.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range,
clause, filter, 100);
+        rows = store.search(range, clause, filter, 100);
 
         assert rows.size() == 1 : StringUtils.join(rows, ",");
         key = new String(rows.get(0).key.key.array(),rows.get(0).key.key.position(),rows.get(0).key.key.remaining());
         assert "k3".equals( key );
 
         // same query again, but with resultset not including the subordinate expression
-        rows = Keyspace.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range,
clause, new NamesQueryFilter(ByteBufferUtil.bytes("birthdate")), 100);
+        rows = store.search(range, clause, new NamesQueryFilter(FBUtilities.singleton(ByteBufferUtil.bytes("birthdate"),
store.getComparator())), 100);
 
         assert rows.size() == 1 : StringUtils.join(rows, ",");
         key = new String(rows.get(0).key.key.array(),rows.get(0).key.key.position(),rows.get(0).key.key.remaining());
@@ -238,7 +241,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
 
         // once more, this time with a slice rowset that needs to be expanded
         SliceQueryFilter emptyFilter = new SliceQueryFilter(ByteBufferUtil.EMPTY_BYTE_BUFFER,
ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 0);
-        rows = Keyspace.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range,
clause, emptyFilter, 100);
+        rows = store.search(range, clause, emptyFilter, 100);
 
         assert rows.size() == 1 : StringUtils.join(rows, ",");
         key = new String(rows.get(0).key.key.array(),rows.get(0).key.key.position(),rows.get(0).key.key.remaining());
@@ -250,7 +253,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         // doesn't tell the scan loop that it's done
         IndexExpression expr3 = new IndexExpression(ByteBufferUtil.bytes("notbirthdate"),
IndexOperator.EQ, ByteBufferUtil.bytes(-1L));
         clause = Arrays.asList(expr, expr3);
-        rows = Keyspace.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range,
clause, filter, 100);
+        rows = store.search(range, clause, filter, 100);
 
         assert rows.isEmpty();
     }
@@ -686,6 +689,50 @@ public class ColumnFamilyStoreTest extends SchemaLoader
     }
 
     @Test
+    public void testCassandra6778() throws CharacterCodingException
+    {
+        String cfname = "StandardInteger1";
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);
+
+        // insert two columns that represent the same integer but have different binary forms
(the
+        // second one is padded with extra zeros)
+        RowMutation rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k1"));
+        byte[] column1 = {1};
+        rm.add(cfname, ByteBuffer.wrap(column1), ByteBufferUtil.bytes("data1"), 1);
+        rm.apply();
+        cfs.forceBlockingFlush();
+
+        rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k1"));
+        byte[] column2 = {0, 0, 1};
+        rm.add(cfname, ByteBuffer.wrap(column2), ByteBufferUtil.bytes("data2"), 2);
+        rm.apply();
+        cfs.forceBlockingFlush();
+
+        // fetch by the first column name; we should get the second version of the column
value
+        SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(
+            "Keyspace1", ByteBufferUtil.bytes("k1"), cfname, System.currentTimeMillis(),
+            new NamesQueryFilter(FBUtilities.singleton(ByteBuffer.wrap(column1), cfs.getComparator())));
+
+        ColumnFamily cf = cmd.getRow(keyspace).cf;
+        assertEquals(1, cf.getColumnCount());
+        Column column = cf.getColumn(ByteBuffer.wrap(column1));
+        assertEquals("data2", ByteBufferUtil.string(column.value()));
+        assertEquals(ByteBuffer.wrap(column2), column.name());
+
+        // fetch by the second column name; we should get the second version of the column
value
+        cmd = new SliceByNamesReadCommand(
+            "Keyspace1", ByteBufferUtil.bytes("k1"), cfname, System.currentTimeMillis(),
+            new NamesQueryFilter(FBUtilities.singleton(ByteBuffer.wrap(column2), cfs.getComparator())));
+
+        cf = cmd.getRow(keyspace).cf;
+        assertEquals(1, cf.getColumnCount());
+        column = cf.getColumn(ByteBuffer.wrap(column2));
+        assertEquals("data2", ByteBufferUtil.string(column.value()));
+        assertEquals(ByteBuffer.wrap(column2), column.name());
+    }
+
+    @Test
     public void testInclusiveBounds() throws IOException, ExecutionException, InterruptedException
     {
         ColumnFamilyStore cfs = insertKey1Key2();
@@ -693,7 +740,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         IPartitioner p = StorageService.getPartitioner();
         List<Row> result = cfs.getRangeSlice(Util.bounds("key1", "key2"),
                                              null,
-                                             new NamesQueryFilter(ByteBufferUtil.bytes("asdf")),
+                                             new NamesQueryFilter(FBUtilities.singleton(ByteBufferUtil.bytes("asdf"),
cfs.getComparator())),
                                              10);
         assertEquals(2, result.size());
         assert result.get(0).key.key.equals(ByteBufferUtil.bytes("key1"));
@@ -945,7 +992,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         putColsStandard(cfs, key, new Column(cname, ByteBufferUtil.bytes("b"), 1));
 
         // Test fetching the column by name returns the first column
-        SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(keyspaceName, key.key,
cfName, System.currentTimeMillis(), new NamesQueryFilter(cname));
+        SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(keyspaceName, key.key,
cfName, System.currentTimeMillis(), new NamesQueryFilter(FBUtilities.singleton(cname, cfs.getComparator())));
         ColumnFamily cf = cmd.getRow(keyspace).cf;
         Column column = (Column) cf.getColumn(cname);
         assert column.value().equals(ByteBufferUtil.bytes("a")) : "expecting a, got " + ByteBufferUtil.string(column.value());

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/test/unit/org/apache/cassandra/db/KeyspaceTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/KeyspaceTest.java b/test/unit/org/apache/cassandra/db/KeyspaceTest.java
index f1fcb29..e04a9d4 100644
--- a/test/unit/org/apache/cassandra/db/KeyspaceTest.java
+++ b/test/unit/org/apache/cassandra/db/KeyspaceTest.java
@@ -43,6 +43,7 @@ import static org.apache.cassandra.Util.expiringColumn;
 import org.apache.cassandra.Util;
 import org.apache.cassandra.io.sstable.SSTableReader;
 import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.FBUtilities;
 
 
 public class KeyspaceTest extends SchemaLoader
@@ -91,7 +92,7 @@ public class KeyspaceTest extends SchemaLoader
 
                 cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY,
                                                                         "Standard3",
-                                                                        ByteBufferUtil.bytes("col99"),
+                                                                        FBUtilities.singleton(ByteBufferUtil.bytes("col99"),
cfStore.getComparator()),
                                                                         System.currentTimeMillis()));
                 assertColumns(cf);
             }
@@ -120,13 +121,13 @@ public class KeyspaceTest extends SchemaLoader
 
                 cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY,
                                                                         "Standard1",
-                                                                        ByteBufferUtil.bytes("col1"),
+                                                                        FBUtilities.singleton(ByteBufferUtil.bytes("col1"),
cfStore.getComparator()),
                                                                         System.currentTimeMillis()));
                 assertColumns(cf, "col1");
 
                 cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY,
                                                                         "Standard1",
-                                                                        ByteBufferUtil.bytes("col3"),
+                                                                        FBUtilities.singleton(ByteBufferUtil.bytes("col3"),
cfStore.getComparator()),
                                                                         System.currentTimeMillis()));
                 assertColumns(cf, "col3");
             }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/test/unit/org/apache/cassandra/db/ReadMessageTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/ReadMessageTest.java b/test/unit/org/apache/cassandra/db/ReadMessageTest.java
index d829dae..94928c0 100644
--- a/test/unit/org/apache/cassandra/db/ReadMessageTest.java
+++ b/test/unit/org/apache/cassandra/db/ReadMessageTest.java
@@ -35,6 +35,7 @@ import org.apache.cassandra.db.filter.SliceQueryFilter;
 import org.apache.cassandra.io.util.DataOutputBuffer;
 import org.apache.cassandra.net.MessagingService;
 import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.FBUtilities;
 
 
 public class ReadMessageTest extends SchemaLoader
@@ -86,6 +87,7 @@ public class ReadMessageTest extends SchemaLoader
     public void testGetColumn() throws IOException, ColumnFamilyNotDefinedException
     {
         Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Standard1");
         RowMutation rm;
         DecoratedKey dk = Util.dk("key1");
 
@@ -94,7 +96,7 @@ public class ReadMessageTest extends SchemaLoader
         rm.add("Standard1", ByteBufferUtil.bytes("Column1"), ByteBufferUtil.bytes("abcd"),
0);
         rm.apply();
 
-        ReadCommand command = new SliceByNamesReadCommand("Keyspace1", dk.key, "Standard1",
System.currentTimeMillis(), new NamesQueryFilter(ByteBufferUtil.bytes("Column1")));
+        ReadCommand command = new SliceByNamesReadCommand("Keyspace1", dk.key, "Standard1",
System.currentTimeMillis(), new NamesQueryFilter(FBUtilities.singleton(ByteBufferUtil.bytes("Column1"),
cfs.getComparator())));
         Row row = command.getRow(keyspace);
         Column col = row.cf.getColumn(ByteBufferUtil.bytes("Column1"));
         assertEquals(col.value(), ByteBuffer.wrap("abcd".getBytes()));

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java b/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java
index b98a8b0..1c98079 100644
--- a/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java
+++ b/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java
@@ -31,6 +31,7 @@ import org.apache.cassandra.db.commitlog.CommitLog;
 import org.apache.cassandra.db.filter.QueryFilter;
 import org.junit.Test;
 import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.FBUtilities;
 
 /**
  * Test for the truncate operation.
@@ -74,7 +75,7 @@ public class RecoveryManagerTruncateTest extends SchemaLoader
 		}
 		cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(Util.dk(keyName),
                                                                 cfName,
-                                                                ByteBufferUtil.bytes(columnName),
+                                                                FBUtilities.singleton(ByteBufferUtil.bytes(columnName),
cfStore.getComparator()),
                                                                 System.currentTimeMillis()));
 		if (cf == null)
 		{

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/test/unit/org/apache/cassandra/db/RemoveColumnTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/RemoveColumnTest.java b/test/unit/org/apache/cassandra/db/RemoveColumnTest.java
index dfbf513..eddf5e0 100644
--- a/test/unit/org/apache/cassandra/db/RemoveColumnTest.java
+++ b/test/unit/org/apache/cassandra/db/RemoveColumnTest.java
@@ -28,6 +28,7 @@ import org.apache.cassandra.db.filter.QueryFilter;
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.Util;
 import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.FBUtilities;
 
 
 public class RemoveColumnTest extends SchemaLoader
@@ -53,7 +54,7 @@ public class RemoveColumnTest extends SchemaLoader
 
         ColumnFamily retrieved = store.getColumnFamily(QueryFilter.getNamesFilter(dk,
                                                                                   "Standard1",
-                                                                                  ByteBufferUtil.bytes("Column1"),
+                                                                                  FBUtilities.singleton(ByteBufferUtil.bytes("Column1"),
store.getComparator()),
                                                                                   System.currentTimeMillis()));
         assert retrieved.getColumn(ByteBufferUtil.bytes("Column1")).isMarkedForDelete(System.currentTimeMillis());
         assertNull(Util.cloneAndRemoveDeleted(retrieved, Integer.MAX_VALUE));

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java b/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java
index e508a55..c4ab8ab 100644
--- a/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java
+++ b/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java
@@ -122,7 +122,7 @@ public class LegacySSTableTest extends SchemaLoader
         for (String keystring : TEST_DATA)
         {
             ByteBuffer key = ByteBufferUtil.bytes(keystring);
-            SSTableNamesIterator iter = new SSTableNamesIterator(sstable, Util.dk(key), FBUtilities.singleton(key));
+            SSTableNamesIterator iter = new SSTableNamesIterator(sstable, Util.dk(key), FBUtilities.singleton(key,
sstable.metadata.comparator));
             ColumnFamily cf = iter.getColumnFamily();
 
             // check not deleted (CASSANDRA-6527)
@@ -149,7 +149,7 @@ public class LegacySSTableTest extends SchemaLoader
                 ByteBuffer key = ByteBufferUtil.bytes(keystring);
                 // confirm that the bloom filter does not reject any keys/names
                 DecoratedKey dk = reader.partitioner.decorateKey(key);
-                SSTableNamesIterator iter = new SSTableNamesIterator(reader, dk, FBUtilities.singleton(key));
+                SSTableNamesIterator iter = new SSTableNamesIterator(reader, dk, FBUtilities.singleton(key,
reader.metadata.comparator));
                 assert iter.next().name().equals(key);
             }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/773fade9/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
index 54c65f4..47aa2c8 100644
--- a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
+++ b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
@@ -30,6 +30,8 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintStream;
+import java.nio.ByteBuffer;
+import java.util.SortedSet;
 
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.Util;
@@ -45,6 +47,7 @@ import org.apache.cassandra.io.sstable.Descriptor;
 import org.apache.cassandra.io.sstable.SSTableReader;
 import org.apache.cassandra.io.sstable.SSTableWriter;
 import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.FBUtilities;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 import org.json.simple.JSONValue;
@@ -201,13 +204,14 @@ public class SSTableExportTest extends SchemaLoader
         new SSTableImport().importJson(tempJson.getPath(), "Keyspace1", "Standard1", tempSS2.getPath());
 
         reader = SSTableReader.open(Descriptor.fromFilename(tempSS2.getPath()));
-        QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), "Standard1", ByteBufferUtil.bytes("name"),
System.currentTimeMillis());
+        SortedSet<ByteBuffer> names = FBUtilities.singleton(ByteBufferUtil.bytes("name"),
cfamily.getComparator());
+        QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), "Standard1", names,
System.currentTimeMillis());
         ColumnFamily cf = qf.getSSTableColumnIterator(reader).getColumnFamily();
         qf.collateOnDiskAtom(cf, qf.getSSTableColumnIterator(reader), Integer.MIN_VALUE);
         assertTrue(cf != null);
         assertTrue(cf.getColumn(ByteBufferUtil.bytes("name")).value().equals(hexToBytes("76616c")));
 
-        qf = QueryFilter.getNamesFilter(Util.dk("rowExclude"), "Standard1", ByteBufferUtil.bytes("name"),
System.currentTimeMillis());
+        qf = QueryFilter.getNamesFilter(Util.dk("rowExclude"), "Standard1", names, System.currentTimeMillis());
         cf = qf.getSSTableColumnIterator(reader).getColumnFamily();
         assert cf == null;
     }


Mime
View raw message