public static HotConfig FromString(string attributes) { if (attributes == null || attributes == string.Empty) return null; HotConfig config = new HotConfig(); int beginQuoteIndex = 0; int endQuoteIndex = 0; UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string errorLogs = attributes.Substring(beginQuoteIndex, endQuoteIndex - beginQuoteIndex); if (errorLogs != null && errorLogs != string.Empty) config._isErrorLogsEnabled = Convert.ToBoolean(errorLogs); UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string detailedLogs = attributes.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1); if (detailedLogs != null && detailedLogs != string.Empty) config._isDetailedLogsEnabled = Convert.ToBoolean(detailedLogs); UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string size = attributes.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1); if (size != null && size != string.Empty) config._cacheMaxSize = Convert.ToInt64(size); UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string interval = attributes.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1); if (interval != null && interval != string.Empty) config._cleanInterval = Convert.ToInt64(interval); UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string evict = attributes.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1); if (evict != null && evict != string.Empty) config._evictRatio = Convert.ToSingle(evict); return config; }
public static HotConfig FromString(string attributes) { if (attributes == null || attributes == string.Empty) { return(null); } HotConfig config = new HotConfig(); int beginQuoteIndex = 0; int endQuoteIndex = 0; UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string errorLogs = attributes.Substring(beginQuoteIndex, endQuoteIndex - beginQuoteIndex); if (errorLogs != null && errorLogs != string.Empty) { config._isErrorLogsEnabled = Convert.ToBoolean(errorLogs); } UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string detailedLogs = attributes.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1); if (detailedLogs != null && detailedLogs != string.Empty) { config._isDetailedLogsEnabled = Convert.ToBoolean(detailedLogs); } UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string size = attributes.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1); if (size != null && size != string.Empty) { config._cacheMaxSize = Convert.ToInt64(size); } UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string interval = attributes.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1); if (interval != null && interval != string.Empty) { config._cleanInterval = Convert.ToInt64(interval); } UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string evict = attributes.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1); if (evict != null && evict != string.Empty) { config._evictRatio = Convert.ToSingle(evict); } return(config); }
public static HotConfig FromString(string attributes) { if (attributes == null || attributes == string.Empty) { return(null); } HotConfig config = new HotConfig(); int beginQuoteIndex = 0; int endQuoteIndex = 0; UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string errorLogs = attributes.Substring(beginQuoteIndex, endQuoteIndex - beginQuoteIndex); if (errorLogs != null && errorLogs != string.Empty) { config._isErrorLogsEnabled = Convert.ToBoolean(errorLogs); } UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string detailedLogs = attributes.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1); if (detailedLogs != null && detailedLogs != string.Empty) { config._isDetailedLogsEnabled = Convert.ToBoolean(detailedLogs); } UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string compression = attributes.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1); if (compression != null && compression != string.Empty) { config._compressionEnabled = Convert.ToBoolean(compression); } UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string threshold = attributes.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1); if (threshold != null && threshold != string.Empty) { long kbs = Convert.ToInt64(threshold); // convert to bytes config._compressionThreshold = kbs * 1024; } UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string size = attributes.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1); if (size != null && size != string.Empty) { config._cacheMaxSize = Convert.ToInt64(size); } UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string interval = attributes.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1); if (interval != null && interval != string.Empty) { config._cleanInterval = Convert.ToInt64(interval); } UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string evict = attributes.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1); if (evict != null && evict != string.Empty) { config._evictRatio = Convert.ToSingle(evict); } UpdateDelimIndexes(ref attributes, '"', ref beginQuoteIndex, ref endQuoteIndex); string isTargetCache = attributes.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1); if (isTargetCache != null && isTargetCache != string.Empty) { config._isTargetCache = Convert.ToBoolean(isTargetCache); } return(config); }
public Exception CanApplyHotConfig(string cacheId, CacheServerConfig config) { CacheInfo cacheInfo = null; cacheId = cacheId.ToLower(); Hashtable result = new Hashtable(); Alachisoft.NCache.Caching.Util.HotConfig hotConfig = new Alachisoft.NCache.Caching.Util.HotConfig(); hotConfig.IsErrorLogsEnabled = config.Log.TraceErrors; hotConfig.IsDetailedLogsEnabled = config.Log.TraceNotices; hotConfig.CacheMaxSize = config.Storage.Size * 1024 * 1024; //from MBs to bytes hotConfig.CleanInterval = config.Cleanup.Interval; hotConfig.EvictRatio = (float)config.EvictionPolicy.EvictionRatio; if (s_caches.Contains(cacheId)) { cacheInfo = (CacheInfo)s_caches[cacheId]; return cacheInfo.Cache.CanApplyHotConfig(hotConfig); } return null; }
public bool RegisterCache(string cacheId, CacheServerConfig config, string partId, bool overwrite, bool hotApply, bool isLocalNode) { if (cacheId == null) throw new ArgumentNullException("cacheId"); //We load configuration before applying the new changes to preserve some old values in the config. cacheId = cacheId.ToLower(); CacheInfo cacheInfo = null; _rwLock.AcquireWriterLock(Timeout.Infinite); try { if (s_partitionedCaches.Contains(cacheId.ToLower())) throw new Runtime.Exceptions.ManagementException("A cache with same cacheId already exists"); if (s_caches.Contains(cacheId.ToLower())) { if (!overwrite) { return false; } cacheInfo = (CacheInfo)s_caches[cacheId.ToLower()]; //(WARNING) This code is here to save the old value of connection-retries //in the cluster configuration to avoid override by NCManager. //This code should be removed after these options appears on UI. //props = GetChangedConfigForTemp(cacheId.ToLower(), cacheInfo.CacheProps, props); } else { ///This is until we change the use of properties in Cache ///from props stirng or hashtable to Dom /// string props = GetProps(config); ClientConfigManager.LocalCacheId = this.LocalCacheIP; ClientConfigManager.AddCache(cacheId, config); cacheInfo = new CacheInfo(); cacheInfo.Cache = new LeasedCache(props); s_caches[cacheId.ToLower()] = cacheInfo; } cacheInfo.CacheProps = config; if (hotApply && cacheInfo != null && cacheInfo.Cache != null && cacheInfo.Cache.IsRunning) { CacheConfig cc = CacheConfig.FromConfiguration(config); Alachisoft.NCache.Caching.Util.HotConfig hotConfig = new Alachisoft.NCache.Caching.Util.HotConfig(); hotConfig.IsErrorLogsEnabled = cc.IsErrorLogsEnabled; hotConfig.IsDetailedLogsEnabled = cc.IsDetailedLogsEnabled; hotConfig.CacheMaxSize = cc.CacheMaxSize; hotConfig.CleanInterval = cc.CleanInterval; hotConfig.EvictRatio = cc.EvictRatio; cacheInfo.Cache.ApplyHotConfiguration(hotConfig); } SaveConfiguration(); } catch (Exception) { throw; } finally { _rwLock.ReleaseWriterLock(); } return true; }
internal ConfigModifiedEvent(HotConfig config, string cacheId, string clientid) { _config = config; _cacheId = cacheId; _clientid = clientid; }
/// <summary> /// This function is called by ConfigurationModified callback /// </summary> /// <param name="hotConfig"></param> private void OnConfigModified(HotConfig hotConfig) { lock (ConnectionManager.CallbackQueue) { if (_client != null) { ConnectionManager.CallbackQueue.Enqueue(new ConfigModifiedEvent(hotConfig, _cacheId, _client.ClientID)); Monitor.Pulse(ConnectionManager.CallbackQueue); } } }
public void ApplyHotConfiguration(HotConfig hotConfig) { if (hotConfig != null) { #region Error Logging Config if (hotConfig.IsErrorLogsEnabled && _cacheInfo != null) { if (!_context.NCacheLog.IsErrorEnabled) { string cache_name = _cacheInfo.Name; if (_cacheInfo.CurrentPartitionId != null && _cacheInfo.CurrentPartitionId != string.Empty) cache_name += "-" + _cacheInfo.CurrentPartitionId; _context.NCacheLog.SetLevel("error"); } if (hotConfig.IsDetailedLogsEnabled) _context.NCacheLog.SetLevel("all"); } else if (!hotConfig.IsErrorLogsEnabled) { _context.NCacheLog.SetLevel("off"); } #endregion this._context.CacheImpl.InternalCache.MaxSize = this._context.CacheImpl.ActualStats.MaxSize = hotConfig.CacheMaxSize; this._context.ExpiryMgr.CleanInterval = hotConfig.CleanInterval; this._context.CacheImpl.InternalCache.EvictRatio = hotConfig.EvictRatio / 100; if (this._configurationModified != null) this._configurationModified(hotConfig); } }
/// <summary> /// Apply runtime configuration settings. /// </summary> /// <param name="cacheConfig"></param> public Exception CanApplyHotConfig(HotConfig hotConfig) { if (this._context.CacheImpl != null && !this._context.CacheImpl.CanChangeCacheSize(hotConfig.CacheMaxSize)) return new Exception("You need to remove some data from cache before applying the new size"); return null; }