From 27101e9626b4a97d4e34ba5ecf3abc52309f1e19 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Mon, 18 Jan 2010 15:51:26 +0000 Subject: [PATCH] change RowsCachedFraction option to RowsCached, specified either as an absolute number or as a percentage of rows in the CF patch by jbellis; reviewed by goffinet for CASSANDRA-688 git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@900435 13f79535-47bb-0310-9956-ffa450edef68 --- conf/storage-conf.xml | 11 +++++++---- .../cassandra/config/DatabaseDescriptor.java | 15 +++++++++++---- .../apache/cassandra/db/ColumnFamilyStore.java | 6 +++++- test/conf/storage-conf.xml | 4 ++-- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/conf/storage-conf.xml b/conf/storage-conf.xml index 303c0c9d8e..bca2fab1a5 100644 --- a/conf/storage-conf.xml +++ b/conf/storage-conf.xml @@ -91,15 +91,16 @@ ~ index. Consider increasing this if you have fewer, wider rows. ~ Set to 0 to disable entirely. ~ - ~ The optional RowsCachedFraction attribute specifies - ~ The fraction of rows per sstable whose entire contents we cache in - ~ memory. Do not use this on ColumnFamilies with large rows, or + ~ The optional RowsCached attribute specifies the number of rows + ~ whose entire contents we cache in memory, either as a fixed number + ~ of rows or as a percent of rows in the ColumnFamily. + ~ Do not use this on ColumnFamilies with large rows, or ~ ColumnFamilies with high write:read ratios. As with key caching, ~ valid values are from 0 to 1. The default 0 disables it entirely. --> @@ -107,6 +108,8 @@ CompareWith="UTF8Type" CompareSubcolumnsWith="UTF8Type" Name="Super1" + RowsCached="1000" + KeysCachedFraction="0" Comment="A column family with supercolumns, whose column and subcolumn names are UTF8 strings"/> diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java index 426544b4c5..0ac09ebcb2 100644 --- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java +++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java @@ -87,7 +87,7 @@ public class DatabaseDescriptor private static int bmtThreshold_ = 256; private static Map, Double> tableKeysCachedFractions_ = new HashMap, Double>(); - private static Map, Double> tableRowsCachedFractions_ = new HashMap, Double>(); + private static Map, Double> tableRowCacheSizes = new HashMap, Double>(); /* * A map from table names to the set of column families for the table and the @@ -523,9 +523,16 @@ public class DatabaseDescriptor tableKeysCachedFractions_.put(Pair.create(tName, cfName), Double.valueOf(value)); } - if ((value = XMLUtils.getAttributeValue(columnFamily, "RowsCachedFraction")) != null) + if ((value = XMLUtils.getAttributeValue(columnFamily, "RowsCached")) != null) { - tableRowsCachedFractions_.put(Pair.create(tName, cfName), Double.valueOf(value)); + if (value.endsWith("%")) + { + tableRowCacheSizes.put(Pair.create(tName, cfName), Double.valueOf(value.substring(0, value.length() - 1)) / 100); + } + else + { + tableRowCacheSizes.put(Pair.create(tName, cfName), Double.valueOf(value)); + } } // Parse out user-specified logical names for the various dimensions @@ -964,7 +971,7 @@ public class DatabaseDescriptor public static double getRowsCachedFraction(String tableName, String columnFamilyName) { - Double v = tableRowsCachedFractions_.get(Pair.create(tableName, columnFamilyName)); + Double v = tableRowCacheSizes.get(Pair.create(tableName, columnFamilyName)); return v == null ? 0 : v; } diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java index b3d339ce28..7429712606 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -191,7 +191,11 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean double v = DatabaseDescriptor.getRowsCachedFraction(table, columnFamilyName); if (v > 0) { - int cacheSize = Math.max(1, (int)(v * SSTableReader.estimatedKeys(columnFamilyName))); + int cacheSize; + if (v < 1) + cacheSize = Math.max(1, (int)(v * SSTableReader.estimatedKeys(columnFamilyName))); + else + cacheSize = (int)v; if (logger_.isDebugEnabled()) logger_.debug("enabling row cache for " + columnFamilyName + " with size " + cacheSize); rowCache = new JMXInstrumentedCache(table, columnFamilyName + "RowCache", cacheSize); diff --git a/test/conf/storage-conf.xml b/test/conf/storage-conf.xml index f03bc6c658..0d975b23bc 100644 --- a/test/conf/storage-conf.xml +++ b/test/conf/storage-conf.xml @@ -44,11 +44,11 @@ 0.00002 - + - +