Ejemplo n.º 1
0
        public void RemoveCacheKey(string cacheKey)
        {
            if (_cacheKeys.ContainsKey(cacheKey))
            {
                int preUpdateBuckets = _cacheKeys.BucketCount;
                _cacheKeys.Remove(cacheKey);

                int postUpdateBuckets = _cacheKeys.BucketCount;
                if (postUpdateBuckets != preUpdateBuckets)
                {
                    _size -= (preUpdateBuckets - postUpdateBuckets) * MemoryUtil.NetHashtableOverHead;
                }
            }
        }
Ejemplo n.º 2
0
        private void UnregisterDataFilter(string serverUID, string clientID, string clientUID, HashVector CID, HashVector CUID)
        {
            //updating clientUIDs
            HashVector clientUIDs = null;

            if (CUID.ContainsKey(clientID))
            {
                clientUIDs = CUID[clientID] as HashVector;
                clientUIDs.Remove(clientUID);
                if (clientUIDs.Count == 0)
                {
                    CUID[clientID] = null;
                    clientUIDs     = CUID[clientID] as HashVector;
                    CUID.Remove(clientID);
                }
            }

            //updating Max values
            HashVector clientDF = null;

            if (CID.ContainsKey(serverUID))
            {
                clientDF = CID[serverUID] as HashVector;
                EventDataFilter max = EventDataFilter.None;
                if (clientUIDs != null)
                {
                    IDictionaryEnumerator ide = clientUIDs.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        if (((EventDataFilter)ide.Value) > max)
                        {
                            max = (EventDataFilter)ide.Value;
                        }
                    }
                    if (!clientDF.ContainsKey(clientID) || ((EventDataFilter)clientDF[clientID]) < max)
                    {
                        clientDF[clientID] = max;
                    }
                }
                else
                {
                    ((IDictionary)CID[serverUID]).Remove(clientID);
                    if (((IDictionary)CID[serverUID]).Count == 0)
                    {
                        CID.Remove(serverUID);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        //assumption contains checks are outside this function
        private void DecrementOrRemove(ref HashVector <string, KeyInfo> keyVector, string key)
        {
            lock (keyVector)
            {
                if (keyVector.ContainsKey(key))
                {
                    KeyInfo kInfo = keyVector[key];

                    if (kInfo.DecrementRefCount() <= 0)
                    {
                        keyVector.Remove(key);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Provides implementation of Remove method of the ICacheStorage interface.
        /// Removes an object from the store, specified by the passed in key
        /// </summary>
        /// <param name="key">key</param>
        /// <returns>object</returns>
        public override object Remove(object key)
        {
            IStorageEntry e = (IStorageEntry)Get(key);

            if (e != null)
            {
                lock (_itemDict.SyncRoot)
                {
                    _itemDict.Remove(key);
                    base.Removed(e, Common.MemoryUtil.GetStringSize(key), e.Type);
                    e?.MarkInUse(NCModulesConstants.Global);
                    e?.MarkFree(NCModulesConstants.CacheStore);
                }
            }
            return(e);
        }
Ejemplo n.º 5
0
 public override void RemoveBucket(int bucket)
 {
     if (Context.NCacheLog.IsInfoEnabled)
     {
         Context.NCacheLog.Info("HashedCache.RemoveBucket", "removing bucket :" + bucket);
     }
     //Remove from stats
     if (LocalBuckets != null)
     {
         LocalBuckets.Remove(bucket);
     }
     //Remove actual data of the bucket
     RemoveBucketData(bucket);
     //remove operation logger for the bucket from log table if any exists.
     RemoveFromLogTbl(bucket);
 }
Ejemplo n.º 6
0
        public bool Remove(string messageId)
        {
            if (_messageIds.ContainsKey(messageId))
            {
                int preUpdateBuckets = _messageIds.BucketCount;
                _messageIds.Remove(messageId);

                int postUpdateBuckets = _messageIds.BucketCount;
                if (postUpdateBuckets != preUpdateBuckets)
                {
                    _size -= (preUpdateBuckets - postUpdateBuckets) * MemoryUtil.NetHashtableOverHead;
                }
                return(_messageIds.Count == 0);
            }

            return(false);
        }
Ejemplo n.º 7
0
        internal IOptimizedQueueOperation Dequeue()
        {
            IOptimizedQueueOperation operation = null;

            try
            {
                lock (_sync_mutex)
                {
                    int index = 0;
                    do                                        //fetch the next valid operation from the queue
                    {
                        if (_head < _tail || _tailMaxReached) //or contition checks if the _tail has reached max long value and _head has not yet reached there , so in this case _head<_tail will fail bcz _tail has been reinitialized
                        {
                            if (_head == int.MaxValue)        //checks if _head has reached the max long value, so reinitialize _head and make _tailMaxReached is set to false as _head<_tail is now again valid
                            {
                                _head           = -1;
                                _tailMaxReached = false;
                            }

                            index     = ++_head;
                            operation = _queue[index] as IOptimizedQueueOperation;    //get key on which the operation is to be performed from the head of the queue

                            if (operation != null)
                            {
                                string cacheKey = _indexToKeyMap[index] as string;
                                _keyToIndexMap.Remove(cacheKey);    //update map
                                _indexToKeyMap.Remove(index);
                                _queue.Remove(index);               //update queue
                                _size -= operation.Size;
                                _count--;
                            }
                        }
                        else
                        {
                            break;
                        }
                    } while (operation == null);
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }
            return(operation);
        }
Ejemplo n.º 8
0
        public bool UnRegister(string serverUniqueId, string clientUniqueId, string clientId)
        {
            lock (this)
            {
                if (clientRefs.ContainsKey(serverUniqueId))
                {
                    HashVector cRefs = (HashVector)clientRefs[serverUniqueId];
                    if (cRefs.ContainsKey(clientId))
                    {
                        ClusteredList <string> refs = (ClusteredList <string>)cRefs[clientId];
                        if (refs.Count > 0)
                        {
                            refs.Remove(clientUniqueId);

                            UnRegisterNotifications(serverUniqueId, clientUniqueId, clientId, addNotifications, maxAddDFAgainstCID, addDFAgainstCUniqueID);
                            UnRegisterNotifications(serverUniqueId, clientUniqueId, clientId, updateNotifications, maxUpdateDFAgainstCID, updateDFAgainstCUniqueID);
                            UnRegisterNotifications(serverUniqueId, clientUniqueId, clientId, removeNotifications, maxRemoveDFAgainstCID, removeDFAgainstCUniqueID);

                            if (refs.Count == 0)
                            {
                                cRefs.Remove(clientId);
                            }
                        }
                        if (cRefs.Count == 0)
                        {
                            int qIndex = -1;
                            foreach (ContinuousQuery query in registeredQueries)
                            {
                                if (query.UniqueId.Equals(serverUniqueId))
                                {
                                    qIndex = registeredQueries.IndexOf(query);
                                    break;
                                }
                            }
                            if (qIndex != -1)
                            {
                                registeredQueries.RemoveAt(qIndex);
                            }
                            return(true);
                        }
                    }
                }
                return(false);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Provides implementation of Remove method of the ICacheStorage interface.
        /// Removes an object from the store, specified by the passed in key
        /// </summary>
        /// <param name="key">key</param>
        /// <returns>object</returns>
        public override object Remove(object key)
        {
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("Store.Remove", "");
            }

            object e = Get(key);

            if (e != null)
            {
                lock (_itemDict.SyncRoot)
                {
                    _itemDict.Remove(key);
                    base.Removed(e as ISizable, Common.MemoryUtil.GetStringSize(key));
                }
            }
            return(e);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Remove a specific key from a group or a sub group
        /// </summary>
        /// <param name="key"></param>
        /// <param name="group"></param>
        /// <param name="subGroup"></param>
        public void RemoveFromGroup(object key, GroupInfo grpInfo)
        {
            if (grpInfo == null)
            {
                return;
            }
            string group    = grpInfo.Group;
            string subGroup = grpInfo.SubGroup;

            if (group == null)
            {
                return;
            }

            group    = DoTrimming(group);
            subGroup = DoTrimming(subGroup);

            lock (_groups.SyncRoot)
            {
                if (_groups.Contains(group))
                {
                    GroupInfoEntry entry = (GroupInfoEntry)_groups[group];

                    long prevSize = entry.IndexInMemorySize;

                    entry.RemoveFromGroup(key, subGroup);

                    long currentSize = entry.IndexInMemorySize;

                    if (entry.SubGroupsCount == 0)
                    {
                        _groups.Remove(group);
                        ModifyGroupIndexSize(-prevSize); //in case the group is being removed we will removed the whole size of the group from our groupindex size
                    }
                    else
                    {
                        ModifyGroupIndexSize(currentSize - prevSize);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        private void DecrementBucketStats(string key, int bucketId, long dataSize)
        {
            if (_stats.LocalBuckets.Contains(bucketId))
            {
                ((BucketStatistics)_stats.LocalBuckets[bucketId]).Decrement(dataSize);
            }

            if (_keyList != null)
            {
                if (_keyList.Contains(bucketId))
                {
                    HashVector keys = (HashVector)_keyList[bucketId];
                    keys.Remove(key);

                    if (keys.Count == 0)
                    {
                        _keyList.Remove(bucketId);
                    }
                }
            }
        }
Ejemplo n.º 12
0
        private void UnRegisterNotifications(string serverUniqueId, string clientUniqueId, string clientId, HashVector notifications
                                             , HashVector CID, HashVector CUID)
        {
            if (notifications.ContainsKey(serverUniqueId))
            {
                HashVector clients = notifications[serverUniqueId] as HashVector;
                if (clients.ContainsKey(clientId))
                {
                    ClusteredList <string> clientQueries = clients[clientId] as ClusteredList <string>;
                    if (clientQueries.Contains(clientUniqueId))
                    {
                        clientQueries.Remove(clientUniqueId);

                        if (clientQueries.Count == 0)
                        {
                            clients.Remove(clientId);
                        }
                    }
                }
            }


            UnregisterDataFilter(serverUniqueId, clientId, clientUniqueId, CID, CUID);
        }
Ejemplo n.º 13
0
        internal void Remove(long key, object value)
        {
            EvictionIndexEntry previousEntry = null;
            EvictionIndexEntry nextEntry     = null;

            int addSize = 0, removeSize = 0;

            if (_index.Contains(key))
            {
                EvictionIndexEntry indexEntry = (EvictionIndexEntry)_index[key];
                bool decrementKeyCount        = true;
                removeSize = indexEntry.InMemorySize;

                if (!indexEntry.Contains(value))
                {
                    decrementKeyCount = false;
                }

                if (indexEntry.Remove(value))
                {
                    if (indexEntry.Previous != -1)
                    {
                        previousEntry = (EvictionIndexEntry)_index[indexEntry.Previous];
                    }
                    if (indexEntry.Next != -1)
                    {
                        nextEntry = (EvictionIndexEntry)_index[indexEntry.Next];
                    }

                    if (previousEntry != null && nextEntry != null)
                    {
                        previousEntry.Next = indexEntry.Next;
                        nextEntry.Previous = indexEntry.Previous;
                    }
                    else if (previousEntry != null)
                    {
                        previousEntry.Next = indexEntry.Next;
                        _tail = indexEntry.Previous;
                    }
                    else if (nextEntry != null)
                    {
                        nextEntry.Previous = indexEntry.Previous;
                        _head = indexEntry.Next;
                    }
                    else
                    {
                        _tail = _head = -1;
                    }
                    _index.Remove(key);
                }
                else
                {
                    addSize = indexEntry.InMemorySize;
                }

                if (decrementKeyCount)
                {
                    _keysCount--;
                }
            }

            _evictionIndexEntriesSize -= removeSize;
            _evictionIndexEntriesSize += addSize;
        }
Ejemplo n.º 14
0
 public void RemoveLogger(int bucket)
 {
     _loggers.Remove(bucket);
 }
Ejemplo n.º 15
0
        private void UpdateNotifications(bool notify, string clientId, string serverUniqueId, string clientUniqueId, HashVector notifications
                                         , EventDataFilter datafilters, HashVector CID, HashVector CUID)
        {
            if (notify)
            {
                if (notifications.ContainsKey(serverUniqueId))
                {
                    HashVector clients = notifications[serverUniqueId] as HashVector;
                    if (clients.ContainsKey(clientId)) //New Query from same client
                    {
                        ClusteredList <string> clientQueries = clients[clientId] as ClusteredList <string>;
                        if (!clientQueries.Contains(clientUniqueId))
                        {
                            clientQueries.Add(clientUniqueId);
                        }
                    }
                    else //new client
                    {
                        ClusteredList <string> clientUniqueIds = new ClusteredList <string>();
                        clientUniqueIds.Add(clientUniqueId);
                        clients[clientId] = clientUniqueIds;
                    }
                }
                else //New Query altogether
                {
                    HashVector             clients         = new HashVector();
                    ClusteredList <string> clientUniqueIds = new ClusteredList <string>();
                    clientUniqueIds.Add(clientUniqueId);
                    clients[clientId] = clientUniqueIds;

                    notifications[serverUniqueId] = clients;
                }

                #region DataFilters registration
                //updating clientUIDs
                HashVector clientUIDs = null;

                if (CUID.ContainsKey(clientId))
                {
                    clientUIDs = CUID[clientId] as HashVector;
                }
                else
                {
                    CUID[clientId] = clientUIDs = new HashVector();
                }

                clientUIDs[clientUniqueId] = datafilters;

                //updating Max values
                HashVector clientDF = null;
                if (CID.ContainsKey(serverUniqueId))
                {
                    clientDF = CID[serverUniqueId] as HashVector;
                }
                else
                {
                    CID[serverUniqueId] = clientDF = new HashVector();
                }


                EventDataFilter       max = EventDataFilter.None;
                IDictionaryEnumerator ide = clientUIDs.GetEnumerator();
                while (ide.MoveNext())
                {
                    if (((EventDataFilter)ide.Value) > max)
                    {
                        max = (EventDataFilter)ide.Value;
                    }
                }
                if (!clientDF.ContainsKey(clientId) || ((EventDataFilter)clientDF[clientId]) < max)
                {
                    clientDF[clientId] = max;
                }
                #endregion
            }
            else //Not to be notified then remove it
            {
                if (notifications.ContainsKey(serverUniqueId))
                {
                    HashVector clients = notifications[serverUniqueId] as HashVector;
                    if (clients.ContainsKey(clientId))
                    {
                        ClusteredList <string> clientQueries = clients[clientId] as ClusteredList <string>;
                        if (clientQueries.Contains(clientUniqueId))
                        {
                            clientQueries.Remove(clientUniqueId);

                            if (clientQueries.Count == 0)
                            {
                                clients.Remove(clientId);
                            }
                        }
                    }
                }

                UnregisterDataFilter(serverUniqueId, clientId, clientUniqueId, CID, CUID);
            }
        }