cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject cassandra git commit: Add Branimir's test from CASSANDRA-10219
Date Fri, 09 Oct 2015 12:01:45 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 ad93f3b6e -> 94b6471b9


Add Branimir's test from CASSANDRA-10219


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

Branch: refs/heads/cassandra-2.1
Commit: 94b6471b93cc55dd078158e7eb00416b79e5d034
Parents: ad93f3b
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Fri Oct 9 13:50:24 2015 +0200
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Fri Oct 9 14:00:30 2015 +0200

----------------------------------------------------------------------
 .../org/apache/cassandra/db/KeyCacheTest.java   | 55 ++++++++++++++++++++
 1 file changed, 55 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/94b6471b/test/unit/org/apache/cassandra/db/KeyCacheTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/KeyCacheTest.java b/test/unit/org/apache/cassandra/db/KeyCacheTest.java
index 4a4c7d5..d3328f1 100644
--- a/test/unit/org/apache/cassandra/db/KeyCacheTest.java
+++ b/test/unit/org/apache/cassandra/db/KeyCacheTest.java
@@ -17,12 +17,14 @@
  */
 package org.apache.cassandra.db;
 
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.Uninterruptibles;
 import org.junit.AfterClass;
 import org.junit.Test;
@@ -31,6 +33,7 @@ import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.Util;
 import org.apache.cassandra.cache.KeyCacheKey;
 import org.apache.cassandra.concurrent.ScheduledExecutors;
+import org.apache.cassandra.db.compaction.OperationType;
 import org.apache.cassandra.db.composites.*;
 import org.apache.cassandra.db.compaction.CompactionManager;
 import org.apache.cassandra.db.filter.QueryFilter;
@@ -46,6 +49,8 @@ public class KeyCacheTest extends SchemaLoader
     private static final String KEYSPACE1 = "KeyCacheSpace";
     private static final String COLUMN_FAMILY1 = "Standard1";
     private static final String COLUMN_FAMILY2 = "Standard2";
+    private static final String COLUMN_FAMILY3 = "Standard3";
+
 
     @AfterClass
     public static void cleanup()
@@ -104,6 +109,56 @@ public class KeyCacheTest extends SchemaLoader
     }
 
     @Test
+    public void testKeyCacheLoadWithLostTable() throws Exception
+    {
+        CompactionManager.instance.disableAutoCompaction();
+
+        ColumnFamilyStore store = Keyspace.open(KEYSPACE1).getColumnFamilyStore(COLUMN_FAMILY3);
+
+        // empty the cache
+        CacheService.instance.invalidateKeyCache();
+        assertKeyCacheSize(0, KEYSPACE1, COLUMN_FAMILY3);
+
+        // insert data and force to disk
+        insertData(KEYSPACE1, COLUMN_FAMILY3, 0, 100);
+        store.forceBlockingFlush();
+
+        Collection<SSTableReader> firstFlushTables = ImmutableList.copyOf(store.getSSTables());
+
+        // populate the cache
+        readData(KEYSPACE1, COLUMN_FAMILY3, 0, 100);
+        assertKeyCacheSize(100, KEYSPACE1, COLUMN_FAMILY3);
+
+        // insert some new data and force to disk
+        insertData(KEYSPACE1, COLUMN_FAMILY3, 100, 50);
+        store.forceBlockingFlush();
+
+        // check that it's fine
+        readData(KEYSPACE1, COLUMN_FAMILY3, 100, 50);
+        assertKeyCacheSize(150, KEYSPACE1, COLUMN_FAMILY3);
+
+        // force the cache to disk
+        CacheService.instance.keyCache.submitWrite(Integer.MAX_VALUE).get();
+
+        CacheService.instance.invalidateKeyCache();
+        assertKeyCacheSize(0, KEYSPACE1, COLUMN_FAMILY3);
+
+        // check that the content is written correctly
+        CacheService.instance.keyCache.loadSaved();
+        assertKeyCacheSize(150, KEYSPACE1, COLUMN_FAMILY3);
+
+        CacheService.instance.invalidateKeyCache();
+        assertKeyCacheSize(0, KEYSPACE1, COLUMN_FAMILY3);
+
+        // now remove the first sstable from the store to simulate losing the file
+        store.markObsolete(firstFlushTables, OperationType.UNKNOWN);
+
+        // check that reading now correctly skips over lost table and reads the rest (CASSANDRA-10219)
+        CacheService.instance.keyCache.loadSaved();
+        assertKeyCacheSize(50, KEYSPACE1, COLUMN_FAMILY3);
+    }
+
+    @Test
     public void testKeyCache() throws ExecutionException, InterruptedException
     {
         CompactionManager.instance.disableAutoCompaction();


Mime
View raw message