You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by al...@apache.org on 2013/06/27 20:36:39 UTC

[03/11] Rename Table to Keyspace

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/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 e5ee5f3..984c354 100644
--- a/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
+++ b/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
@@ -78,8 +78,8 @@ public class ColumnFamilyStoreTest extends SchemaLoader
     // create two sstables, and verify that we only deserialize data from the most recent one
     public void testTimeSortedQuery() throws IOException, ExecutionException, InterruptedException
     {
-        Table table = Table.open("Keyspace1");
-        ColumnFamilyStore cfs = table.getColumnFamilyStore("Standard1");
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Standard1");
         cfs.truncateBlocking();
 
         RowMutation rm;
@@ -101,8 +101,8 @@ public class ColumnFamilyStoreTest extends SchemaLoader
     @Test
     public void testGetColumnWithWrongBF() throws IOException, ExecutionException, InterruptedException
     {
-        Table table = Table.open("Keyspace1");
-        ColumnFamilyStore cfs = table.getColumnFamilyStore("Standard1");
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Standard1");
         cfs.truncateBlocking();
 
         List<IMutation> rms = new LinkedList<IMutation>();
@@ -113,7 +113,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         rms.add(rm);
         Util.writeColumnFamily(rms);
 
-        List<SSTableReader> ssTables = table.getAllSSTables();
+        List<SSTableReader> ssTables = keyspace.getAllSSTables();
         assertEquals(1, ssTables.size());
         ssTables.get(0).forceFilterFailures();
         ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("key2"), "Standard1", System.currentTimeMillis()));
@@ -123,8 +123,8 @@ public class ColumnFamilyStoreTest extends SchemaLoader
     @Test
     public void testEmptyRow() throws Exception
     {
-        Table table = Table.open("Keyspace1");
-        final ColumnFamilyStore store = table.getColumnFamilyStore("Standard2");
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+        final ColumnFamilyStore store = keyspace.getColumnFamilyStore("Standard2");
         RowMutation rm;
 
         rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("key1"));
@@ -156,7 +156,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
             }
         };
 
-        TableTest.reTest(store, r);
+        KeyspaceTest.reTest(store, r);
     }
 
     @Test
@@ -204,7 +204,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         IDiskAtomFilter filter = new IdentityQueryFilter();
         IPartitioner p = StorageService.getPartitioner();
         Range<RowPosition> range = Util.range("", "");
-        List<Row> rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
+        List<Row> rows = Keyspace.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
 
         assert rows != null;
         assert rows.size() == 2 : StringUtils.join(rows, ",");
@@ -221,14 +221,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 = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
+        rows = Keyspace.open("Keyspace1").getColumnFamilyStore("Indexed1").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 = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range, clause, new NamesQueryFilter(ByteBufferUtil.bytes("birthdate")), 100);
+        rows = Keyspace.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range, clause, new NamesQueryFilter(ByteBufferUtil.bytes("birthdate")), 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 +238,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 = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range, clause, emptyFilter, 100);
+        rows = Keyspace.open("Keyspace1").getColumnFamilyStore("Indexed1").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 +250,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 = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
+        rows = Keyspace.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
 
         assert rows.isEmpty();
     }
@@ -273,7 +273,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         IDiskAtomFilter filter = new IdentityQueryFilter();
         IPartitioner p = StorageService.getPartitioner();
         Range<RowPosition> range = Util.range("", "");
-        List<Row> rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
+        List<Row> rows = Keyspace.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
 
         assert rows != null;
         assert rows.size() == 50 : rows.size();
@@ -287,7 +287,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
     @Test
     public void testIndexDeletions() throws IOException
     {
-        ColumnFamilyStore cfs = Table.open("Keyspace3").getColumnFamilyStore("Indexed1");
+        ColumnFamilyStore cfs = Keyspace.open("Keyspace3").getColumnFamilyStore("Indexed1");
         RowMutation rm;
 
         rm = new RowMutation("Keyspace3", ByteBufferUtil.bytes("k1"));
@@ -382,7 +382,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
     @Test
     public void testIndexUpdate() throws IOException
     {
-        Table table = Table.open("Keyspace2");
+        Keyspace keyspace = Keyspace.open("Keyspace2");
 
         // create a row and update the birthdate value, test that the index query fetches the new version
         RowMutation rm;
@@ -398,12 +398,12 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         IDiskAtomFilter filter = new IdentityQueryFilter();
         IPartitioner p = StorageService.getPartitioner();
         Range<RowPosition> range = Util.range("", "");
-        List<Row> rows = table.getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
+        List<Row> rows = keyspace.getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
         assert rows.size() == 0;
 
         expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(2L));
         clause = Arrays.asList(expr);
-        rows = table.getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
+        rows = keyspace.getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
         String key = ByteBufferUtil.string(rows.get(0).key.key);
         assert "k1".equals( key );
 
@@ -412,7 +412,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(3L), 0);
         rm.apply();
 
-        rows = table.getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
+        rows = keyspace.getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
         key = ByteBufferUtil.string(rows.get(0).key.key);
         assert "k1".equals( key );
 
@@ -424,8 +424,8 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         String keySpace = "Keyspace2";
         String cfName = "Indexed1";
 
-        Table table = Table.open(keySpace);
-        ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
+        Keyspace keyspace = Keyspace.open(keySpace);
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName);
         cfs.truncateBlocking();
 
         ByteBuffer rowKey = ByteBufferUtil.bytes("k1");
@@ -442,42 +442,42 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         List<IndexExpression> clause = Arrays.asList(expr);
         IDiskAtomFilter filter = new IdentityQueryFilter();
         Range<RowPosition> range = Util.range("", "");
-        List<Row> rows = table.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
+        List<Row> rows = keyspace.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
         assertEquals(1, rows.size());
 
         // force a flush, so our index isn't being read from a memtable
-        table.getColumnFamilyStore(cfName).forceBlockingFlush();
+        keyspace.getColumnFamilyStore(cfName).forceBlockingFlush();
 
         // now apply another update, but force the index update to be skipped
         rm = new RowMutation(keySpace, rowKey);
         rm.add(cfName, colName, val2, 1);
-        table.apply(rm, true, false);
+        keyspace.apply(rm, true, false);
 
         // Now searching the index for either the old or new value should return 0 rows
         // because the new value was not indexed and the old value should be ignored
         // (and in fact purged from the index cf).
         // first check for the old value
-        rows = table.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
+        rows = keyspace.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
         assertEquals(0, rows.size());
         // now check for the updated value
         expr = new IndexExpression(colName, IndexOperator.EQ, val2);
         clause = Arrays.asList(expr);
         filter = new IdentityQueryFilter();
         range = Util.range("", "");
-        rows = table.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
+        rows = keyspace.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
         assertEquals(0, rows.size());
 
         // now, reset back to the original value, still skipping the index update, to
         // make sure the value was expunged from the index when it was discovered to be inconsistent
         rm = new RowMutation(keySpace, rowKey);
         rm.add(cfName, colName, ByteBufferUtil.bytes(1L), 3);
-        table.apply(rm, true, false);
+        keyspace.apply(rm, true, false);
 
         expr = new IndexExpression(colName, IndexOperator.EQ, ByteBufferUtil.bytes(1L));
         clause = Arrays.asList(expr);
         filter = new IdentityQueryFilter();
         range = Util.range("", "");
-        rows = table.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
+        rows = keyspace.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
         assertEquals(0, rows.size());
     }
 
@@ -487,8 +487,8 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         String keySpace = "Keyspace2";
         String cfName = "Indexed2";
 
-        Table table = Table.open(keySpace);
-        ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
+        Keyspace keyspace = Keyspace.open(keySpace);
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName);
         cfs.truncateBlocking();
 
         ByteBuffer rowKey = ByteBufferUtil.bytes("k1");
@@ -514,44 +514,44 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         List<IndexExpression> clause = Arrays.asList(expr);
         IDiskAtomFilter filter = new IdentityQueryFilter();
         Range<RowPosition> range = Util.range("", "");
-        List<Row> rows = table.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
+        List<Row> rows = keyspace.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
         assertEquals(1, rows.size());
 
         // force a flush and retry the query, so our index isn't being read from a memtable
-        table.getColumnFamilyStore(cfName).forceBlockingFlush();
-        rows = table.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
+        keyspace.getColumnFamilyStore(cfName).forceBlockingFlush();
+        rows = keyspace.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
         assertEquals(1, rows.size());
 
         // now apply another update, but force the index update to be skipped
         rm = new RowMutation(keySpace, rowKey);
         rm.add(cfName, compositeName, val2, 1);
-        table.apply(rm, true, false);
+        keyspace.apply(rm, true, false);
 
         // Now searching the index for either the old or new value should return 0 rows
         // because the new value was not indexed and the old value should be ignored
         // (and in fact purged from the index cf).
         // first check for the old value
-        rows = table.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
+        rows = keyspace.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
         assertEquals(0, rows.size());
         // now check for the updated value
         expr = new IndexExpression(colName, IndexOperator.EQ, val2);
         clause = Arrays.asList(expr);
         filter = new IdentityQueryFilter();
         range = Util.range("", "");
-        rows = table.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
+        rows = keyspace.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
         assertEquals(0, rows.size());
 
         // now, reset back to the original value, still skipping the index update, to
         // make sure the value was expunged from the index when it was discovered to be inconsistent
         rm = new RowMutation(keySpace, rowKey);
         rm.add(cfName, compositeName, val1, 2);
-        table.apply(rm, true, false);
+        keyspace.apply(rm, true, false);
 
         expr = new IndexExpression(colName, IndexOperator.EQ, val1);
         clause = Arrays.asList(expr);
         filter = new IdentityQueryFilter();
         range = Util.range("", "");
