Updated Branches: refs/heads/trunk 8bd1c1f86 -> 3925aba84
Make jmx setters consistent with yaml config. Patch by Chris Merrill, reviewed by brandonwilliams for CASSANDRA-4479 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/3925aba8 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/3925aba8 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/3925aba8 Branch: refs/heads/trunk Commit: 3925aba84260063618bf85db6d51b409116f4050 Parents: 8bd1c1f Author: Brandon Williams <brandonwilli...@apache.org> Authored: Thu Aug 23 10:58:54 2012 -0500 Committer: Brandon Williams <brandonwilli...@apache.org> Committed: Thu Aug 23 10:58:54 2012 -0500 ---------------------------------------------------------------------- src/java/org/apache/cassandra/config/Config.java | 24 ++++++++------ .../cassandra/config/DatabaseDescriptor.java | 25 ++++++++++++++ .../org/apache/cassandra/gms/FailureDetector.java | 10 ++--- .../org/apache/cassandra/service/CacheService.java | 26 ++++++--------- .../org/apache/cassandra/service/StorageProxy.java | 14 +++---- 5 files changed, 59 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/3925aba8/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 8da9777..8488d08 100644 --- a/src/java/org/apache/cassandra/config/Config.java +++ b/src/java/org/apache/cassandra/config/Config.java @@ -19,7 +19,11 @@ package org.apache.cassandra.config; import org.apache.cassandra.cache.ConcurrentLinkedHashCacheProvider; - +/** + * A class that contains configuration properties for the cassandra node it runs within. + * + * Properties declared as volatile can be mutated via JMX. + */ public class Config { public String cluster_name = "Test Cluster"; @@ -30,8 +34,8 @@ public class Config public String partitioner; public Boolean auto_bootstrap = true; - public Boolean hinted_handoff_enabled = true; - public Integer max_hint_window_in_ms = Integer.MAX_VALUE; + public volatile Boolean hinted_handoff_enabled = true; + public volatile Integer max_hint_window_in_ms = Integer.MAX_VALUE; public SeedProviderDef seed_provider; public DiskAccessMode disk_access_mode = DiskAccessMode.auto; @@ -40,7 +44,7 @@ public class Config public String initial_token; public Integer num_tokens = 1; - public Long rpc_timeout_in_ms = new Long(10000); + public volatile Long rpc_timeout_in_ms = new Long(10000); public Long read_rpc_timeout_in_ms = new Long(10000); @@ -52,7 +56,7 @@ public class Config public Integer streaming_socket_timeout_in_ms = new Integer(0); - public Double phi_convict_threshold = 8.0; + public volatile Double phi_convict_threshold = 8.0; public Integer concurrent_reads = 8; public Integer concurrent_writes = 32; @@ -90,12 +94,12 @@ public class Config public Integer column_index_size_in_kb = 64; public Integer in_memory_compaction_limit_in_mb = 256; public Integer concurrent_compactors = Runtime.getRuntime().availableProcessors(); - public Integer compaction_throughput_mb_per_sec = 16; + public volatile Integer compaction_throughput_mb_per_sec = 16; public Boolean multithreaded_compaction = false; public Integer max_streaming_retries = 3; - public Integer stream_throughput_outbound_megabits_per_sec; + public volatile Integer stream_throughput_outbound_megabits_per_sec; public String[] data_file_directories; @@ -132,17 +136,17 @@ public class Config public int max_hints_delivery_threads = 1; public boolean compaction_preheat_key_cache = true; - public boolean incremental_backups = false; + public volatile boolean incremental_backups = false; public int memtable_flush_queue_size = 4; public boolean trickle_fsync = false; public int trickle_fsync_interval_in_kb = 10240; public Long key_cache_size_in_mb = null; - public int key_cache_save_period = 14400; + public volatile int key_cache_save_period = 14400; public int key_cache_keys_to_save = Integer.MAX_VALUE; public long row_cache_size_in_mb = 0; - public int row_cache_save_period = 0; + public volatile int row_cache_save_period = 0; public int row_cache_keys_to_save = Integer.MAX_VALUE; public String row_cache_provider = ConcurrentLinkedHashCacheProvider.class.getSimpleName(); public boolean populate_io_cache_on_flush = false; http://git-wip-us.apache.org/repos/asf/cassandra/blob/3925aba8/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 796ba64..dce43c9 100644 --- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java +++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java @@ -804,6 +804,11 @@ public class DatabaseDescriptor return conf.phi_convict_threshold; } + public static void setPhiConvictThreshold(double phiConvictThreshold) + { + conf.phi_convict_threshold = phiConvictThreshold; + } + public static int getConcurrentReaders() { return conf.concurrent_reads; @@ -1005,11 +1010,21 @@ public class DatabaseDescriptor return conf.auto_bootstrap; } + public static void setHintedHandoffEnabled(boolean hintedHandoffEnabled) + { + conf.hinted_handoff_enabled = hintedHandoffEnabled; + } + public static boolean hintedHandoffEnabled() { return conf.hinted_handoff_enabled; } + public static void setMaxHintWindow(int ms) + { + conf.max_hint_window_in_ms = ms; + } + public static int getMaxHintWindow() { return conf.max_hint_window_in_ms; @@ -1149,6 +1164,11 @@ public class DatabaseDescriptor return conf.key_cache_save_period; } + public static void setKeyCacheSavePeriod(int keyCacheSavePeriod) + { + conf.key_cache_save_period = keyCacheSavePeriod; + } + public static int getKeyCacheKeysToSave() { return conf.key_cache_keys_to_save; @@ -1164,6 +1184,11 @@ public class DatabaseDescriptor return conf.row_cache_save_period; } + public static void setRowCacheSavePeriod(int rowCacheSavePeriod) + { + conf.row_cache_save_period = rowCacheSavePeriod; + } + public static int getRowCacheKeysToSave() { return conf.row_cache_keys_to_save; http://git-wip-us.apache.org/repos/asf/cassandra/blob/3925aba8/src/java/org/apache/cassandra/gms/FailureDetector.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/gms/FailureDetector.java b/src/java/org/apache/cassandra/gms/FailureDetector.java index 952328b..c58a559 100644 --- a/src/java/org/apache/cassandra/gms/FailureDetector.java +++ b/src/java/org/apache/cassandra/gms/FailureDetector.java @@ -48,14 +48,12 @@ public class FailureDetector implements IFailureDetector, FailureDetectorMBean public static final IFailureDetector instance = new FailureDetector(); private static final Logger logger = LoggerFactory.getLogger(FailureDetector.class); - private static double phiConvictThreshold; private final Map<InetAddress, ArrivalWindow> arrivalSamples = new Hashtable<InetAddress, ArrivalWindow>(); private final List<IFailureDetectionEventListener> fdEvntListeners = new CopyOnWriteArrayList<IFailureDetectionEventListener>(); public FailureDetector() { - phiConvictThreshold = DatabaseDescriptor.getPhiConvictThreshold(); // Register this instance with JMX try { @@ -131,12 +129,12 @@ public class FailureDetector implements IFailureDetector, FailureDetectorMBean public void setPhiConvictThreshold(double phi) { - phiConvictThreshold = phi; + DatabaseDescriptor.setPhiConvictThreshold(phi); } public double getPhiConvictThreshold() { - return phiConvictThreshold; + return DatabaseDescriptor.getPhiConvictThreshold(); } public boolean isAlive(InetAddress ep) @@ -186,7 +184,7 @@ public class FailureDetector implements IFailureDetector, FailureDetectorMBean if (logger.isTraceEnabled()) logger.trace("PHI for " + ep + " : " + phi); - if ( phi > phiConvictThreshold ) + if (phi > getPhiConvictThreshold()) { logger.trace("notifying listeners that {} is down", ep); logger.trace("intervals: {} mean: {}", hbWnd, hbWnd.mean()); @@ -202,7 +200,7 @@ public class FailureDetector implements IFailureDetector, FailureDetectorMBean logger.debug("Forcing conviction of {}", ep); for (IFailureDetectionEventListener listener : fdEvntListeners) { - listener.convict(ep, phiConvictThreshold); + listener.convict(ep, getPhiConvictThreshold()); } } http://git-wip-us.apache.org/repos/asf/cassandra/blob/3925aba8/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 58600ef..8446b8d 100644 --- a/src/java/org/apache/cassandra/service/CacheService.java +++ b/src/java/org/apache/cassandra/service/CacheService.java @@ -83,9 +83,6 @@ public class CacheService implements CacheServiceMBean public final AutoSavingCache<KeyCacheKey, RowIndexEntry> keyCache; public final AutoSavingCache<RowCacheKey, IRowCacheEntry> rowCache; - private int rowCacheSavePeriod; - private int keyCacheSavePeriod; - private CacheService() { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); @@ -99,9 +96,6 @@ public class CacheService implements CacheServiceMBean throw new RuntimeException(e); } - rowCacheSavePeriod = DatabaseDescriptor.getRowCacheSavePeriod(); - keyCacheSavePeriod = DatabaseDescriptor.getKeyCacheSavePeriod(); - keyCache = initKeyCache(); rowCache = initRowCache(); } @@ -142,10 +136,10 @@ public class CacheService implements CacheServiceMBean int keyCacheKeysToSave = DatabaseDescriptor.getKeyCacheKeysToSave(); logger.info("Scheduling key cache save to each {} seconds (going to save {} keys).", - keyCacheSavePeriod, + DatabaseDescriptor.getKeyCacheSavePeriod(), keyCacheKeysToSave == Integer.MAX_VALUE ? "all" : keyCacheKeysToSave); - keyCache.scheduleSaving(keyCacheSavePeriod, keyCacheKeysToSave); + keyCache.scheduleSaving(DatabaseDescriptor.getKeyCacheSavePeriod(), keyCacheKeysToSave); return keyCache; } @@ -168,10 +162,10 @@ public class CacheService implements CacheServiceMBean int rowCacheKeysToSave = DatabaseDescriptor.getRowCacheKeysToSave(); logger.info("Scheduling row cache save to each {} seconds (going to save {} keys).", - rowCacheSavePeriod, + DatabaseDescriptor.getRowCacheSavePeriod(), rowCacheKeysToSave == Integer.MAX_VALUE ? "all" : rowCacheKeysToSave); - rowCache.scheduleSaving(rowCacheSavePeriod, rowCacheKeysToSave); + rowCache.scheduleSaving(DatabaseDescriptor.getRowCacheSavePeriod(), rowCacheKeysToSave); return rowCache; } @@ -208,7 +202,7 @@ public class CacheService implements CacheServiceMBean public int getRowCacheSavePeriodInSeconds() { - return rowCacheSavePeriod; + return DatabaseDescriptor.getRowCacheSavePeriod(); } public void setRowCacheSavePeriodInSeconds(int rcspis) @@ -216,13 +210,13 @@ public class CacheService implements CacheServiceMBean if (rcspis < 0) throw new RuntimeException("RowCacheSavePeriodInSeconds must be non-negative."); - rowCacheSavePeriod = rcspis; - rowCache.scheduleSaving(rowCacheSavePeriod, DatabaseDescriptor.getRowCacheKeysToSave()); + DatabaseDescriptor.setRowCacheSavePeriod(rcspis); + rowCache.scheduleSaving(rcspis, DatabaseDescriptor.getRowCacheKeysToSave()); } public int getKeyCacheSavePeriodInSeconds() { - return keyCacheSavePeriod; + return DatabaseDescriptor.getKeyCacheSavePeriod(); } public void setKeyCacheSavePeriodInSeconds(int kcspis) @@ -230,8 +224,8 @@ public class CacheService implements CacheServiceMBean if (kcspis < 0) throw new RuntimeException("KeyCacheSavePeriodInSeconds must be non-negative."); - keyCacheSavePeriod = kcspis; - keyCache.scheduleSaving(keyCacheSavePeriod, DatabaseDescriptor.getKeyCacheKeysToSave()); + DatabaseDescriptor.setKeyCacheSavePeriod(kcspis); + keyCache.scheduleSaving(kcspis, DatabaseDescriptor.getKeyCacheKeysToSave()); } public void invalidateKeyCache() http://git-wip-us.apache.org/repos/asf/cassandra/blob/3925aba8/src/java/org/apache/cassandra/service/StorageProxy.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/service/StorageProxy.java b/src/java/org/apache/cassandra/service/StorageProxy.java index 1fb84cd..f308405 100644 --- a/src/java/org/apache/cassandra/service/StorageProxy.java +++ b/src/java/org/apache/cassandra/service/StorageProxy.java @@ -78,8 +78,6 @@ public class StorageProxy implements StorageProxyMBean public static final StorageProxy instance = new StorageProxy(); - private static volatile boolean hintedHandoffEnabled = DatabaseDescriptor.hintedHandoffEnabled(); - private static volatile int maxHintWindow = DatabaseDescriptor.getMaxHintWindow(); private static volatile int maxHintsInProgress = 1024 * Runtime.getRuntime().availableProcessors(); private static final AtomicInteger totalHintsInProgress = new AtomicInteger(); private static final Map<InetAddress, AtomicInteger> hintsInProgress = new MapMaker().concurrencyLevel(1).makeComputingMap(new Function<InetAddress, AtomicInteger>() @@ -1161,30 +1159,30 @@ public class StorageProxy implements StorageProxyMBean public boolean getHintedHandoffEnabled() { - return hintedHandoffEnabled; + return DatabaseDescriptor.hintedHandoffEnabled(); } public void setHintedHandoffEnabled(boolean b) { - hintedHandoffEnabled = b; + DatabaseDescriptor.setHintedHandoffEnabled(b); } public int getMaxHintWindow() { - return maxHintWindow; + return DatabaseDescriptor.getMaxHintWindow(); } public void setMaxHintWindow(int ms) { - maxHintWindow = ms; + DatabaseDescriptor.setMaxHintWindow(ms); } public static boolean shouldHint(InetAddress ep) { - if (!hintedHandoffEnabled) + if (!DatabaseDescriptor.hintedHandoffEnabled()) return false; - boolean hintWindowExpired = Gossiper.instance.getEndpointDowntime(ep) > maxHintWindow; + boolean hintWindowExpired = Gossiper.instance.getEndpointDowntime(ep) > DatabaseDescriptor.getMaxHintWindow(); if (hintWindowExpired) logger.debug("not hinting {} which has been down {}ms", ep, Gossiper.instance.getEndpointDowntime(ep)); return !hintWindowExpired;