Updated Branches: refs/heads/cassandra-1.1 c7ce11f00 -> c710edf07 refs/heads/trunk ec14be929 -> ad8ebc684
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/ad8ebc68 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/ad8ebc68 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/ad8ebc68 Branch: refs/heads/trunk Commit: ad8ebc684a2e8226b88da80c98dd0e252a18dbb7 Parents: ec14be9 c710edf Author: Jonathan Ellis <[email protected]> Authored: Fri Sep 28 10:15:31 2012 -0500 Committer: Jonathan Ellis <[email protected]> Committed: Fri Sep 28 10:15:31 2012 -0500 ---------------------------------------------------------------------- .../org/apache/cassandra/cache/KeyCacheKey.java | 9 +----- .../apache/cassandra/io/sstable/SSTableReader.java | 21 +++++++++++++- .../apache/cassandra/io/sstable/SSTableWriter.java | 1 + 3 files changed, 21 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/ad8ebc68/src/java/org/apache/cassandra/cache/KeyCacheKey.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/ad8ebc68/src/java/org/apache/cassandra/io/sstable/SSTableReader.java ---------------------------------------------------------------------- diff --cc src/java/org/apache/cassandra/io/sstable/SSTableReader.java index fd4874c,a4cca37..b89ee24 --- a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java +++ b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java @@@ -686,10 -651,12 +686,12 @@@ public class SSTableReader extends SSTa return; // avoid keeping a permanent reference to the original key buffer - keyCache.put(new KeyCacheKey(descriptor, ByteBufferUtil.clone(key.key)), info); + KeyCacheKey cacheKey = new KeyCacheKey(descriptor, ByteBufferUtil.clone(key.key)); + logger.trace("Adding cache entry for {} -> {}", cacheKey, info); + keyCache.put(cacheKey, info); } - public Long getCachedPosition(DecoratedKey key, boolean updateStats) + public RowIndexEntry getCachedPosition(DecoratedKey key, boolean updateStats) { return getCachedPosition(new KeyCacheKey(descriptor, key.key), updateStats); } @@@ -731,9 -698,13 +733,13 @@@ if ((op == Operator.EQ || op == Operator.GE) && (key instanceof DecoratedKey)) { DecoratedKey decoratedKey = (DecoratedKey)key; - RowIndexEntry cachedPosition = getCachedPosition(new KeyCacheKey(descriptor, decoratedKey.key), updateCacheAndStats); + KeyCacheKey cacheKey = new KeyCacheKey(descriptor, decoratedKey.key); - Long cachedPosition = getCachedPosition(cacheKey, updateCacheAndStats); ++ RowIndexEntry cachedPosition = getCachedPosition(cacheKey, updateCacheAndStats); if (cachedPosition != null) + { + logger.trace("Cache hit for {} -> {}", cacheKey, cachedPosition); return cachedPosition; + } } // next, see if the sampled index says it's impossible for the key to be present @@@ -793,8 -738,22 +799,19 @@@ { assert key instanceof DecoratedKey; // key can be == to the index key only if it's a true row key DecoratedKey decoratedKey = (DecoratedKey)key; + + if (logger.isTraceEnabled()) + { + // expensive sanity check! see CASSANDRA-4687 - FileDataInput fdi = dfile.getSegment(dataPosition); ++ FileDataInput fdi = dfile.getSegment(indexEntry.position); + DecoratedKey keyInDisk = SSTableReader.decodeKey(partitioner, descriptor, ByteBufferUtil.readWithShortLength(fdi)); + if (!keyInDisk.equals(key)) + throw new AssertionError(String.format("%s != %s in %s", keyInDisk, key, fdi.getPath())); + fdi.close(); + } + - if (keyCache != null && keyCache.getCapacity() > 0 && updateCacheAndStats) - { - // store exact match for the key - cacheKey(decoratedKey, dataPosition); - } + // store exact match for the key + cacheKey(decoratedKey, indexEntry); } if (op == Operator.EQ && updateCacheAndStats) bloomFilterTracker.addTruePositive(); http://git-wip-us.apache.org/repos/asf/cassandra/blob/ad8ebc68/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java ---------------------------------------------------------------------- diff --cc src/java/org/apache/cassandra/io/sstable/SSTableWriter.java index 898ef4a,5a6ca38..0d92a76 --- a/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java +++ b/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java @@@ -124,9 -127,10 +124,10 @@@ public class SSTableWriter extends SSTa /** * Perform sanity checks on @param decoratedKey and @return the position in the data file before any data is written */ - private long beforeAppend(DecoratedKey<?> decoratedKey) throws IOException + private long beforeAppend(DecoratedKey decoratedKey) { assert decoratedKey != null : "Keys must not be null"; + assert decoratedKey.key.remaining() > 0 : "Keys must not be empty"; if (lastWrittenKey != null && lastWrittenKey.compareTo(decoratedKey) >= 0) throw new RuntimeException("Last written key " + lastWrittenKey + " >= current key " + decoratedKey + " writing into " + getFilename()); return (lastWrittenKey == null) ? 0 : dataFile.getFilePointer();