-        rows = table.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
+        rows = keyspace.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
         assertEquals(0, rows.size());
     }
 
@@ -588,7 +588,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         IDiskAtomFilter filter = new IdentityQueryFilter();
         IPartitioner p = StorageService.getPartitioner();
         Range<RowPosition> range = Util.range("", "");
-        List<Row> rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range, clause, filter, 1);
+        List<Row> rows = Keyspace.open("Keyspace1").getColumnFamilyStore("Indexed1").search(range, clause, filter, 1);
 
         assert rows != null;
         assert rows.size() == 1 : StringUtils.join(rows, ",");
@@ -597,7 +597,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
     @Test
     public void testIndexCreate() throws IOException, ConfigurationException, InterruptedException, ExecutionException
     {
-        Table table = Table.open("Keyspace1");
+        Keyspace keyspace = Keyspace.open("Keyspace1");
 
         // create a row and update the birthdate value, test that the index query fetches the new version
         RowMutation rm;
@@ -605,7 +605,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         rm.add("Indexed2", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), 1);
         rm.apply();
 
-        ColumnFamilyStore cfs = table.getColumnFamilyStore("Indexed2");
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Indexed2");
         ColumnDefinition old = cfs.metadata.getColumnDefinition(ByteBufferUtil.bytes("birthdate"));
         ColumnDefinition cd = ColumnDefinition.regularDef(old.name, old.getValidator(), null).setIndex("birthdate_index", IndexType.KEYS, null);
         Future<?> future = cfs.indexManager.addIndexedColumn(cd);
@@ -613,7 +613,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         // we had a bug (CASSANDRA-2244) where index would get created but not flushed -- check for that
         assert cfs.indexManager.getIndexForColumn(cd.name).getIndexCfs().getSSTables().size() > 0;
 
-        queryBirthdate(table);
+        queryBirthdate(keyspace);
 
         // validate that drop clears it out & rebuild works (CASSANDRA-2320)
         SecondaryIndex indexedCfs = cfs.indexManager.getIndexForColumn(ByteBufferUtil.bytes("birthdate"));
@@ -623,16 +623,16 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         // rebuild & re-query
         future = cfs.indexManager.addIndexedColumn(cd);
         future.get();
-        queryBirthdate(table);
+        queryBirthdate(keyspace);
     }
 
-    private void queryBirthdate(Table table) throws CharacterCodingException
+    private void queryBirthdate(Keyspace keyspace) throws CharacterCodingException
     {
         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();
-        List<Row> rows = table.getColumnFamilyStore("Indexed2").search(Util.range("", ""), clause, filter, 100);
+        List<Row> rows = keyspace.getColumnFamilyStore("Indexed2").search(Util.range("", ""), clause, filter, 100);
         assert rows.size() == 1 : StringUtils.join(rows, ",");
         assertEquals("k1", ByteBufferUtil.string(rows.get(0).key.key));
     }
@@ -654,11 +654,11 @@ public class ColumnFamilyStoreTest extends SchemaLoader
     @Test
     public void testDeleteSuperRowSticksAfterFlush() throws Throwable
     {
-        String tableName = "Keyspace1";
+        String keyspaceName = "Keyspace1";
         String cfName= "Super1";
         ByteBuffer scfName = ByteBufferUtil.bytes("SuperDuper");
-        Table table = Table.open(tableName);
-        ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
+        Keyspace keyspace = Keyspace.open(keyspaceName);
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName);
         DecoratedKey key = Util.dk("flush-resurrection");
 
         // create an isolated sstable.
@@ -684,7 +684,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         assertRowAndColCount(1, 6, scfName, false, cfs.getRangeSlice(Util.range("f", "g"), null, ThriftValidation.asIFilter(sp, cfs.metadata, scfName), 100));
 
         // delete
-        RowMutation rm = new RowMutation(table.getName(), key.key);
+        RowMutation rm = new RowMutation(keyspace.getName(), key.key);
         rm.deleteRange(cfName, SuperColumns.startOf(scfName), SuperColumns.endOf(scfName), 2);
         rm.apply();
 
@@ -735,19 +735,19 @@ public class ColumnFamilyStoreTest extends SchemaLoader
 
     private static void putColsSuper(ColumnFamilyStore cfs, DecoratedKey key, ByteBuffer scfName, Column... cols) throws Throwable
     {
-        ColumnFamily cf = TreeMapBackedSortedColumns.factory.create(cfs.table.getName(), cfs.name);
+        ColumnFamily cf = TreeMapBackedSortedColumns.factory.create(cfs.keyspace.getName(), cfs.name);
         for (Column col : cols)
             cf.addColumn(col.withUpdatedName(CompositeType.build(scfName, col.name())));
-        RowMutation rm = new RowMutation(cfs.table.getName(), key.key, cf);
+        RowMutation rm = new RowMutation(cfs.keyspace.getName(), key.key, cf);
         rm.apply();
     }
 
     private static void putColsStandard(ColumnFamilyStore cfs, DecoratedKey key, Column... cols) throws Throwable
     {
-        ColumnFamily cf = TreeMapBackedSortedColumns.factory.create(cfs.table.getName(), cfs.name);
+        ColumnFamily cf = TreeMapBackedSortedColumns.factory.create(cfs.keyspace.getName(), cfs.name);
         for (Column col : cols)
             cf.addColumn(col);
-        RowMutation rm = new RowMutation(cfs.table.getName(), key.key, cf);
+        RowMutation rm = new RowMutation(cfs.keyspace.getName(), key.key, cf);
         rm.apply();
     }
 
@@ -755,10 +755,10 @@ public class ColumnFamilyStoreTest extends SchemaLoader
     public void testDeleteStandardRowSticksAfterFlush() throws Throwable
     {
         // test to make sure flushing after a delete doesn't resurrect delted cols.
-        String tableName = "Keyspace1";
+        String keyspaceName = "Keyspace1";
         String cfName = "Standard1";
-        Table table = Table.open(tableName);
-        ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
+        Keyspace keyspace = Keyspace.open(keyspaceName);
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName);
         DecoratedKey key = Util.dk("f-flush-resurrection");
 
         SlicePredicate sp = new SlicePredicate();
@@ -779,7 +779,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         assertRowAndColCount(1, 4, null, false, cfs.getRangeSlice(Util.range("f", "g"), null, ThriftValidation.asIFilter(sp, cfs.metadata, null), 100));
 
         // delete (from sstable and memtable)
-        RowMutation rm = new RowMutation(table.getName(), key.key);
+        RowMutation rm = new RowMutation(keyspace.getName(), key.key);
         rm.delete(cfs.name, 2);
         rm.apply();
 
@@ -841,11 +841,11 @@ public class ColumnFamilyStoreTest extends SchemaLoader
     @Test
     public void testSliceByNamesCommandOnUUIDTypeSCF() throws Throwable
     {
-        String tableName = "Keyspace1";
+        String keyspaceName = "Keyspace1";
         String cfName = "Super6";
         ByteBuffer superColName = LexicalUUIDType.instance.fromString("a4ed3562-0e8e-4b41-bdfd-c45a2774682d");
-        Table table = Table.open(tableName);
-        ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
+        Keyspace keyspace = Keyspace.open(keyspaceName);
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName);
         DecoratedKey key = Util.dk("slice-get-uuid-type");
 
         // Insert a row with one supercolumn and multiple subcolumns
@@ -861,8 +861,8 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         SortedSet<ByteBuffer> sliceColNames = new TreeSet<ByteBuffer>(cfs.metadata.comparator);
         sliceColNames.add(CompositeType.build(superColName, ByteBufferUtil.bytes("a")));
         sliceColNames.add(CompositeType.build(superColName, ByteBufferUtil.bytes("b")));
-        SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(tableName, key.key, cfName, System.currentTimeMillis(), new NamesQueryFilter(sliceColNames));
-        ColumnFamily cfSliced = cmd.getRow(table).cf;
+        SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(keyspaceName, key.key, cfName, System.currentTimeMillis(), new NamesQueryFilter(sliceColNames));
+        ColumnFamily cfSliced = cmd.getRow(keyspace).cf;
 
         // Make sure the slice returns the same as the straight get
         assertEquals(ByteBufferUtil.bytes("A"), cfSliced.getColumn(CompositeType.build(superColName, ByteBufferUtil.bytes("a"))).value());
@@ -872,12 +872,12 @@ public class ColumnFamilyStoreTest extends SchemaLoader
     @Test
     public void testSliceByNamesCommandOldMetatada() throws Throwable
     {
-        String tableName = "Keyspace1";
+        String keyspaceName = "Keyspace1";
         String cfName= "Standard1";
         DecoratedKey key = Util.dk("slice-name-old-metadata");
         ByteBuffer cname = ByteBufferUtil.bytes("c1");
-        Table table = Table.open(tableName);
-        ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
+        Keyspace keyspace = Keyspace.open(keyspaceName);
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName);
         cfs.clearUnsafe();
 
         // Create a column a 'high timestamp'
@@ -897,8 +897,8 @@ 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(tableName, key.key, cfName, System.currentTimeMillis(), new NamesQueryFilter(cname));
-        ColumnFamily cf = cmd.getRow(table).cf;
+        SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(keyspaceName, key.key, cfName, System.currentTimeMillis(), new NamesQueryFilter(cname));
+        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());
     }
