Repository: cassandra
Updated Branches:
  refs/heads/cassandra-3.0 44164bc3a -> 4378b58bb


Don't throw assertion error on old key cache keys just skip serializing them.

patch by aweisberg; reviewed by slebresne for CASSANDRA-10778


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

Branch: refs/heads/cassandra-3.0
Commit: 4378b58bba61ec6e7eb0bbfa5733cf9800a7dec3
Parents: 44164bc
Author: Ariel Weisberg <ariel.weisb...@datastax.com>
Authored: Mon Nov 30 14:43:50 2015 -0500
Committer: Sylvain Lebresne <sylv...@datastax.com>
Committed: Tue Dec 1 10:27:10 2015 +0100

----------------------------------------------------------------------
 CHANGES.txt                                      |  1 +
 .../apache/cassandra/service/CacheService.java   |  4 ++++
 .../cassandra/io/sstable/LegacySSTableTest.java  | 19 ++++++++++++++++++-
 3 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/4378b58b/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 0356045..bd14e67 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.1
+ * Fix error when saving cached key for old format sstable (CASSANDRA-10778)
  * Invalidate prepared statements on DROP INDEX (CASSANDRA-10758)
  * Fix SELECT statement with IN restrictions on partition key,
    ORDER BY and LIMIT (CASSANDRA-10729)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4378b58b/src/java/org/apache/cassandra/service/CacheService.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/CacheService.java 
b/src/java/org/apache/cassandra/service/CacheService.java
index a3e7d12..c51a5d1 100644
--- a/src/java/org/apache/cassandra/service/CacheService.java
+++ b/src/java/org/apache/cassandra/service/CacheService.java
@@ -455,6 +455,10 @@ public class CacheService implements CacheServiceMBean
     {
         public void serialize(KeyCacheKey key, DataOutputPlus out, 
ColumnFamilyStore cfs) throws IOException
         {
+            //Don't serialize old format entries since we didn't bother to 
implement serialization of both for simplicity
+            //https://issues.apache.org/jira/browse/CASSANDRA-10778
+            if (!key.desc.version.storeRows()) return;
+
             RowIndexEntry entry = 
CacheService.instance.keyCache.getInternal(key);
             if (entry == null)
                 return;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/4378b58b/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java 
b/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java
index 0578d44..00727b8 100644
--- a/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java
+++ b/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java
@@ -56,6 +56,7 @@ import org.apache.cassandra.io.sstable.format.SSTableReader;
 import org.apache.cassandra.io.sstable.format.Version;
 import org.apache.cassandra.io.sstable.format.big.BigFormat;
 import org.apache.cassandra.schema.KeyspaceParams;
+import org.apache.cassandra.service.CacheService;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.streaming.StreamPlan;
 import org.apache.cassandra.streaming.StreamSession;
@@ -238,7 +239,7 @@ public class LegacySSTableTest
         loadLegacyTables();
     }
 
-    private static void loadLegacyTables() throws IOException
+    private static void loadLegacyTables() throws Exception
     {
         for (String legacyVersion : legacyVersions)
         {
@@ -251,6 +252,8 @@ public class LegacySSTableTest
             loadLegacyTable("legacy_%s_clust", legacyVersion);
             loadLegacyTable("legacy_%s_clust_counter", legacyVersion);
 
+            CacheService.instance.invalidateKeyCache();
+            long startCount = CacheService.instance.keyCache.size();
             for (int ck = 0; ck < 50; ck++)
             {
                 String ckValue = Integer.toString(ck) + longString;
@@ -286,6 +289,20 @@ public class LegacySSTableTest
                     Assert.assertEquals(1L, rs.one().getLong("val"));
                 }
             }
+
+            //For https://issues.apache.org/jira/browse/CASSANDRA-10778
+            //Validate whether the key cache successfully saves in the 
presence of old keys as
+            //well as loads the correct number of keys
+            long endCount = CacheService.instance.keyCache.size();
+            Assert.assertTrue(endCount > startCount);
+            
CacheService.instance.keyCache.submitWrite(Integer.MAX_VALUE).get();
+            CacheService.instance.invalidateKeyCache();
+            Assert.assertEquals(startCount, 
CacheService.instance.keyCache.size());
+            CacheService.instance.keyCache.loadSaved();
+            if (BigFormat.instance.getVersion(legacyVersion).storeRows())
+                Assert.assertEquals(endCount, 
CacheService.instance.keyCache.size());
+            else
+                Assert.assertEquals(startCount, 
CacheService.instance.keyCache.size());
         }
     }
 

Reply via email to