You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2010/06/01 21:26:34 UTC
svn commit: r950222 - in /cassandra/branches/cassandra-0.6: ./
src/java/org/apache/cassandra/cache/ src/java/org/apache/cassandra/db/
src/java/org/apache/cassandra/io/ test/conf/
test/unit/org/apache/cassandra/db/
Author: jbellis
Date: Tue Jun 1 19:26:34 2010
New Revision: 950222
URL: http://svn.apache.org/viewvc?rev=950222&view=rev
Log:
fix cache capacity only being recalculated once. patch by Jon Heremes; reviewed by jbellis for CASSANDRA-1129
Modified:
cassandra/branches/cassandra-0.6/CHANGES.txt
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/InstrumentedCache.java
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/SSTableTracker.java
cassandra/branches/cassandra-0.6/test/conf/storage-conf.xml
cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java
Modified: cassandra/branches/cassandra-0.6/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/CHANGES.txt?rev=950222&r1=950221&r2=950222&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.6/CHANGES.txt Tue Jun 1 19:26:34 2010
@@ -3,6 +3,8 @@
* fix potential for duplicate rows seen by Hadoop jobs (CASSANDRA-1042)
* reject describe_ring() calls on invalid keyspaces (CASSANDRA-1111)
* fix cache size calculation for size of 100% (CASSANDRA-1129)
+ * fix cache capacity only being recalculated once (CASSANDRA-1129)
+
0.6.2
* fix contrib/word_count build. (CASSANDRA-992)
Modified: cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/InstrumentedCache.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/InstrumentedCache.java?rev=950222&r1=950221&r2=950222&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/InstrumentedCache.java (original)
+++ cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/InstrumentedCache.java Tue Jun 1 19:26:34 2010
@@ -33,7 +33,7 @@ public class InstrumentedCache<K, V>
private final AtomicLong hits = new AtomicLong(0);
private final AtomicLong lastRequests = new AtomicLong(0);
private final AtomicLong lastHits = new AtomicLong(0);
- private volatile boolean capacityModified;
+ private volatile boolean capacitySetManually;
public InstrumentedCache(int capacity)
{
@@ -70,17 +70,22 @@ public class InstrumentedCache<K, V>
return capacity;
}
- public boolean isCapacityModified()
+ public boolean isCapacitySetManually()
{
- return capacityModified;
+ return capacitySetManually;
}
-
- public void setCapacity(int capacity)
+
+ public void updateCapacity(int capacity)
{
map.setCapacity(capacity);
this.capacity = capacity;
- capacityModified = true;
- }
+ }
+
+ public void setCapacity(int capacity)
+ {
+ updateCapacity(capacity);
+ capacitySetManually = true;
+ }
public int getSize()
{
Modified: cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStore.java?rev=950222&r1=950221&r2=950222&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStore.java (original)
+++ cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStore.java Tue Jun 1 19:26:34 2010
@@ -1140,6 +1140,16 @@ public class ColumnFamilyStore implement
ssTables_.getRowCache().clear();
}
+ public int getRowCacheSize()
+ {
+ return ssTables_.getRowCache().getCapacity();
+ }
+
+ public int getKeyCacheSize()
+ {
+ return ssTables_.getKeyCache().getCapacity();
+ }
+
public static Iterable<ColumnFamilyStore> all()
{
Iterable<ColumnFamilyStore>[] stores = new Iterable[DatabaseDescriptor.getTables().size()];
Modified: cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/SSTableTracker.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/SSTableTracker.java?rev=950222&r1=950221&r2=950222&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/SSTableTracker.java (original)
+++ cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/SSTableTracker.java Tue Jun 1 19:26:34 2010
@@ -107,7 +107,7 @@ public class SSTableTracker implements I
{
long keys = estimatedKeys();
- if (!keyCache.isCapacityModified())
+ if (!keyCache.isCapacitySetManually())
{
int keyCacheSize = DatabaseDescriptor.getKeysCachedFor(ksname, cfname, keys);
if (keyCacheSize != keyCache.getCapacity())
@@ -115,18 +115,18 @@ public class SSTableTracker implements I
// update cache size for the new key volume
if (logger.isDebugEnabled())
logger.debug("key cache capacity for " + cfname + " is " + keyCacheSize);
- keyCache.setCapacity(keyCacheSize);
+ keyCache.updateCapacity(keyCacheSize);
}
}
- if (!rowCache.isCapacityModified())
+ if (!rowCache.isCapacitySetManually())
{
int rowCacheSize = DatabaseDescriptor.getRowsCachedFor(ksname, cfname, keys);
if (rowCacheSize != rowCache.getCapacity())
{
if (logger.isDebugEnabled())
logger.debug("row cache capacity for " + cfname + " is " + rowCacheSize);
- rowCache.setCapacity(rowCacheSize);
+ rowCache.updateCapacity(rowCacheSize);
}
}
}
Modified: cassandra/branches/cassandra-0.6/test/conf/storage-conf.xml
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/test/conf/storage-conf.xml?rev=950222&r1=950221&r2=950222&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/test/conf/storage-conf.xml (original)
+++ cassandra/branches/cassandra-0.6/test/conf/storage-conf.xml Tue Jun 1 19:26:34 2010
@@ -41,6 +41,8 @@
<Keyspace Name = "Keyspace1">
<ColumnFamily Name="Standard1" RowsCached="10%" KeysCached="0"/>
<ColumnFamily Name="Standard2"/>
+ <ColumnFamily Name="Standard3" KeysCached="50%"/>
+ <ColumnFamily Name="Standard4" KeysCached="100%"/>
<ColumnFamily CompareWith="LongType" Name="StandardLong1"/>
<ColumnFamily CompareWith="LongType" Name="StandardLong2"/>
<ColumnFamily ColumnType="Super" CompareSubcolumnsWith="LongType" Name="Super1" RowsCached="1000" KeysCached="0"/>
Modified: cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java?rev=950222&r1=950221&r2=950222&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java (original)
+++ cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java Tue Jun 1 19:26:34 2010
@@ -19,13 +19,8 @@
package org.apache.cassandra.db;
import java.io.IOException;
-import java.net.InetAddress;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
import org.junit.Test;
@@ -33,7 +28,6 @@ import org.apache.cassandra.CleanupHelpe
import org.apache.cassandra.db.filter.IdentityQueryFilter;
import org.apache.cassandra.db.filter.QueryPath;
import org.apache.cassandra.io.SSTableReader;
-import org.apache.cassandra.utils.FBUtilities;
import static junit.framework.Assert.assertEquals;
import static org.apache.cassandra.db.TableTest.assertColumns;
@@ -133,4 +127,59 @@ public class CompactionsPurgeTest extend
ColumnFamily cf = table.getColumnFamilyStore(cfName).getColumnFamily(new IdentityQueryFilter(key, new QueryPath(cfName)));
assert cf == null : cf;
}
-}
\ No newline at end of file
+
+ @Test
+ public void testKeyCache50() throws IOException, ExecutionException, InterruptedException
+ {
+ testKeyCache("Standard3", 64);
+ }
+
+ @Test
+ public void testKeyCache100() throws IOException, ExecutionException, InterruptedException
+ {
+ testKeyCache("Standard4", 128);
+ }
+
+ public void testKeyCache(String cfname, int expectedCacheSize) throws IOException, ExecutionException, InterruptedException
+ {
+ CompactionManager.instance.disableAutoCompaction();
+
+ Table table = Table.open(TABLE1);
+ String cfName = cfname;
+ ColumnFamilyStore store = table.getColumnFamilyStore(cfName);
+
+ // KeyCache should start at size 1 if we're caching X% of zero data.
+ int keyCacheSize = store.getKeyCacheSize();
+ assert keyCacheSize == 1 : keyCacheSize;
+
+ String key1 = "key1";
+ String key2 = "key2";
+ RowMutation rm;
+
+ // inserts
+ rm = new RowMutation(TABLE1, key1);
+ rm.add(new QueryPath(cfName, null, "1".getBytes()), new byte[0], 0);
+ rm.apply();
+ rm = new RowMutation(TABLE1, key2);
+ rm.add(new QueryPath(cfName, null, "2".getBytes()), new byte[0], 0);
+ rm.apply();
+
+ // deletes
+ rm = new RowMutation(TABLE1, key1);
+ rm.delete(new QueryPath(cfName, null, "1".getBytes()), 1);
+ rm.apply();
+ rm = new RowMutation(TABLE1, key2);
+ rm.delete(new QueryPath(cfName, null, "2".getBytes()), 1);
+ rm.apply();
+
+ // After a flush, the cache should expand to be X% of indices * INDEX_INTERVAL.
+ store.forceBlockingFlush();
+ keyCacheSize = store.getKeyCacheSize();
+ assert keyCacheSize == expectedCacheSize : keyCacheSize;
+
+ // After a compaction, the cache should expand to be X% of zero data.
+ CompactionManager.instance.submitMajor(store, 0, Integer.MAX_VALUE).get();
+ keyCacheSize = store.getKeyCacheSize();
+ assert keyCacheSize == 1 : keyCacheSize;
+ }
+}