public StateTxfrInfo(HashVector data, bool transferCompleted, long dataSize, Stream st) { this.data = data; this.transferCompleted = transferCompleted; this.sendDataSize = dataSize; this.stream = st; }
//public ArrayList PayLoad //{ // get { return _payLoad; } //} //public ArrayList PayLoadCompilationInfo //{ // get { return _payLoadCompilationInformation; } //} #region ICompactSerializable Members void Runtime.Serialization.ICompactSerializable.Deserialize(Runtime.Serialization.IO.CompactReader reader) { data = (HashVector)reader.ReadObject(); transferCompleted = reader.ReadBoolean(); //_payLoadCompilationInformation = reader.ReadObject() as ArrayList; this.sendDataSize = reader.ReadInt64(); }
private void IncrementBucketStats(string key, int bucketId, long dataSize) { if (_stats.LocalBuckets != null && _stats.LocalBuckets.Contains(bucketId)) { ((BucketStatistics)_stats.LocalBuckets[bucketId]).Increment(dataSize); } if (_keyList == null) _keyList = new HashVector(); if (_keyList != null) { if (_keyList.Contains(bucketId)) { HashVector keys = (HashVector)_keyList[bucketId]; long oldSize = keys.BucketCount * MemoryUtil.NetHashtableOverHead; keys[key] = null; long newSize = keys.BucketCount * MemoryUtil.NetHashtableOverHead; _keyListSize += newSize - oldSize; } else { HashVector keys = new HashVector(); long oldSize = keys.BucketCount * MemoryUtil.NetHashtableOverHead; keys[key] = null; long newSize = keys.BucketCount * MemoryUtil.NetHashtableOverHead; _keyListSize += newSize - oldSize; _keyList[bucketId] = keys; } } }
/// <summary> /// We log all the operations in a transitory index when we are iterating on /// the main index to determine the expired items. StopLogging should be called /// after selection of item is completd. We apply all the logs from transitory /// index to the main index. A null value in transitory index against a key /// indicates that this item is removed during logging, so we should remove /// it from the main log as well. /// </summary> private void ApplyLoggs() { lock (_status_mutex) { IsInProgress = false; if (_indexCleared) { //_mainIndex.Clear(); _mainIndex = new HashVector(); _indexCleared = false; } IDictionaryEnumerator ide = _transitoryIndex.GetEnumerator(); object key; ExpirationHint expHint; while (ide.MoveNext()) { key = ide.Key; expHint = ide.Value as ExpirationHint; ExpirationHint oldEntry = (ExpirationHint)_mainIndex[key]; if (expHint != null) { _mainIndex[key] = expHint; } else { //it means this item has been removed; _mainIndex.Remove(key); } if (oldEntry != null) _expirationManagerSize -= oldEntry.InMemorySize; } } }
/// <summary> /// Called by the scheduler to remove the items that has expired /// </summary> public bool Expire() { //indicates whether some items expired during this interval or not... bool expired = false; //muds: //if user has updated the file then the new values will be reloaded. _sleepInterval = Convert.ToInt32(ServiceConfiguration.ExpirationBulkRemoveDelay); _removeThreshhold = Convert.ToInt32(ServiceConfiguration.ExpirationBulkRemoveSize); CacheBase cacheInst = _context.CacheImpl; CacheBase cache = _context.CacheInternal; Cache rootCache = _context.CacheRoot; if (cache == null) throw new InvalidOperationException("No cache instance defined"); bool allowExpire = AllowClusteredExpiry; //in case of replication, only the coordinator/sub-coordinator is responsible to expire the items. if (!allowExpire) return false; ClusteredArrayList selectedKeys = new ClusteredArrayList(); int oldItemsCount = 0; HashVector oldeItems = null; try { StartLogging(); DateTime startTime = DateTime.Now; int currentTime = AppUtil.DiffSeconds(startTime); int cleanSize = (int)Math.Ceiling(cache.Count * _cleanRatio); //set the flag that we are going to expire the items. if (_cacheLastAccessLoggingIntervalPassed >= _cacheLastAccessLoggingInterval) { _cacheLastAccessLoggingInterval = CacheLastAccessLoggingInterval; _cacheLastAccessCountEnabled = IsCacheLastAccessCountEnabled; _cacheLastAccessCountLoggingEnabled = IsCacheLastAccessLoggingEnabled; _cacheLastAccessInterval = CacheLastAccessCountInterval; } else _cacheLastAccessLoggingIntervalPassed++; if (_cacheLastAccessCountEnabled && _cacheLastAccessCountLoggingEnabled) { if (_cacheLastAccessLoggingIntervalPassed >= _cacheLastAccessLoggingInterval) { _cacheLastAccessLoggingIntervalPassed = 0; oldeItems = new HashVector(); } } lock (_mainIndex.SyncRoot) { IDictionaryEnumerator em = _mainIndex.GetEnumerator(); if (em != null) { while (em.MoveNext()) { ExpirationHint hint = em.Value as ExpirationHint; if (hint != null && _cacheLastAccessCountEnabled && hint is IdleExpiration) { IdleExpiration slidingExpHint = hint as IdleExpiration; TimeSpan diff = AppUtil.GetDateTime(AppUtil.DiffSeconds(DateTime.Now)) - AppUtil.GetDateTime(slidingExpHint.LastAccessTime); if (diff.TotalMinutes >= _cacheLastAccessInterval) { oldItemsCount++; if (oldeItems != null) { oldeItems.Add(em.Key, null); } } } if (hint == null || hint.SortKey.CompareTo(currentTime) >= 0) continue; if (hint.DetermineExpiration(_context)) { selectedKeys.Add(em.Key); if (cleanSize > 0 && selectedKeys.Count == cleanSize) break; } } } } if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ExpirationManager.Expire()", String.Format("Expiry time for {0}/{1} Items: " + (DateTime.UtcNow - startTime), selectedKeys.Count, /*_expiryIndex.KeyCount*/cache.Count)); } catch (Exception e) { NCacheLog.Error("ExpirationManager.Expire(bool)", "LocalCache(Expire): " + e.ToString()); } finally { _context.PerfStatsColl.IncrementCacheLastAccessCountStats(oldItemsCount); ApplyLoggs(); ClusteredArrayList dependentItems = new ClusteredArrayList(); DateTime startTime = DateTime.Now; HashVector expiredItemTable = new HashVector(); expiredItemTable.Add(ItemRemoveReason.Expired, selectedKeys);//Time based expiration try { IDictionaryEnumerator ide = expiredItemTable.GetEnumerator(); while (ide.MoveNext()) { selectedKeys = ide.Value as ClusteredArrayList; ItemRemoveReason removedReason = (ItemRemoveReason)ide.Key; if (selectedKeys.Count > 0) { //new architectural changes begins from here. ClusteredArrayList keysTobeRemoved = new ClusteredArrayList(); for (int i = 0; i < selectedKeys.Count && !_cacheCleared; i++) { keysTobeRemoved.Add(selectedKeys[i]); if (keysTobeRemoved.Count % _removeThreshhold == 0) { try { if (this.IsDisposed) break; OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); object[][] keysExposed = keysTobeRemoved.ToInternalArray(); foreach (object[] collection in keysExposed) { cache.RemoveSync(collection, removedReason, false, operationContext); } //set the flag that item has expired from cache... expired = true; if (_context.PerfStatsColl != null) _context.PerfStatsColl.IncrementExpiryPerSecStatsBy(keysTobeRemoved.Count); } catch (Exception e) { NCacheLog.Error("ExpiryManager.Expire", "an error occurred while removing expired items. Error " + e.ToString()); } keysTobeRemoved.Clear(); //we stop the activity of the current thread so that normal user operation is not affected. Thread.Sleep(_sleepInterval); } } if (!this.IsDisposed && keysTobeRemoved.Count > 0) { try { OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); object[][] keysExposed = keysTobeRemoved.ToInternalArray(); foreach (object[] keyCollection in keysExposed) { cache.RemoveSync(keyCollection, removedReason, false, operationContext); } //set the flag that item has expired from cache... expired = true; if (_context.PerfStatsColl != null) _context.PerfStatsColl.IncrementExpiryPerSecStatsBy(keysTobeRemoved.Count); } catch (Exception e) { NCacheLog.Error("ExpiryManager.Expire", "an error occurred while removing expired items. Error " + e.ToString()); } } } } } finally { _transitoryIndex.Clear(); lock (this) { _cacheCleared = false; } if (oldeItems != null) { StringBuilder sb = new StringBuilder(); IDictionaryEnumerator ide = oldeItems.GetEnumerator(); int count = 1; while (ide.MoveNext()) { sb.Append(ide.Key + ", "); if (count % 10 == 0) { sb.Append("\r\n"); count = 1; } else count++; } NCacheLog.Info(sb.ToString().Trim()); } } } return expired; }
internal HashVectorEnumerator(HashVector hashtable, int getObjRetType) { this.hashtable = hashtable; bucket = hashtable.bucketCount; version = hashtable.version; current = false; getObjectRetType = getObjRetType; }
/// <summary> /// Copy constructor. /// </summary> /// <param name="stat"></param> protected CacheStatistics(CacheStatistics stat) { lock (stat) { this._className = stat._className; this._perfInst = stat._perfInst; this._upTime = stat._upTime; this._count = stat._count; this._hiCount = stat._hiCount; this._maxCount = stat._maxCount; this._maxSize = stat._maxSize; this._hitCount = stat._hitCount; this._missCount = stat._missCount; this._localBuckets = stat._localBuckets != null ? stat._localBuckets.Clone() as HashVector : null; } }
void IEvictionPolicy.Clear() { lock (_index.SyncRoot) { if (_index != null) for (int i = 0; i < 5; i++) if (_index[i] != null) { _index[i] = new HashVector(); } } }
/// <summary> /// Default constructor. /// </summary> public ClrHeapStorageProvider() { _itemDict = new HashVector(DEFAULT_CAPACITY, 0.7f); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or /// resetting unmanaged resources. /// </summary> public override void Dispose() { _itemDict.Clear(); _itemDict = null; base.Dispose(); }
// Clone returns a virtually identical copy of this hash table. This does // a shallow copy - the Objects in the table aren't cloned, only the references // to those Objects. public virtual Object Clone() { bucket[][] lbuckets = buckets; HashVector ht = new HashVector(count, _keycomparer); ht.version = version; ht.loadFactor = loadFactor; ht.count = 0; int superBucket = lbuckets.Length; while (superBucket > 0) { superBucket--; int bucket = lbuckets[superBucket].Length; while (bucket > 0) { bucket--; Object keyv = lbuckets[superBucket][bucket].key; if ((keyv != null) && (keyv != lbuckets)) { ht[keyv] = lbuckets[superBucket][bucket].val; } } } return ht; }
internal SyncHashVector(HashVector vector) : base(false) { _vector = vector; }
internal VectorValueCollection(HashVector hashVector) { _hashVector = hashVector; }
internal VectorKeyCollection(HashVector hashVector) { _hashVector = hashVector; }
public static HashVector Synchronized(HashVector vector) { return new SyncHashVector(vector); }
public override void UpdateLocalBuckets(ArrayList bucketIds) { IEnumerator ie = bucketIds.GetEnumerator(); while (ie.MoveNext()) { if (LocalBuckets == null) LocalBuckets = new HashVector(); if (!LocalBuckets.Contains(ie.Current)) { LocalBuckets[ie.Current] = new BucketStatistics(); } } }
void IEvictionPolicy.Notify(object key, EvictionHint oldhint, EvictionHint newHint) { //always use the new priority eviction hint. EvictionHint hint = newHint; if (hint != null) { CacheItemPriority hintPriority = ((PriorityEvictionHint)hint).Priority; if (hintPriority == CacheItemPriority.Default) { hintPriority = this._priority;//set the default priority from the config. ((PriorityEvictionHint)hint).Priority = this._priority; } if ((oldhint != null)) { CacheItemPriority oldPriority = ((PriorityEvictionHint)oldhint).Priority; CacheItemPriority newPriority = ((PriorityEvictionHint)newHint).Priority; if (oldPriority != newPriority) { IEvictionPolicy temp = this as IEvictionPolicy; temp.Remove(key, oldhint); } } lock (_index.SyncRoot) { int changedIndex = -1; switch (hintPriority) { case CacheItemPriority.Low: if (_index[0] == null) _index[0] = new HashVector(); _index[0][key] = hint; changedIndex = 0; break; case CacheItemPriority.BelowNormal: if (_index[1] == null) _index[1] = new HashVector(); _index[1][key] = hint; changedIndex = 1; break; case CacheItemPriority.Normal: if (_index[2] == null) _index[2] = new HashVector(); _index[2][key] = hint; changedIndex = 2; break; case CacheItemPriority.AboveNormal: if (_index[3] == null) _index[3] = new HashVector(); _index[3][key] = hint; changedIndex = 3; break; case CacheItemPriority.High: if (_index[4] == null) _index[4] = new HashVector(); _index[4][key] = hint; changedIndex = 4; break; } } } }
/// <summary> /// Overloaded constructor. The passed in parameters specify the values for maxObjects /// and maxSizeMB. /// </summary> /// <param name="maxDataSize">maximum size of data, in bytes, that store can contain.</param> public ClrHeapStorageProvider(long maxDataSize) : base(maxDataSize) { _itemDict = new HashVector(DEFAULT_CAPACITY, 0.7f); }
public virtual void Deserialize(CompactReader reader) { _className = reader.ReadObject() as string; _perfInst = reader.ReadObject() as string; _upTime = new DateTime(reader.ReadInt64()); _count = reader.ReadInt64(); _hiCount = reader.ReadInt64(); _maxSize = reader.ReadInt64(); _maxCount = reader.ReadInt64(); _hitCount = reader.ReadInt64(); _missCount = reader.ReadInt64(); _clientsList = reader.ReadObject() as Hashtable; //muds: _localBuckets = new HashVector(); int count = reader.ReadInt32(); for (int i = 0; i < count; i++) { BucketStatistics tmp = new BucketStatistics(); int bucketId = reader.ReadInt32(); tmp.DeserializeLocal(reader); _localBuckets[bucketId] = tmp; } }
/// <summary> /// Overloaded constructor. Takes the properties as a map. /// </summary> /// <param name="properties">properties collection</param> public ClrHeapStorageProvider(IDictionary properties, bool evictionEnabled, ILogger NCacheLog) : base(properties, evictionEnabled, NCacheLog) { _itemDict = new HashVector(DEFAULT_CAPACITY, 0.7f); }
public StateTxfrInfo(bool transferCompleted) { this.transferCompleted = transferCompleted; data = null; }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or /// resetting unmanaged resources. /// </summary> public virtual void Dispose() { if (_taskExpiry != null) { _taskExpiry.Cancel(); _taskExpiry = null; } lock (_status_mutex) { _mainIndex.Clear(); _mainIndex = null; _transitoryIndex.Clear(); _transitoryIndex = null; _expirationManagerSize = 0; } GC.SuppressFinalize(this); }
/// <summary> /// Clear the expiration index /// </summary> public void Clear() { lock (this) { _cacheCleared = true; } lock (_status_mutex) { if (!IsInProgress) { _mainIndex = new HashVector(); _transitoryIndex = new HashVector(); } else { _transitoryIndex = new HashVector(); _indexCleared = true; } _expirationManagerSize = 0; } }
private void IncrementBucketStats(string key, int bucketId, long dataSize) { if (_stats.LocalBuckets.Contains(bucketId)) { ((BucketStatistics)_stats.LocalBuckets[bucketId]).Increment(dataSize); } if (_keyList == null) _keyList = new HashVector(); if (_keyList.Contains(bucketId)) { HashVector keys = (HashVector)_keyList[bucketId]; keys[key] = null; } else { HashVector keys = new HashVector(); keys[key] = null; _keyList[bucketId] = keys; } }