@@ -917,10 +917,10 @@ public class ColumnFamilyStoreTest extends SchemaLoader
     @Test
     public void testRangeSliceColumnsLimit() throws Throwable
     {
-        String tableName = "Keyspace1";
+        String keyspaceName = "Keyspace1";
         String cfName = "Standard1";
-        Table table = Table.open(tableName);
-        ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
+        Keyspace keyspace = Keyspace.open(keyspaceName);
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName);
         cfs.clearUnsafe();
 
         Column[] cols = new Column[5];
@@ -1033,10 +1033,10 @@ public class ColumnFamilyStoreTest extends SchemaLoader
     @Test
     public void testRangeSlicePaging() throws Throwable
     {
-        String tableName = "Keyspace1";
+        String keyspaceName = "Keyspace1";
         String cfName = "Standard1";
-        Table table = Table.open(tableName);
-        ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
+        Keyspace keyspace = Keyspace.open(keyspaceName);
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName);
         cfs.clearUnsafe();
 
         Column[] cols = new Column[4];
@@ -1169,10 +1169,10 @@ public class ColumnFamilyStoreTest extends SchemaLoader
     @Test
     public void testRangeSliceInclusionExclusion() throws Throwable
     {
-        String tableName = "Keyspace1";
+        String keyspaceName = "Keyspace1";
         String cfName = "Standard1";
-        Table table = Table.open(tableName);
-        ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
+        Keyspace keyspace = Keyspace.open(keyspaceName);
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName);
         cfs.clearUnsafe();
 
         Column[] cols = new Column[5];
@@ -1223,8 +1223,8 @@ public class ColumnFamilyStoreTest extends SchemaLoader
     public void testKeysSearcher() throws Exception
     {
         // Create secondary index and flush to disk
-        Table table = Table.open("Keyspace1");
-        ColumnFamilyStore store = table.getColumnFamilyStore("Indexed1");
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamilyStore store = keyspace.getColumnFamilyStore("Indexed1");
 
         store.truncateBlocking();
 
@@ -1271,10 +1271,10 @@ public class ColumnFamilyStoreTest extends SchemaLoader
                 new ColumnSlice(bytes("colE"), bytes("colC")),
                 new ColumnSlice(bytes("colA"), ByteBuffer.wrap(EMPTY_BYTE_ARRAY)) };
 
-        String tableName = "Keyspace1";
+        String keyspaceName = "Keyspace1";
         String cfName = "Standard1";
-        Table table = Table.open(tableName);
-        ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
+        Keyspace keyspace = Keyspace.open(keyspaceName);
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName);
         cfs.clearUnsafe();
 
         String[] letters = new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i" };
@@ -1391,10 +1391,10 @@ public class ColumnFamilyStoreTest extends SchemaLoader
 
     private ColumnFamilyStore prepareMultiRangeSlicesTest(int valueSize, boolean flush) throws Throwable
     {
-        String tableName = "Keyspace1";
+        String keyspaceName = "Keyspace1";
         String cfName = "Standard1";
-        Table table = Table.open(tableName);
-        ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
+        Keyspace keyspace = Keyspace.open(keyspaceName);
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName);
         cfs.clearUnsafe();
 
         String[] letters = new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l" };

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/test/unit/org/apache/cassandra/db/CounterColumnTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/CounterColumnTest.java b/test/unit/org/apache/cassandra/db/CounterColumnTest.java
index 90fe76f..7c2be9f 100644
--- a/test/unit/org/apache/cassandra/db/CounterColumnTest.java
+++ b/test/unit/org/apache/cassandra/db/CounterColumnTest.java
@@ -60,7 +60,7 @@ public class CounterColumnTest extends SchemaLoader
     {
         long delta = 3L;
         CounterUpdateColumn cuc = new CounterUpdateColumn(ByteBufferUtil.bytes("x"), delta, 1L);
-        CounterColumn column = cuc.localCopy(Table.open("Keyspace5").getColumnFamilyStore("Counter1"));
+        CounterColumn column = cuc.localCopy(Keyspace.open("Keyspace5").getColumnFamilyStore("Counter1"));
 
         assert delta == column.total();
         assert 1 == column.value().getShort(0);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/test/unit/org/apache/cassandra/db/CounterMutationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/CounterMutationTest.java b/test/unit/org/apache/cassandra/db/CounterMutationTest.java
index 82141d8..3cbd030 100644
--- a/test/unit/org/apache/cassandra/db/CounterMutationTest.java
+++ b/test/unit/org/apache/cassandra/db/CounterMutationTest.java
@@ -64,7 +64,7 @@ public class CounterMutationTest extends SchemaLoader
         cm.apply();
 
         DecoratedKey dk = Util.dk("key1");
-        ColumnFamily cf = Util.getColumnFamily(Table.open("Keyspace1"), dk, "Counter1");
+        ColumnFamily cf = Util.getColumnFamily(Keyspace.open("Keyspace1"), dk, "Counter1");
 
         // First merges old shards
         CounterColumn.mergeAndRemoveOldShards(dk, cf, Integer.MIN_VALUE, Integer.MAX_VALUE, false);
@@ -99,16 +99,16 @@ public class CounterMutationTest extends SchemaLoader
     }
 
     @Test
