cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xe...@apache.org
Subject [6/6] git commit: Adds posibility to autoconfigure size of the KeyCache patch by Pavel Yaskevich; reviewed by Yuki Morishita for CASSANDRA-4087
Date Tue, 27 Mar 2012 20:13:03 GMT
Adds posibility to autoconfigure size of the KeyCache
patch by Pavel Yaskevich; reviewed by Yuki Morishita for CASSANDRA-4087


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

Branch: refs/heads/cassandra-1.1
Commit: 731af1a4323314dc31020deec9fd04b97a79519c
Parents: e3c4c09
Author: Pavel Yaskevich <xedin@apache.org>
Authored: Tue Mar 27 13:57:07 2012 +0300
Committer: Pavel Yaskevich <xedin@apache.org>
Committed: Tue Mar 27 22:43:00 2012 +0300

----------------------------------------------------------------------
 CHANGES.txt                                        |    2 +
 conf/cassandra.yaml                                |    4 +-
 src/java/org/apache/cassandra/config/Config.java   |    2 +-
 .../cassandra/config/DatabaseDescriptor.java       |   19 ++++++++++++++-
 4 files changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/731af1a4/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index e92ee3f..a1cd359 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,7 @@
 1.1-dev
  * Adds caching and bloomFilterFpChange to CQL options (CASSANDRA-4042)
+ * Adds posibility to autoconfigure size of the KeyCache (CASSANDRA-4087)
+
 
 1.1-beta2
  * rename loaded sstables to avoid conflicts with local snapshots

http://git-wip-us.apache.org/repos/asf/cassandra/blob/731af1a4/conf/cassandra.yaml
----------------------------------------------------------------------
diff --git a/conf/cassandra.yaml b/conf/cassandra.yaml
index fa4ee9f..4010d74 100644
--- a/conf/cassandra.yaml
+++ b/conf/cassandra.yaml
@@ -77,8 +77,8 @@ commitlog_directory: /var/lib/cassandra/commitlog
 #
 # NOTE: if you reduce the size, you may not get you hottest keys loaded on startup.
 #
-# Default value is 2 (call hold > 200000 keys). Set to 0 to disable key cache.
-key_cache_size_in_mb: 2
+# Default value is "auto" (min(5% of Heap (in MB), 100MB)). Set to 0 to disable key cache.
+key_cache_size_in_mb: auto
 
 # Duration in seconds after which Cassandra should
 # safe the keys cache. Caches are saved to saved_caches_directory as

http://git-wip-us.apache.org/repos/asf/cassandra/blob/731af1a4/src/java/org/apache/cassandra/config/Config.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/Config.java b/src/java/org/apache/cassandra/config/Config.java
index d875584..7adce69 100644
--- a/src/java/org/apache/cassandra/config/Config.java
+++ b/src/java/org/apache/cassandra/config/Config.java
@@ -126,7 +126,7 @@ public class Config
     public boolean trickle_fsync = false;
     public int trickle_fsync_interval_in_kb = 10240;
 
-    public int key_cache_size_in_mb = 2;
+    public String key_cache_size_in_mb = "auto";
     public int key_cache_save_period = 14400;
     public int key_cache_keys_to_save = Integer.MAX_VALUE;
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/731af1a4/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
index 439c958..227a6a3 100644
--- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
+++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
@@ -83,6 +83,7 @@ public class DatabaseDescriptor
     private static RequestSchedulerId requestSchedulerId;
     private static RequestSchedulerOptions requestSchedulerOptions;
 
+    private static int keyCacheSizeInMB;
     private static IRowCacheProvider rowCacheProvider;
 
     /**
@@ -414,6 +415,22 @@ public class DatabaseDescriptor
             if (conf.initial_token != null)
                 partitioner.getTokenFactory().validate(conf.initial_token);
 
+            try
+            {
+                // if key_cache_size_in_mb option was set to "auto" then size of the cache
should be "min(5% of Heap (in MB), 100MB)
+                keyCacheSizeInMB = "auto".equalsIgnoreCase(conf.key_cache_size_in_mb)
+                                    ? Math.min((int) (Runtime.getRuntime().totalMemory()
* 0.05 / 1024 / 1024), 100)
+                                    : Integer.valueOf(conf.key_cache_size_in_mb);
+
+                if (keyCacheSizeInMB < 0)
+                    throw new NumberFormatException(); // to escape duplicating error message
+            }
+            catch (NumberFormatException e)
+            {
+                throw new ConfigurationException("key_cache_size_in_mb option was set incorrectly
to '"
+                                                 + conf.key_cache_size_in_mb + "', supported
values are 'auto' and <integer> >= 0.");
+            }
+
             rowCacheProvider = FBUtilities.newCacheProvider(conf.row_cache_provider);
 
             // Hardcoded system tables
@@ -993,7 +1010,7 @@ public class DatabaseDescriptor
 
     public static int getKeyCacheSizeInMB()
     {
-        return conf.key_cache_size_in_mb;
+        return keyCacheSizeInMB;
     }
 
     public static int getKeyCacheSavePeriod()


Mime
View raw message