Updated Branches: refs/heads/cassandra-1.0 fbdf7b03c -> 1e18538c9 refs/heads/cassandra-1.1 11bdcd6d7 -> d685f45ee refs/heads/cassandra-1.1.0 643d18af2 -> 5697c3997 refs/heads/trunk e571ec2c6 -> 830495027
merge from 1.1 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/83049502 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/83049502 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/83049502 Branch: refs/heads/trunk Commit: 83049502795d83a498c2c0d22b6042de64eb977f Parents: e571ec2 d685f45 Author: Jonathan Ellis <jbel...@apache.org> Authored: Fri Mar 23 10:02:23 2012 -0500 Committer: Jonathan Ellis <jbel...@apache.org> Committed: Fri Mar 23 10:02:23 2012 -0500 ---------------------------------------------------------------------- CHANGES.txt | 3 +- build.xml | 2 +- debian/changelog | 8 +- .../org/apache/cassandra/cache/IRowCacheEntry.java | 27 +++- .../apache/cassandra/cache/RowCacheSentinel.java | 107 +++++++++------ .../apache/cassandra/io/sstable/SSTableReader.java | 25 ++-- .../org/apache/cassandra/utils/ByteBufferUtil.java | 4 +- .../cassandra/io/sstable/SSTableReaderTest.java | 42 ++++++ 8 files changed, 153 insertions(+), 65 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/83049502/CHANGES.txt ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/83049502/src/java/org/apache/cassandra/io/sstable/SSTableReader.java ---------------------------------------------------------------------- diff --cc src/java/org/apache/cassandra/io/sstable/SSTableReader.java index 864e11f,2715613..9e92220 --- a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java +++ b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java @@@ -357,23 -366,28 +357,28 @@@ public class SSTableReader extends SSTa if (indexPosition == indexSize) break; - ByteBuffer key = null, skippedKey; - skippedKey = ByteBufferUtil.readWithShortLength(input); + DecoratedKey decoratedKey = null; + int len = ByteBufferUtil.readShortLength(input); + boolean firstKey = left == null; - boolean lastKey = indexPosition + DBConstants.shortSize + len + DBConstants.longSize == indexSize; ++ boolean lastKey = indexPosition + DBConstants.SHORT_SIZE + len + DBConstants.LONG_SIZE == indexSize; boolean shouldAddEntry = indexSummary.shouldAddEntry(); - if (shouldAddEntry || cacheLoading || recreatebloom) + if (shouldAddEntry || cacheLoading || recreatebloom || firstKey || lastKey) { - key = skippedKey; + decoratedKey = decodeKey(partitioner, descriptor, ByteBufferUtil.read(input, len)); + if (firstKey) + left = decoratedKey; + if (lastKey) + right = decoratedKey; + } + else + { + FileUtils.skipBytesFully(input, len); } - - if(null == left) - left = decodeKey(partitioner, descriptor, skippedKey); - right = decodeKey(partitioner, descriptor, skippedKey); - long dataPosition = input.readLong(); + RowIndexEntry indexEntry = RowIndexEntry.serializer.deserialize(input, descriptor); - if (key != null) + if (decoratedKey != null) { - DecoratedKey decoratedKey = decodeKey(partitioner, descriptor, key); if (recreatebloom) bf.add(decoratedKey.key); if (shouldAddEntry) http://git-wip-us.apache.org/repos/asf/cassandra/blob/83049502/src/java/org/apache/cassandra/utils/ByteBufferUtil.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/83049502/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java ---------------------------------------------------------------------- diff --cc test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java index 22e1233,102fccd..544f9e6 --- a/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java +++ b/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java @@@ -242,6 -244,46 +244,46 @@@ public class SSTableReaderTest extends assertIndexQueryWorks(store); } + @Test + public void testOpeningSSTable() throws Exception + { + String ks = "Keyspace1"; + String cf = "Standard1"; + + // clear and create just one sstable for this test + Table table = Table.open(ks); + ColumnFamilyStore store = table.getColumnFamilyStore(cf); + store.clearUnsafe(); + store.disableAutoCompaction(); + + DecoratedKey firstKey = null, lastKey = null; + long timestamp = System.currentTimeMillis(); + for (int i = 0; i < DatabaseDescriptor.getIndexInterval(); i++) { + DecoratedKey key = Util.dk(String.valueOf(i)); + if (firstKey == null) + firstKey = key; + if (lastKey == null) + lastKey = key; + if (store.metadata.getKeyValidator().compare(lastKey.key, key.key) < 0) + lastKey = key; + RowMutation rm = new RowMutation(ks, key.key); + rm.add(new QueryPath(cf, null, ByteBufferUtil.bytes("col")), + ByteBufferUtil.EMPTY_BYTE_BUFFER, timestamp); + rm.apply(); + } + store.forceBlockingFlush(); + + SSTableReader sstable = store.getSSTables().iterator().next(); + Descriptor desc = sstable.descriptor; + + // test to see if sstable can be opened as expected + SSTableReader target = SSTableReader.open(desc); - Collection<DecoratedKey<?>> keySamples = target.getKeySamples(); ++ Collection<DecoratedKey> keySamples = target.getKeySamples(); + assert keySamples.size() == 1 && keySamples.iterator().next().equals(firstKey); + assert target.first.equals(firstKey); + assert target.last.equals(lastKey); + } + private void assertIndexQueryWorks(ColumnFamilyStore indexedCFS) throws IOException { assert "Indexed1".equals(indexedCFS.getColumnFamilyName());