-    public void testGetOldShardFromSystemTable() throws IOException
+    public void testGetOldShardFromSystemKeyspace() throws IOException
     {
         // Renewing a bunch of times and checking we get the same thing from
-        // the system table that what is in memory
+        // the system keyspace that what is in memory
         CounterId.renewLocalId();
         CounterId.renewLocalId();
         CounterId.renewLocalId();
 
         List<CounterId.CounterIdRecord> inMem = CounterId.getOldLocalCounterIds();
-        List<CounterId.CounterIdRecord> onDisk = SystemTable.getOldLocalCounterIds();
+        List<CounterId.CounterIdRecord> onDisk = SystemKeyspace.getOldLocalCounterIds();
 
         assert inMem.equals(onDisk);
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/test/unit/org/apache/cassandra/db/HintedHandOffTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/HintedHandOffTest.java b/test/unit/org/apache/cassandra/db/HintedHandOffTest.java
index c19efcb..8bbf5a9 100644
--- a/test/unit/org/apache/cassandra/db/HintedHandOffTest.java
+++ b/test/unit/org/apache/cassandra/db/HintedHandOffTest.java
@@ -45,7 +45,7 @@ import static org.apache.cassandra.cql3.QueryProcessor.processInternal;
 public class HintedHandOffTest extends SchemaLoader
 {
 
-    public static final String TABLE4 = "Keyspace4";
+    public static final String KEYSPACE4 = "Keyspace4";
     public static final String STANDARD1_CF = "Standard1";
     public static final String COLUMN1 = "column1";
 
@@ -54,15 +54,15 @@ public class HintedHandOffTest extends SchemaLoader
     public void testCompactionOfHintsCF() throws Exception
     {
         // prepare hints column family
-        Table systemTable = Table.open("system");
-        ColumnFamilyStore hintStore = systemTable.getColumnFamilyStore(SystemTable.HINTS_CF);
+        Keyspace systemKeyspace = Keyspace.open("system");
+        ColumnFamilyStore hintStore = systemKeyspace.getColumnFamilyStore(SystemKeyspace.HINTS_CF);
         hintStore.clearUnsafe();
         hintStore.metadata.gcGraceSeconds(36000); // 10 hours
         hintStore.setCompactionStrategyClass(SizeTieredCompactionStrategy.class.getCanonicalName());
         hintStore.disableAutoCompaction();
 
         // insert 1 hint
-        RowMutation rm = new RowMutation(TABLE4, ByteBufferUtil.bytes(1));
+        RowMutation rm = new RowMutation(KEYSPACE4, ByteBufferUtil.bytes(1));
         rm.add(STANDARD1_CF, ByteBufferUtil.bytes(String.valueOf(COLUMN1)), ByteBufferUtil.EMPTY_BYTE_BUFFER, System.currentTimeMillis());
 
         HintedHandOffManager.hintFor(rm, HintedHandOffManager.calculateHintTTL(rm), UUID.randomUUID()).apply();
@@ -88,7 +88,7 @@ public class HintedHandOffTest extends SchemaLoader
             HintedHandOffManager.instance.metrics.incrPastWindow(InetAddress.getLocalHost());
         HintedHandOffManager.instance.metrics.log();
 
-        UntypedResultSet rows = processInternal("SELECT hints_dropped FROM system." + SystemTable.PEER_EVENTS_CF);
+        UntypedResultSet rows = processInternal("SELECT hints_dropped FROM system." + SystemKeyspace.PEER_EVENTS_CF);
         Map<UUID, Integer> returned = rows.one().getMap("hints_dropped", UUIDType.instance, Int32Type.instance);
         assertEquals(Iterators.getLast(returned.values().iterator()).intValue(), 99);
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/test/unit/org/apache/cassandra/db/KeyCacheTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/KeyCacheTest.java b/test/unit/org/apache/cassandra/db/KeyCacheTest.java
index 922e255..e8e524d 100644
--- a/test/unit/org/apache/cassandra/db/KeyCacheTest.java
+++ b/test/unit/org/apache/cassandra/db/KeyCacheTest.java
@@ -41,7 +41,7 @@ import static junit.framework.Assert.assertEquals;
 
 public class KeyCacheTest extends SchemaLoader
 {
-    private static final String TABLE1 = "KeyCacheSpace";
+    private static final String KEYSPACE1 = "KeyCacheSpace";
     private static final String COLUMN_FAMILY1 = "Standard1";
     private static final String COLUMN_FAMILY2 = "Standard2";
 
@@ -56,18 +56,18 @@ public class KeyCacheTest extends SchemaLoader
     {
         CompactionManager.instance.disableAutoCompaction();
 
-        ColumnFamilyStore store = Table.open(TABLE1).getColumnFamilyStore(COLUMN_FAMILY2);
+        ColumnFamilyStore store = Keyspace.open(KEYSPACE1).getColumnFamilyStore(COLUMN_FAMILY2);
 
         // empty the cache
         CacheService.instance.invalidateKeyCache();
         assert CacheService.instance.keyCache.size() == 0;
 
         // insert data and force to disk
-        insertData(TABLE1, COLUMN_FAMILY2, 0, 100);
+        insertData(KEYSPACE1, COLUMN_FAMILY2, 0, 100);
         store.forceBlockingFlush();
 
         // populate the cache
-        readData(TABLE1, COLUMN_FAMILY2, 0, 100);
+        readData(KEYSPACE1, COLUMN_FAMILY2, 0, 100);
         assertEquals(100, CacheService.instance.keyCache.size());
 
         // really? our caches don't implement the map interface? (hence no .addAll)
@@ -89,8 +89,8 @@ public class KeyCacheTest extends SchemaLoader
     {
         CompactionManager.instance.disableAutoCompaction();
 
-        Table table = Table.open(TABLE1);
-        ColumnFamilyStore cfs = table.getColumnFamilyStore(COLUMN_FAMILY1);
+        Keyspace keyspace = Keyspace.open(KEYSPACE1);
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(COLUMN_FAMILY1);
 
         // just to make sure that everything is clean
         CacheService.instance.invalidateKeyCache();
@@ -103,10 +103,10 @@ public class KeyCacheTest extends SchemaLoader
         RowMutation rm;
 
         // inserts
-        rm = new RowMutation(TABLE1, key1.key);
+        rm = new RowMutation(KEYSPACE1, key1.key);
         rm.add(COLUMN_FAMILY1, ByteBufferUtil.bytes("1"), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0);
         rm.apply();
-        rm = new RowMutation(TABLE1, key2.key);
+        rm = new RowMutation(KEYSPACE1, key2.key);
         rm.add(COLUMN_FAMILY1, ByteBufferUtil.bytes("2"), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0);
         rm.apply();
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/test/unit/org/apache/cassandra/db/KeyCollisionTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/KeyCollisionTest.java b/test/unit/org/apache/cassandra/db/KeyCollisionTest.java
index a6fbecf..345febd 100644
--- a/test/unit/org/apache/cassandra/db/KeyCollisionTest.java
+++ b/test/unit/org/apache/cassandra/db/KeyCollisionTest.java
@@ -63,8 +63,8 @@ public class KeyCollisionTest extends SchemaLoader
     @Test
     public void testGetSliceWithCollision() throws Exception
     {
-        Table table = Table.open(KEYSPACE);
-        ColumnFamilyStore cfs = table.getColumnFamilyStore(CF);
+        Keyspace keyspace = Keyspace.open(KEYSPACE);
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF);
         cfs.clearUnsafe();
 
         insert("k1", "k2", "k3");       // token = 2
@@ -181,7 +181,7 @@ public class KeyCollisionTest extends SchemaLoader
                 lastToken = node;
             }
 
-            for (String ks : Schema.instance.getTables())
+            for (String ks : Schema.instance.getKeyspaces())
             {
                 for (CFMetaData cfmd : Schema.instance.getKSMetaData(ks).cfMetaData().values())
                 {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/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
new file mode 100644
index 0000000..faee4e7
--- /dev/null
+++ b/test/unit/org/apache/cassandra/db/KeyspaceTest.java
@@ -0,0 +1,649 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.*;
+import java.io.IOException;
+import java.util.concurrent.ExecutionException;
+
+import com.google.common.collect.Iterables;
+import org.apache.commons.lang.StringUtils;
+import org.junit.Test;
+
+import static junit.framework.Assert.*;
+import org.apache.cassandra.SchemaLoader;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.db.compaction.CompactionManager;
+import org.apache.cassandra.db.filter.QueryFilter;
+import org.apache.cassandra.db.marshal.BytesType;
+import org.apache.cassandra.db.marshal.CompositeType;
+import org.apache.cassandra.db.marshal.IntegerType;
+import org.apache.cassandra.utils.WrappedRunnable;
+import static org.apache.cassandra.Util.column;
+import static org.apache.cassandra.Util.expiringColumn;
+import static org.apache.cassandra.Util.getBytes;
+import static org.junit.Assert.assertEquals;
+import org.apache.cassandra.Util;
+import org.apache.cassandra.io.sstable.SSTableReader;
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+
+public class KeyspaceTest extends SchemaLoader
+{
+    private static final DecoratedKey TEST_KEY = Util.dk("key1");
+    private static final DecoratedKey TEST_SLICE_KEY = Util.dk("key1-slicerange");
+
+    public static void reTest(ColumnFamilyStore cfs, Runnable verify) throws Exception
+    {
+        verify.run();
+        cfs.forceBlockingFlush();
+        verify.run();
+    }
+
+    @Test
+    public void testGetRowNoColumns() throws Throwable
+    {
+        final Keyspace keyspace = Keyspace.open("Keyspace2");
+        final ColumnFamilyStore cfStore = keyspace.getColumnFamilyStore("Standard3");
+
+        ColumnFamily cf = TreeMapBackedSortedColumns.factory.create("Keyspace2", "Standard3");
+        cf.addColumn(column("col1","val1", 1L));
+        RowMutation rm = new RowMutation("Keyspace2", TEST_KEY.key, cf);
+        rm.apply();
+
+        Runnable verify = new WrappedRunnable()
+        {
+            public void runMayThrow() throws Exception
+            {
+                ColumnFamily cf;
+
+                cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY,
+                                                                        "Standard3",
+                                                                        new TreeSet<ByteBuffer>(),
+                                                                        System.currentTimeMillis()));
+                assertColumns(cf);
+
+                cf = cfStore.getColumnFamily(QueryFilter.getSliceFilter(TEST_KEY,
+                                                                        "Standard3",
+                                                                        ByteBufferUtil.EMPTY_BYTE_BUFFER,
+                                                                        ByteBufferUtil.EMPTY_BYTE_BUFFER,
+                                                                        false,
+                                                                        0,
+                                                                        System.currentTimeMillis()));
+                assertColumns(cf);
+
+                cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY,
+                                                                        "Standard3",
+                                                                        ByteBufferUtil.bytes("col99"),
+                                                                        System.currentTimeMillis()));
+                assertColumns(cf);
+            }
+        };
+        reTest(keyspace.getColumnFamilyStore("Standard3"), verify);
+    }
+
+    @Test
+    public void testGetRowSingleColumn() throws Throwable
+    {
+        final Keyspace keyspace = Keyspace.open("Keyspace1");
+        final ColumnFamilyStore cfStore = keyspace.getColumnFamilyStore("Standard1");
+
+        ColumnFamily cf = TreeMapBackedSortedColumns.factory.create("Keyspace1", "Standard1");
+        cf.addColumn(column("col1","val1", 1L));
+        cf.addColumn(column("col2","val2", 1L));
+        cf.addColumn(column("col3","val3", 1L));
+        RowMutation rm = new RowMutation("Keyspace1", TEST_KEY.key, cf);
+        rm.apply();
+
+        Runnable verify = new WrappedRunnable()
+        {
+            public void runMayThrow() throws Exception
+            {
+                ColumnFamily cf;
+
+                cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY,
+                                                                        "Standard1",
+                                                                        ByteBufferUtil.bytes("col1"),
+                                                                        System.currentTimeMillis()));
+                assertColumns(cf, "col1");
+
+                cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY,
+                                                                        "Standard1",
+                                                                        ByteBufferUtil.bytes("col3"),
+                                                                        System.currentTimeMillis()));
+                assertColumns(cf, "col3");
+            }
+        };
+        reTest(keyspace.getColumnFamilyStore("Standard1"), verify);
+    }
+
+    @Test
+    public void testGetRowSliceByRange() throws Throwable
+    {
+    	DecoratedKey key = TEST_SLICE_KEY;
+    	Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamilyStore cfStore = keyspace.getColumnFamilyStore("Standard1");
+        ColumnFamily cf = TreeMapBackedSortedColumns.factory.create("Keyspace1", "Standard1");
+        // First write "a", "b", "c"
+        cf.addColumn(column("a", "val1", 1L));
+        cf.addColumn(column("b", "val2", 1L));
+        cf.addColumn(column("c", "val3", 1L));
+        RowMutation rm = new RowMutation("Keyspace1", key.key, cf);
+        rm.apply();
+
+        cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("b"), ByteBufferUtil.bytes("c"), false, 100, System.currentTimeMillis());
+        assertEquals(2, cf.getColumnCount());
+
+        cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("b"), ByteBufferUtil.bytes("b"), false, 100, System.currentTimeMillis());
+        assertEquals(1, cf.getColumnCount());
+
+        cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("b"), ByteBufferUtil.bytes("c"), false, 1, System.currentTimeMillis());
+        assertEquals(1, cf.getColumnCount());
+    }
+
+    @Test
+    public void testGetSliceNoMatch() throws Throwable
+    {
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamily cf = TreeMapBackedSortedColumns.factory.create("Keyspace1", "Standard2");
+        cf.addColumn(column("col1", "val1", 1));
+        RowMutation rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("row1000"), cf);
+        rm.apply();
+
+        validateGetSliceNoMatch(keyspace);
+        keyspace.getColumnFamilyStore("Standard2").forceBlockingFlush();
+        validateGetSliceNoMatch(keyspace);
+
+        Collection<SSTableReader> ssTables = keyspace.getColumnFamilyStore("Standard2").getSSTables();
+        assertEquals(1, ssTables.size());
+        ssTables.iterator().next().forceFilterFailures();
+        validateGetSliceNoMatch(keyspace);
+    }
+
+    @Test
+    public void testGetSliceWithCutoff() throws Throwable
+    {
+        // tests slicing against data from one row in a memtable and then flushed to an sstable
+        final Keyspace keyspace = Keyspace.open("Keyspace1");
+        final ColumnFamilyStore cfStore = keyspace.getColumnFamilyStore("Standard1");
+        final DecoratedKey ROW = Util.dk("row4");
+        final NumberFormat fmt = new DecimalFormat("000");
+
+        ColumnFamily cf = TreeMapBackedSortedColumns.factory.create("Keyspace1", "Standard1");
+        // at this rate, we're getting 78-79 cos/block, assuming the blocks are set to be about 4k.
+        // so if we go to 300, we'll get at least 4 blocks, which is plenty for testing.
+        for (int i = 0; i < 300; i++)
+            cf.addColumn(column("col" + fmt.format(i), "omg!thisisthevalue!"+i, 1L));
+        RowMutation rm = new RowMutation("Keyspace1", ROW.key, cf);
+        rm.apply();
+
+        Runnable verify = new WrappedRunnable()
+        {
+            public void runMayThrow() throws Exception
+            {
+                ColumnFamily cf;
+
+                // blocks are partitioned like this: 000-097, 098-193, 194-289, 290-299, assuming a 4k column index size.
+                assert DatabaseDescriptor.getColumnIndexSize() == 4096 : "Unexpected column index size, block boundaries won't be where tests expect them.";
+
+                // test forward, spanning a segment.
+                cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col096"), ByteBufferUtil.bytes("col099"), false, 4, System.currentTimeMillis());
+                assertColumns(cf, "col096", "col097", "col098", "col099");
+
+                // test reversed, spanning a segment.
+                cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col099"), ByteBufferUtil.bytes("col096"), true, 4, System.currentTimeMillis());
+                assertColumns(cf, "col096", "col097", "col098", "col099");
+
+                // test forward, within a segment.
+                cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col100"), ByteBufferUtil.bytes("col103"), false, 4, System.currentTimeMillis());
+                assertColumns(cf, "col100", "col101", "col102", "col103");
+
+                // test reversed, within a segment.
+                cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col103"), ByteBufferUtil.bytes("col100"), true, 4, System.currentTimeMillis());
+                assertColumns(cf, "col100", "col101", "col102", "col103");
+
+                // test forward from beginning, spanning a segment.
+                String[] strCols = new String[100]; // col000-col099
+                for (int i = 0; i < 100; i++)
+                    strCols[i] = "col" + fmt.format(i);
+                cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.bytes("col099"), false, 100, System.currentTimeMillis());
+                assertColumns(cf, strCols);
+
+                // test reversed, from end, spanning a segment.
+                cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.bytes("col288"), true, 12, System.currentTimeMillis());
+                assertColumns(cf, "col288", "col289", "col290", "col291", "col292", "col293", "col294", "col295", "col296", "col297", "col298", "col299");
+            }
+        };
+
+        reTest(keyspace.getColumnFamilyStore("Standard1"), verify);
+    }
+
+    @Test
+    public void testReversedWithFlushing() throws IOException, ExecutionException, InterruptedException
+    {
+        final Keyspace keyspace = Keyspace.open("Keyspace1");
+        final ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("StandardLong1");
+        final DecoratedKey ROW = Util.dk("row4");
+
+        for (int i = 0; i < 10; i++)
+        {
+            ColumnFamily cf = TreeMapBackedSortedColumns.factory.create("Keyspace1", "StandardLong1");
+            cf.addColumn(new Column(ByteBufferUtil.bytes((long)i), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0));
+            RowMutation rm = new RowMutation("Keyspace1", ROW.key, cf);
+            rm.apply();
+        }
+
+        cfs.forceBlockingFlush();
+
+        for (int i = 10; i < 20; i++)
+        {
+            ColumnFamily cf = TreeMapBackedSortedColumns.factory.create("Keyspace1", "StandardLong1");
+            cf.addColumn(new Column(ByteBufferUtil.bytes((long)i), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0));
+            RowMutation rm = new RowMutation("Keyspace1", ROW.key, cf);
+            rm.apply();
+
+            cf = cfs.getColumnFamily(ROW, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 1, System.currentTimeMillis());
+            assertEquals(1, Iterables.size(cf.getColumnNames()));
+            assertEquals(i, cf.getColumnNames().iterator().next().getLong());
+        }
+    }
+
+    private void validateGetSliceNoMatch(Keyspace keyspace) throws IOException
+    {
+        ColumnFamilyStore cfStore = keyspace.getColumnFamilyStore("Standard2");
+        ColumnFamily cf;
+
+        // key before the rows that exists
+        cf = cfStore.getColumnFamily(Util.dk("a"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1, System.currentTimeMillis());
+        assertColumns(cf);
+
+        // key after the rows that exist
+        cf = cfStore.getColumnFamily(Util.dk("z"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1, System.currentTimeMillis());
+        assertColumns(cf);
+    }
+
+    @Test
+    public void testGetSliceFromBasic() throws Throwable
+    {
+        // tests slicing against data from one row in a memtable and then flushed to an sstable
+        final Keyspace keyspace = Keyspace.open("Keyspace1");
+        final ColumnFamilyStore cfStore = keyspace.getColumnFamilyStore("Standard1");
+        final DecoratedKey ROW = Util.dk("row1");
+
+        ColumnFamily cf = TreeMapBackedSortedColumns.factory.create("Keyspace1", "Standard1");
+        cf.addColumn(column("col1", "val1", 1L));
+        cf.addColumn(column("col3", "val3", 1L));
+        cf.addColumn(column("col4", "val4", 1L));
+        cf.addColumn(column("col5", "val5", 1L));
+        cf.addColumn(column("col7", "val7", 1L));
+        cf.addColumn(column("col9", "val9", 1L));
+        RowMutation rm = new RowMutation("Keyspace1", ROW.key, cf);
+        rm.apply();
+
+        rm = new RowMutation("Keyspace1", ROW.key);
+        rm.delete("Standard1", ByteBufferUtil.bytes("col4"), 2L);
+        rm.apply();
+
+        Runnable verify = new WrappedRunnable()
+        {
+            public void runMayThrow() throws Exception
+            {
+                ColumnFamily cf;
+
+                cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col5"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 2, System.currentTimeMillis());
+                assertColumns(cf, "col5", "col7");
+
+                cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col4"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 2, System.currentTimeMillis());
+                assertColumns(cf, "col4", "col5", "col7");
+                assertColumns(ColumnFamilyStore.removeDeleted(cf, Integer.MAX_VALUE), "col5", "col7");
+
+                cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col5"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2, System.currentTimeMillis());
+                assertColumns(cf, "col3", "col4", "col5");
+
+                cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col6"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2, System.currentTimeMillis());
+                assertColumns(cf, "col3", "col4", "col5");
+
+                cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2, System.currentTimeMillis());
+                assertColumns(cf, "col7", "col9");
+
+                cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col95"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 2, System.currentTimeMillis());
+                assertColumns(cf);
+
+                cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col0"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2, System.currentTimeMillis());
+                assertColumns(cf);
+            }
+        };
+
+        reTest(keyspace.getColumnFamilyStore("Standard1"), verify);
+    }
+
+    @Test
+    public void testGetSliceWithExpiration() throws Throwable
+    {
+        // tests slicing against data from one row with expiring column in a memtable and then flushed to an sstable
+        final Keyspace keyspace = Keyspace.open("Keyspace1");
+        final ColumnFamilyStore cfStore = keyspace.getColumnFamilyStore("Standard1");
+        final DecoratedKey ROW = Util.dk("row5");
+
+        ColumnFamily cf = TreeMapBackedSortedColumns.factory.create("Keyspace1", "Standard1");
+        cf.addColumn(column("col1", "val1", 1L));
+        cf.addColumn(expiringColumn("col2", "val2", 1L, 60)); // long enough not to be tombstoned
+        cf.addColumn(column("col3", "val3", 1L));
+        RowMutation rm = new RowMutation("Keyspace1", ROW.key, cf);
+        rm.apply();
+
+        Runnable verify = new WrappedRunnable()
+        {
+            public void runMayThrow() throws Exception
+            {
+                ColumnFamily cf;
+
+                cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 2, System.currentTimeMillis());
+                assertColumns(cf, "col1", "col2");
+                assertColumns(ColumnFamilyStore.removeDeleted(cf, Integer.MAX_VALUE), "col1");
+
+                cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col2"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1, System.currentTimeMillis());
+                assertColumns(cf, "col2");
+                assertColumns(ColumnFamilyStore.removeDeleted(cf, Integer.MAX_VALUE));
+            }
+        };
+
+        reTest(keyspace.getColumnFamilyStore("Standard1"), verify);
+    }
+
+    @Test
+    public void testGetSliceFromAdvanced() throws Throwable
+    {
+        // tests slicing against data from one row spread across two sstables
+        final Keyspace keyspace = Keyspace.open("Keyspace1");
+        final ColumnFamilyStore cfStore = keyspace.getColumnFamilyStore("Standard1");
+        final DecoratedKey ROW = Util.dk("row2");
+
+        ColumnFamily cf = TreeMapBackedSortedColumns.factory.create("Keyspace1", "Standard1");
+        cf.addColumn(column("col1", "val1", 1L));
+        cf.addColumn(column("col2", "val2", 1L));
+        cf.addColumn(column("col3", "val3", 1L));
+        cf.addColumn(column("col4", "val4", 1L));
+        cf.addColumn(column("col5", "val5", 1L));
+        cf.addColumn(column("col6", "val6", 1L));
+        RowMutation rm = new RowMutation("Keyspace1", ROW.key, cf);
+        rm.apply();
+        cfStore.forceBlockingFlush();
+
+        cf = TreeMapBackedSortedColumns.factory.create("Keyspace1", "Standard1");
+        cf.addColumn(column("col1", "valx", 2L));
+        cf.addColumn(column("col2", "valx", 2L));
+        cf.addColumn(column("col3", "valx", 2L));
+        rm = new RowMutation("Keyspace1", ROW.key, cf);
+        rm.apply();
+
+        Runnable verify = new WrappedRunnable()
+        {
+            public void runMayThrow() throws Exception
+            {
+                ColumnFamily cf;
+
+                cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col2"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 3, System.currentTimeMillis());
+                assertColumns(cf, "col2", "col3", "col4");
+
+                ByteBuffer col = cf.getColumn(ByteBufferUtil.bytes("col2")).value();
+                assertEquals(ByteBufferUtil.string(col), "valx");
+
+                col = cf.getColumn(ByteBufferUtil.bytes("col3")).value();
+                assertEquals(ByteBufferUtil.string(col), "valx");
+
+                col = cf.getColumn(ByteBufferUtil.bytes("col4")).value();
+                assertEquals(ByteBufferUtil.string(col), "val4");
+            }
+        };
+
+        reTest(keyspace.getColumnFamilyStore("Standard1"), verify);
+    }
+
+    @Test
+    public void testGetSliceFromLarge() throws Throwable
+    {
+        // tests slicing against 1000 columns in an sstable
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamilyStore cfStore = keyspace.getColumnFamilyStore("Standard1");
+        DecoratedKey key = Util.dk("row3");
+        ColumnFamily cf = TreeMapBackedSortedColumns.factory.create("Keyspace1", "Standard1");
+        for (int i = 1000; i < 2000; i++)
+            cf.addColumn(column("col" + i, ("v" + i), 1L));
+        RowMutation rm = new RowMutation("Keyspace1", key.key, cf);
+        rm.apply();
+        cfStore.forceBlockingFlush();
+
+        validateSliceLarge(cfStore);
+
+        // compact so we have a big row with more than the minimum index count
+        if (cfStore.getSSTables().size() > 1)
+        {
+            CompactionManager.instance.performMaximal(cfStore);
+        }
+        // verify that we do indeed have multiple index entries
+        SSTableReader sstable = cfStore.getSSTables().iterator().next();
+        RowIndexEntry indexEntry = sstable.getPosition(key, SSTableReader.Operator.EQ);
+        assert indexEntry.columnsIndex().size() > 2;
+
+        validateSliceLarge(cfStore);
+    }
+
+    @Test
+    public void testLimitSSTables() throws CharacterCodingException, InterruptedException
+    {
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamilyStore cfStore = keyspace.getColumnFamilyStore("Standard1");
+        cfStore.disableAutoCompaction();
+        DecoratedKey key = Util.dk("row_maxmin");
+        for (int j = 0; j < 10; j++)
+        {
+            ColumnFamily cf = TreeMapBackedSortedColumns.factory.create("Keyspace1", "Standard1");
+            for (int i = 1000 + (j*100); i < 1000 + ((j+1)*100); i++)
+            {
+                cf.addColumn(column("col" + i, ("v" + i), i));
+            }
+            RowMutation rm = new RowMutation("Keyspace1", key.key, cf);
+            rm.apply();
+            cfStore.forceBlockingFlush();
+        }
+        cfStore.metric.sstablesPerReadHistogram.clear();
+        ColumnFamily cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes(""), ByteBufferUtil.bytes("col1499"), false, 1000, System.currentTimeMillis());
+        assertEquals(cfStore.metric.sstablesPerReadHistogram.max(), 5, 0.1);
+        int i = 0;
+        for (Column c : cf.getSortedColumns())
+        {
+            assertEquals(ByteBufferUtil.string(c.name), "col" + (1000 + i++));
+        }
+        assertEquals(i, 500);
+        cfStore.metric.sstablesPerReadHistogram.clear();
+        cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("col1500"), ByteBufferUtil.bytes("col2000"), false, 1000, System.currentTimeMillis());
+        assertEquals(cfStore.metric.sstablesPerReadHistogram.max(), 5, 0.1);
+
+        for (Column c : cf.getSortedColumns())
+        {
+            assertEquals(ByteBufferUtil.string(c.name), "col"+(1000 + i++));
+        }
+        assertEquals(i, 1000);
+
+        // reverse
+        cfStore.metric.sstablesPerReadHistogram.clear();
+        cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("col2000"), ByteBufferUtil.bytes("col1500"), true, 1000, System.currentTimeMillis());
+        assertEquals(cfStore.metric.sstablesPerReadHistogram.max(), 5, 0.1);
+        i = 500;
+        for (Column c : cf.getSortedColumns())
+        {
+            assertEquals(ByteBufferUtil.string(c.name), "col"+(1000 + i++));
+        }
+        assertEquals(i, 1000);
+
+    }
+
+    @Test
+    public void testLimitSSTablesComposites() throws CharacterCodingException, ExecutionException, InterruptedException
+    {
+        /*
+        creates 10 sstables, composite columns like this:
+        ---------------------
+        k   |a0:0|a1:1|..|a9:9
+        ---------------------
+        ---------------------
+        k   |a0:10|a1:11|..|a9:19
+        ---------------------
+        ...
+        ---------------------
+        k   |a0:90|a1:91|..|a9:99
+        ---------------------
+        then we slice out col1 = a5 and col2 > 85 -> which should let us just check 2 sstables and get 2 columns
+         */
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("StandardComposite2");
+        cfs.disableAutoCompaction();
+
+        CompositeType ct = CompositeType.getInstance(BytesType.instance, IntegerType.instance);
+        DecoratedKey key = Util.dk("k");
+        for (int j = 0; j < 10; j++)
+        {
+            for (int i = 0; i < 10; i++)
+            {
+                RowMutation rm = new RowMutation("Keyspace1", key.key);
+                ByteBuffer colName = ct.builder().add(ByteBufferUtil.bytes("a" + i)).add(ByteBufferUtil.bytes(j*10 + i)).build();
+                rm.add("StandardComposite2", colName, ByteBufferUtil.EMPTY_BYTE_BUFFER, 0);
+                rm.apply();
+            }
+            cfs.forceBlockingFlush();
+        }
+        ByteBuffer start = ct.builder().add(ByteBufferUtil.bytes("a5")).add(ByteBufferUtil.bytes(85)).build();
+        ByteBuffer finish = ct.builder().add(ByteBufferUtil.bytes("a5")).buildAsEndOfRange();
+        cfs.metric.sstablesPerReadHistogram.clear();
+        ColumnFamily cf = cfs.getColumnFamily(key, start, finish, false, 1000, System.currentTimeMillis());
+        int colCount = 0;
+        for (Column c : cf)
+            colCount++;
+        assertEquals(2, colCount);
+        assertEquals(2, cfs.metric.sstablesPerReadHistogram.max(), 0.1);
+    }
+
+    private void validateSliceLarge(ColumnFamilyStore cfStore) throws IOException
+    {
+        DecoratedKey key = Util.dk("row3");
+        ColumnFamily cf;
+        cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("col1000"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 3, System.currentTimeMillis());
+        assertColumns(cf, "col1000", "col1001", "col1002");
+
+        ByteBuffer col;
+        col = cf.getColumn(ByteBufferUtil.bytes("col1000")).value();
+        assertEquals(ByteBufferUtil.string(col), "v1000");
+        col = cf.getColumn(ByteBufferUtil.bytes("col1001")).value();
+        assertEquals(ByteBufferUtil.string(col), "v1001");
+        col = cf.getColumn(ByteBufferUtil.bytes("col1002")).value();
+        assertEquals(ByteBufferUtil.string(col), "v1002");
+
+        cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("col1195"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 3, System.currentTimeMillis());
+        assertColumns(cf, "col1195", "col1196", "col1197");
+
+        col = cf.getColumn(ByteBufferUtil.bytes("col1195")).value();
+        assertEquals(ByteBufferUtil.string(col), "v1195");
+        col = cf.getColumn(ByteBufferUtil.bytes("col1196")).value();
+        assertEquals(ByteBufferUtil.string(col), "v1196");
+        col = cf.getColumn(ByteBufferUtil.bytes("col1197")).value();
+        assertEquals(ByteBufferUtil.string(col), "v1197");
+
+
+        cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("col1996"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 1000, System.currentTimeMillis());
+        Column[] columns = cf.getSortedColumns().toArray(new Column[0]);
+        for (int i = 1000; i < 1996; i++)
+        {
+            String expectedName = "col" + i;
+            Column column = columns[i - 1000];
+            assertEquals(ByteBufferUtil.string(column.name()), expectedName);
+            assertEquals(ByteBufferUtil.string(column.value()), ("v" + i));
+        }
+
+        cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("col1990"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 3, System.currentTimeMillis());
+        assertColumns(cf, "col1990", "col1991", "col1992");
+        col = cf.getColumn(ByteBufferUtil.bytes("col1990")).value();
+        assertEquals(ByteBufferUtil.string(col), "v1990");
+        col = cf.getColumn(ByteBufferUtil.bytes("col1991")).value();
+        assertEquals(ByteBufferUtil.string(col), "v1991");
+        col = cf.getColumn(ByteBufferUtil.bytes("col1992")).value();
+        assertEquals(ByteBufferUtil.string(col), "v1992");
+
+        cf = cfStore.getColumnFamily(key, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 3, System.currentTimeMillis());
+        assertColumns(cf, "col1997", "col1998", "col1999");
+        col = cf.getColumn(ByteBufferUtil.bytes("col1997")).value();
+        assertEquals(ByteBufferUtil.string(col), "v1997");
+        col = cf.getColumn(ByteBufferUtil.bytes("col1998")).value();
+        assertEquals(ByteBufferUtil.string(col), "v1998");
+        col = cf.getColumn(ByteBufferUtil.bytes("col1999")).value();
+        assertEquals(ByteBufferUtil.string(col), "v1999");
+
+        cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("col9000"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 3, System.currentTimeMillis());
+        assertColumns(cf, "col1997", "col1998", "col1999");
+
+        cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("col9000"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 3, System.currentTimeMillis());
+        assertColumns(cf);
+    }
+
+    public static void assertColumns(ColumnFamily container, String... columnNames)
+    {
+        Collection<Column> columns = container == null ? new TreeSet<Column>() : container.getSortedColumns();
+        List<String> L = new ArrayList<String>();
+        for (Column column : columns)
+        {
+            try
+            {
+                L.add(ByteBufferUtil.string(column.name()));
+            }
+            catch (CharacterCodingException e)
+            {
+                throw new AssertionError(e);
+            }
+        }
+
+        List<String> names = new ArrayList<String>(columnNames.length);
+
+        names.addAll(Arrays.asList(columnNames));
+
+        String[] columnNames1 = names.toArray(new String[0]);
+        String[] la = L.toArray(new String[columns.size()]);
+
+        assert Arrays.equals(la, columnNames1)
+                : String.format("Columns [%s])] is not expected [%s]",
+                                ((container == null) ? "" : container.getComparator().getColumnsString(columns)),
+                                StringUtils.join(columnNames1, ","));
+    }
+
+    public static void assertColumn(ColumnFamily cf, String name, String value, long timestamp)
+    {
+        assertColumn(cf.getColumn(ByteBufferUtil.bytes(name)), value, timestamp);
+    }
+
+    public static void assertColumn(Column column, String value, long timestamp)
+    {
+        assertNotNull(column);
+        assertEquals(0, ByteBufferUtil.compareUnsigned(column.value(), ByteBufferUtil.bytes(value)));
+        assertEquals(timestamp, column.timestamp());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/test/unit/org/apache/cassandra/db/MultitableTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/MultitableTest.java b/test/unit/org/apache/cassandra/db/MultitableTest.java
index 606af98..3d0c8ac 100644
--- a/test/unit/org/apache/cassandra/db/MultitableTest.java
+++ b/test/unit/org/apache/cassandra/db/MultitableTest.java
@@ -27,7 +27,7 @@ import java.util.concurrent.ExecutionException;
 import org.apache.cassandra.Util;
 import org.junit.Test;
 
-import static org.apache.cassandra.db.TableTest.assertColumns;
+import static org.apache.cassandra.db.KeyspaceTest.assertColumns;
 import org.apache.cassandra.SchemaLoader;
 import static org.apache.cassandra.Util.column;
 
@@ -36,8 +36,8 @@ public class MultitableTest extends SchemaLoader
     @Test
     public void testSameCFs() throws IOException, ExecutionException, InterruptedException
     {
-        Table table1 = Table.open("Keyspace1");
-        Table table2 = Table.open("Keyspace2");
+        Keyspace keyspace1 = Keyspace.open("Keyspace1");
+        Keyspace keyspace2 = Keyspace.open("Keyspace2");
 
         RowMutation rm;
         DecoratedKey dk = Util.dk("keymulti");
@@ -53,10 +53,10 @@ public class MultitableTest extends SchemaLoader
         rm = new RowMutation("Keyspace2", dk.key, cf);
         rm.apply();
 
-        table1.getColumnFamilyStore("Standard1").forceBlockingFlush();
-        table2.getColumnFamilyStore("Standard1").forceBlockingFlush();
+        keyspace1.getColumnFamilyStore("Standard1").forceBlockingFlush();
+        keyspace2.getColumnFamilyStore("Standard1").forceBlockingFlush();
 
-        assertColumns(Util.getColumnFamily(table1, dk, "Standard1"), "col1");
-        assertColumns(Util.getColumnFamily(table2, dk, "Standard1"), "col2");
+        assertColumns(Util.getColumnFamily(keyspace1, dk, "Standard1"), "col1");
+        assertColumns(Util.getColumnFamily(keyspace2, dk, "Standard1"), "col2");
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/test/unit/org/apache/cassandra/db/NameSortTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/NameSortTest.java b/test/unit/org/apache/cassandra/db/NameSortTest.java
index 97a4a8a..4babab2 100644
--- a/test/unit/org/apache/cassandra/db/NameSortTest.java
+++ b/test/unit/org/apache/cassandra/db/NameSortTest.java
@@ -56,7 +56,7 @@ public class NameSortTest extends SchemaLoader
 
     private void testNameSort(int N) throws IOException, ExecutionException, InterruptedException
     {
-        Table table = Table.open("Keyspace1");
+        Keyspace keyspace = Keyspace.open("Keyspace1");
 
         for (int i = 0; i < N; ++i)
         {
@@ -85,21 +85,21 @@ public class NameSortTest extends SchemaLoader
             }
         }
 
-        validateNameSort(table, N);
+        validateNameSort(keyspace, N);
 
-        table.getColumnFamilyStore("Standard1").forceBlockingFlush();
-        table.getColumnFamilyStore("Super1").forceBlockingFlush();
-        validateNameSort(table, N);
+        keyspace.getColumnFamilyStore("Standard1").forceBlockingFlush();
+        keyspace.getColumnFamilyStore("Super1").forceBlockingFlush();
+        validateNameSort(keyspace, N);
     }
 
-    private void validateNameSort(Table table, int N) throws IOException
+    private void validateNameSort(Keyspace keyspace, int N) throws IOException
     {
         for (int i = 0; i < N; ++i)
         {
             DecoratedKey key = Util.dk(Integer.toString(i));
             ColumnFamily cf;
 
-            cf = Util.getColumnFamily(table, key, "Standard1");
+            cf = Util.getColumnFamily(keyspace, key, "Standard1");
             Collection<Column> columns = cf.getSortedColumns();
             for (Column column : columns)
             {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/test/unit/org/apache/cassandra/db/RangeTombstoneTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/RangeTombstoneTest.java b/test/unit/org/apache/cassandra/db/RangeTombstoneTest.java
index 0ed0c4a..9d04cfd 100644
--- a/test/unit/org/apache/cassandra/db/RangeTombstoneTest.java
+++ b/test/unit/org/apache/cassandra/db/RangeTombstoneTest.java
@@ -38,8 +38,8 @@ public class RangeTombstoneTest extends SchemaLoader
     @Test
     public void simpleQueryWithRangeTombstoneTest() throws Exception
     {
-        Table table = Table.open(KSNAME);
-        ColumnFamilyStore cfs = table.getColumnFamilyStore(CFNAME);
+        Keyspace keyspace = Keyspace.open(KSNAME);
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CFNAME);
 
         // Inserting data
         String key = "k1";
@@ -98,8 +98,8 @@ public class RangeTombstoneTest extends SchemaLoader
     public void overlappingRangeTest() throws Exception
     {
         CompactionManager.instance.disableAutoCompaction();
-        Table table = Table.open(KSNAME);
-        ColumnFamilyStore cfs = table.getColumnFamilyStore(CFNAME);
+        Keyspace keyspace = Keyspace.open(KSNAME);
+        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CFNAME);
 
         // Inserting data
         String key = "k2";

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/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 cc15fe7..b16b921 100644
--- a/test/unit/org/apache/cassandra/db/ReadMessageTest.java
+++ b/test/unit/org/apache/cassandra/db/ReadMessageTest.java
@@ -85,7 +85,7 @@ public class ReadMessageTest extends SchemaLoader
     @Test
     public void testGetColumn() throws IOException, ColumnFamilyNotDefinedException
     {
-        Table table = Table.open("Keyspace1");
+        Keyspace keyspace = Keyspace.open("Keyspace1");
         RowMutation rm;
         DecoratedKey dk = Util.dk("key1");
 
@@ -95,7 +95,7 @@ public class ReadMessageTest extends SchemaLoader
         rm.apply();
 
         ReadCommand command = new SliceByNamesReadCommand("Keyspace1", dk.key, "Standard1", System.currentTimeMillis(), new NamesQueryFilter(ByteBufferUtil.bytes("Column1")));
-        Row row = command.getRow(table);
+        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/0e96e585/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java b/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java
index 0e743f6..ac2d642 100644
--- a/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java
+++ b/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java
@@ -43,7 +43,7 @@ public class RecoveryManager2Test extends SchemaLoader
     public void testWithFlush() throws Exception
     {
         // Flush everything that may be in the commit log now to start fresh
-        FBUtilities.waitOnFutures(Table.open(Table.SYSTEM_KS).flush());
+        FBUtilities.waitOnFutures(Keyspace.open(Keyspace.SYSTEM_KS).flush());
 
         CompactionManager.instance.disableAutoCompaction();
 
@@ -56,8 +56,8 @@ public class RecoveryManager2Test extends SchemaLoader
             insertRow("Standard1", key);
         }
 
-        Table table1 = Table.open("Keyspace1");
-        ColumnFamilyStore cfs = table1.getColumnFamilyStore("Standard1");
+        Keyspace keyspace1 = Keyspace.open("Keyspace1");
+        ColumnFamilyStore cfs = keyspace1.getColumnFamilyStore("Standard1");
         logger.debug("forcing flush");
         cfs.forceBlockingFlush();
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/test/unit/org/apache/cassandra/db/RecoveryManager3Test.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/RecoveryManager3Test.java b/test/unit/org/apache/cassandra/db/RecoveryManager3Test.java
index dcc0901..8258970 100644
--- a/test/unit/org/apache/cassandra/db/RecoveryManager3Test.java
+++ b/test/unit/org/apache/cassandra/db/RecoveryManager3Test.java
@@ -34,15 +34,15 @@ import org.apache.cassandra.db.commitlog.CommitLog;
 import org.apache.cassandra.io.util.FileUtils;
 
 import static org.apache.cassandra.Util.column;
-import static org.apache.cassandra.db.TableTest.assertColumns;
+import static org.apache.cassandra.db.KeyspaceTest.assertColumns;
 
 public class RecoveryManager3Test extends SchemaLoader
 {
     @Test
     public void testMissingHeader() throws IOException, ExecutionException, InterruptedException
     {
-        Table table1 = Table.open("Keyspace1");
-        Table table2 = Table.open("Keyspace2");
+        Keyspace keyspace1 = Keyspace.open("Keyspace1");
+        Keyspace keyspace2 = Keyspace.open("Keyspace2");
 
         RowMutation rm;
         DecoratedKey dk = Util.dk("keymulti");
@@ -58,8 +58,8 @@ public class RecoveryManager3Test extends SchemaLoader
         rm = new RowMutation("Keyspace2", dk.key, cf);
         rm.apply();
 
-        table1.getColumnFamilyStore("Standard1").clearUnsafe();
-        table2.getColumnFamilyStore("Standard3").clearUnsafe();
+        keyspace1.getColumnFamilyStore("Standard1").clearUnsafe();
+        keyspace2.getColumnFamilyStore("Standard3").clearUnsafe();
 
         // nuke the header
         for (File file : new File(DatabaseDescriptor.getCommitLogLocation()).listFiles())
@@ -71,7 +71,7 @@ public class RecoveryManager3Test extends SchemaLoader
         CommitLog.instance.resetUnsafe(); // disassociate segments from live CL
         CommitLog.instance.recover();
 
-        assertColumns(Util.getColumnFamily(table1, dk, "Standard1"), "col1");
-        assertColumns(Util.getColumnFamily(table2, dk, "Standard3"), "col2");
+        assertColumns(Util.getColumnFamily(keyspace1, dk, "Standard1"), "col1");
+        assertColumns(Util.getColumnFamily(keyspace2, dk, "Standard3"), "col2");
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/test/unit/org/apache/cassandra/db/RecoveryManagerTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/RecoveryManagerTest.java b/test/unit/org/apache/cassandra/db/RecoveryManagerTest.java
index a98a401..bd15bbf 100644
--- a/test/unit/org/apache/cassandra/db/RecoveryManagerTest.java
+++ b/test/unit/org/apache/cassandra/db/RecoveryManagerTest.java
@@ -29,7 +29,7 @@ import org.apache.cassandra.db.commitlog.CommitLog;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 import static org.apache.cassandra.Util.column;
-import static org.apache.cassandra.db.TableTest.assertColumns;
+import static org.apache.cassandra.db.KeyspaceTest.assertColumns;
 
 public class RecoveryManagerTest extends SchemaLoader
 {
@@ -41,8 +41,8 @@ public class RecoveryManagerTest extends SchemaLoader
     @Test
     public void testOne() throws IOException, ExecutionException, InterruptedException
     {
-        Table table1 = Table.open("Keyspace1");
-        Table table2 = Table.open("Keyspace2");
+        Keyspace keyspace1 = Keyspace.open("Keyspace1");
+        Keyspace keyspace2 = Keyspace.open("Keyspace2");
 
         RowMutation rm;
         DecoratedKey dk = Util.dk("keymulti");
@@ -58,20 +58,20 @@ public class RecoveryManagerTest extends SchemaLoader
         rm = new RowMutation("Keyspace2", dk.key, cf);
         rm.apply();
 
-        table1.getColumnFamilyStore("Standard1").clearUnsafe();
-        table2.getColumnFamilyStore("Standard3").clearUnsafe();
+        keyspace1.getColumnFamilyStore("Standard1").clearUnsafe();
+        keyspace2.getColumnFamilyStore("Standard3").clearUnsafe();
 
         CommitLog.instance.resetUnsafe(); // disassociate segments from live CL
         CommitLog.instance.recover();
 
-        assertColumns(Util.getColumnFamily(table1, dk, "Standard1"), "col1");
-        assertColumns(Util.getColumnFamily(table2, dk, "Standard3"), "col2");
+        assertColumns(Util.getColumnFamily(keyspace1, dk, "Standard1"), "col1");
+        assertColumns(Util.getColumnFamily(keyspace2, dk, "Standard3"), "col2");
     }
 
     @Test
     public void testRecoverCounter() throws IOException, ExecutionException, InterruptedException
     {
-        Table table1 = Table.open("Keyspace1");
+        Keyspace keyspace1 = Keyspace.open("Keyspace1");
 
         RowMutation rm;
         DecoratedKey dk = Util.dk("key");
@@ -85,12 +85,12 @@ public class RecoveryManagerTest extends SchemaLoader
             rm.apply();
         }
 
-        table1.getColumnFamilyStore("Counter1").clearUnsafe();
+        keyspace1.getColumnFamilyStore("Counter1").clearUnsafe();
 
         CommitLog.instance.resetUnsafe(); // disassociate segments from live CL
         CommitLog.instance.recover();
 
-        cf = Util.getColumnFamily(table1, dk, "Counter1");
+        cf = Util.getColumnFamily(keyspace1, dk, "Counter1");
 
         assert cf.getColumnCount() == 1;
         Column c = cf.getColumn(ByteBufferUtil.bytes("col"));

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/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 5e34e91..b98a8b0 100644
--- a/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java
+++ b/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java
@@ -40,8 +40,8 @@ public class RecoveryManagerTruncateTest extends SchemaLoader
 	@Test
 	public void testTruncate() throws IOException, ExecutionException, InterruptedException
 	{
-		Table table = Table.open("Keyspace1");
-		ColumnFamilyStore cfs = table.getColumnFamilyStore("Standard1");
+		Keyspace keyspace = Keyspace.open("Keyspace1");
+		ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Standard1");
 
 		RowMutation rm;
 		ColumnFamily cf;
@@ -53,7 +53,7 @@ public class RecoveryManagerTruncateTest extends SchemaLoader
 		rm.apply();
 
 		// Make sure data was written
-		assertNotNull(getFromTable(table, "Standard1", "keymulti", "col1"));
+		assertNotNull(getFromTable(keyspace, "Standard1", "keymulti", "col1"));
 
 		// and now truncate it
 		cfs.truncateBlocking();
@@ -61,13 +61,13 @@ public class RecoveryManagerTruncateTest extends SchemaLoader
 		CommitLog.instance.recover();
 
 		// and validate truncation.
-		assertNull(getFromTable(table, "Standard1", "keymulti", "col1"));
+		assertNull(getFromTable(keyspace, "Standard1", "keymulti", "col1"));
 	}
 
-	private Column getFromTable(Table table, String cfName, String keyName, String columnName)
+	private Column getFromTable(Keyspace keyspace, String cfName, String keyName, String columnName)
 	{
 		ColumnFamily cf;
-		ColumnFamilyStore cfStore = table.getColumnFamilyStore(cfName);
+		ColumnFamilyStore cfStore = keyspace.getColumnFamilyStore(cfName);
 		if (cfStore == null)
 		{
 			return null;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/test/unit/org/apache/cassandra/db/RemoveColumnFamilyTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyTest.java b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyTest.java
index 345f967..f937709 100644
--- a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyTest.java
+++ b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyTest.java
@@ -36,8 +36,8 @@ public class RemoveColumnFamilyTest extends SchemaLoader
     @Test
     public void testRemoveColumnFamily() throws IOException, ExecutionException, InterruptedException
     {
-        Table table = Table.open("Keyspace1");
-        ColumnFamilyStore store = table.getColumnFamilyStore("Standard1");
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamilyStore store = keyspace.getColumnFamilyStore("Standard1");
         RowMutation rm;
         DecoratedKey dk = Util.dk("key1");
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush1Test.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush1Test.java b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush1Test.java
index bd97e00..08913c6 100644
--- a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush1Test.java
+++ b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush1Test.java
@@ -36,8 +36,8 @@ public class RemoveColumnFamilyWithFlush1Test extends SchemaLoader
     @Test
     public void testRemoveColumnFamilyWithFlush1() throws IOException, ExecutionException, InterruptedException
     {
-        Table table = Table.open("Keyspace1");
-        ColumnFamilyStore store = table.getColumnFamilyStore("Standard1");
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamilyStore store = keyspace.getColumnFamilyStore("Standard1");
         RowMutation rm;
         DecoratedKey dk = Util.dk("key1");
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0e96e585/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush2Test.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush2Test.java b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush2Test.java
index 037c5dd..b7fc640 100644
--- a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush2Test.java
+++ b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush2Test.java
@@ -36,8 +36,8 @@ public class RemoveColumnFamilyWithFlush2Test extends SchemaLoader
     @Test
     public void testRemoveColumnFamilyWithFlush2() throws IOException, ExecutionException, InterruptedException
     {
-        Table table = Table.open("Keyspace1");
-        ColumnFamilyStore store = table.getColumnFamilyStore("Standard1");
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamilyStore store = keyspace.getColumnFamilyStore("Standard1");
         RowMutation rm;
         DecoratedKey dk = Util.dk("key1");