Author: brandonwilliams Date: Thu Mar 3 17:40:59 2011 New Revision: 1076699
URL: http://svn.apache.org/viewvc?rev=1076699&view=rev Log: CFS correctly flushes index CFs. Patch by jbellis, reviewed by brandonwilliams for CASSANDRA-2244 Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyStore.java cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyStore.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyStore.java?rev=1076699&r1=1076698&r2=1076699&view=diff ============================================================================== --- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyStore.java (original) +++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyStore.java Thu Mar 3 17:40:59 2011 @@ -685,8 +685,11 @@ public class ColumnFamilyStore implement { if (oldMemtable.isFrozen()) return null; - - if (DatabaseDescriptor.getCFMetaData(metadata.cfId) == null) + + boolean isDropped = isIndex() + ? DatabaseDescriptor.getCFMetaData(table.name, getParentColumnfamily()) == null + : DatabaseDescriptor.getCFMetaData(metadata.cfId) == null; + if (isDropped) return null; // column family was dropped. no point in flushing. assert memtable == oldMemtable; @@ -2113,6 +2116,12 @@ public class ColumnFamilyStore implement return partitioner instanceof LocalPartitioner; } + private String getParentColumnfamily() + { + assert isIndex(); + return columnFamily.split("\\.")[0]; + } + /** * sets each cache's maximum capacity to 75% of its current size */ Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java?rev=1076699&r1=1076698&r2=1076699&view=diff ============================================================================== --- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java (original) +++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java Thu Mar 3 17:40:59 2011 @@ -307,7 +307,7 @@ public class ColumnFamilyStoreTest exten } @Test - public void testIndexCreate() throws IOException, ConfigurationException, InterruptedException + public void testIndexCreate() throws IOException, ConfigurationException, InterruptedException, ExecutionException { Table table = Table.open("Keyspace1"); @@ -324,6 +324,9 @@ public class ColumnFamilyStoreTest exten while (!SystemTable.isIndexBuilt("Keyspace1", cfs.getIndexedColumnFamilyStore(ByteBufferUtil.bytes("birthdate")).columnFamily)) TimeUnit.MILLISECONDS.sleep(100); + // we had a bug (CASSANDRA-2244) where index would get created but not flushed -- check for that + assert cfs.getIndexedColumnFamilyStore(cd.name).getSSTables().size() > 0; + IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(1L)); IndexClause clause = new IndexClause(Arrays.asList(expr), ByteBufferUtil.EMPTY_BYTE_BUFFER, 100); IFilter filter = new IdentityQueryFilter(); @@ -331,8 +334,7 @@ public class ColumnFamilyStoreTest exten Range range = new Range(p.getMinimumToken(), p.getMinimumToken()); List<Row> rows = table.getColumnFamilyStore("Indexed2").scan(clause, range, filter); assert rows.size() == 1 : StringUtils.join(rows, ","); - String key = new String(rows.get(0).key.key.array(),rows.get(0).key.key.position(),rows.get(0).key.key.remaining()); - assert "k1".equals( key ); + assertEquals("k1", ByteBufferUtil.string(rows.get(0).key.key)); } @Test