cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yu...@apache.org
Subject [2/6] git commit: fix saved key cache not loading at startup; patch by yukim reviewed by jbellis for CASSANDRA-5166
Date Fri, 18 Jan 2013 17:48:56 GMT
fix saved key cache not loading at startup; patch by yukim reviewed by jbellis for CASSANDRA-5166


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

Branch: refs/heads/cassandra-1.2
Commit: f930eb79cd4567efaeca44142bf8ea93a181f37e
Parents: 1311649
Author: Yuki Morishita <yukim@apache.org>
Authored: Fri Jan 18 11:47:01 2013 -0600
Committer: Yuki Morishita <yukim@apache.org>
Committed: Fri Jan 18 11:47:01 2013 -0600

----------------------------------------------------------------------
 CHANGES.txt                                        |    3 +
 .../apache/cassandra/io/sstable/SSTableReader.java |    4 +-
 .../cassandra/io/sstable/SSTableReaderTest.java    |   32 +++++++++++++++
 3 files changed, 38 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f930eb79/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index afee142..2a19ed5 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,6 @@
+1.1.10
+ * fix saved key cache not loading at startup (CASSANDRA-5166)
+
 1.1.9
  * Simplify CompressedRandomAccessReader to work around JDK FD bug (CASSANDRA-5088)
  * Improve handling a changing target throttle rate mid-compaction (CASSANDRA-5087)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f930eb79/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
index f3305b5..18d77ee 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
@@ -353,7 +353,9 @@ public class SSTableReader extends SSTable
      */
     private void load(boolean recreatebloom, Set<DecoratedKey> keysToLoadInCache) throws
IOException
     {
-        boolean cacheLoading = keyCache != null && !keysToLoadInCache.isEmpty();
+        boolean cacheLoading = !keysToLoadInCache.isEmpty();
+        if (cacheLoading && keyCache == null)
+            keyCache = CacheService.instance.keyCache;
 
         SegmentedFile.Builder ibuilder = SegmentedFile.getBuilder(DatabaseDescriptor.getIndexAccessMode());
         SegmentedFile.Builder dbuilder = compression

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f930eb79/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java b/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
index 004dac8..fd0c1c6 100644
--- a/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
+++ b/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
@@ -35,7 +35,10 @@ import org.junit.Test;
 
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.Util;
+import org.apache.cassandra.cache.KeyCacheKey;
+import org.apache.cassandra.config.CFMetaData;
 import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.config.Schema;
 import org.apache.cassandra.db.*;
 import org.apache.cassandra.db.columniterator.IdentityQueryFilter;
 import org.apache.cassandra.db.compaction.CompactionManager;
@@ -43,6 +46,7 @@ import org.apache.cassandra.db.filter.QueryPath;
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.dht.Range;
 import org.apache.cassandra.dht.Token;
+import org.apache.cassandra.io.util.SequentialWriter;
 import org.apache.cassandra.service.CacheService;
 import org.apache.cassandra.io.util.FileDataInput;
 import org.apache.cassandra.io.util.FileUtils;
@@ -284,6 +288,34 @@ public class SSTableReaderTest extends SchemaLoader
         assert target.last.equals(lastKey);
     }
 
+    @Test
+    public void testLoadingSavedKeyCache() throws Exception
+    {
+        final String ks = "Keyspace1";
+        final String cf = "Standard1";
+        CFMetaData meta = Schema.instance.getCFMetaData(ks, cf);
+        Table.clear(ks);
+
+        ByteBuffer key = ByteBufferUtil.bytes("key");
+        CacheService.instance.keyCache.setCapacity(1024);
+        File dir = Directories.create(ks, cf).getDirectoryForNewSSTables(100);
+        SSTableSimpleWriter writer = new SSTableSimpleWriter(dir, meta, StorageService.getPartitioner());
+        writer.newRow(key);
+        writer.addColumn(ByteBufferUtil.bytes("col"), ByteBufferUtil.EMPTY_BYTE_BUFFER, 1);
+        writer.close();
+        Descriptor desc = Descriptor.fromFilename(dir, String.format("%s-%s-%s-1-Data.db",
ks, cf, Descriptor.CURRENT_VERSION)).left;
+
+        File cachePath = CacheService.instance.keyCache.getCachePath(ks, cf);
+        SequentialWriter out = SequentialWriter.open(cachePath);
+        new KeyCacheKey(desc, key).write(out.stream);
+        out.close();
+
+        ColumnFamilyStore cfs = Table.open(ks).getColumnFamilyStore(cf);
+        cfs.disableAutoCompaction();
+        SSTableReader sstable = cfs.getSSTables().iterator().next();
+        assert 0 == sstable.getCachedPosition(StorageService.getPartitioner().decorateKey(key),
false);
+    }
+
     private void assertIndexQueryWorks(ColumnFamilyStore indexedCFS) throws IOException
     {
         assert "Indexed1".equals(indexedCFS.getColumnFamilyName());


Mime
View raw message