Пример #1
0
        DeleteResult <JSONDocument> IDocumentStore.DeleteDocument(RemoveOperation operation)
        {
            UsageStats stats = new UsageStats();

            stats.BeginSample();

            DeleteResult <JSONDocument> result = new DeleteResult <JSONDocument>();
            CacheItem cItem;

            if (!_cache.ContainsKey(operation.RowId))
            {
                //TODO: Read-through
                if (!_persistenceManager.MetadataIndex(_parent.Name).ContainsRowId(operation.RowId))
                {
                    if (LoggerManager.Instance.StorageLogger != null && LoggerManager.Instance.StorageLogger.IsWarnEnabled)
                    {
                        LoggerManager.Instance.StorageLogger.Warn("Delete : document not found.", "Document not found while deleting in metadataIndex. rowId = " + operation.RowId + " collection = " + Name);
                    }
                    AddFailedOperation(operation);
                    return(result);
                }
                cItem = LoadDocument(operation.RowId, operation.Context);
            }
            else
            {
                cItem = CacheGet(operation.RowId);
            }

            //Remove an item from eviction index, so that it's not marked for eviction.
            if (cItem != null)
            {
                _evictionPolicy.Remove(operation.RowId, cItem.EvictionHint);
            }

            result.Document = cItem.Document;
            result.RowId    = operation.RowId;
            //_cache.Remove(operation.RowId);
            //CacheRemove(operation.RowId);

            _indexManager.UpdateIndex(operation.RowId, result.Document, new JSONDocument(), operation.OperationId);

            cItem.Flag.SetBit(BitsetConstants.DocumentDirty);
            cItem.Flag.SetBit(BitsetConstants.MarkedForDeletion);

            PersistenceOperation persistenceOperation = new PersistenceDeleteOperation(operation.OperationId, _parent.Name, operation.RowId, cItem, operation.Context);

            AddToPersistenceDictionary(persistenceOperation);
            _persistenceManager.MetadataIndex(_parent.Name).Remove(new DocumentKey(cItem.Document.Key));

            if (_statsCollector != null)
            {
                stats.EndSample();
                _statsCollector.IncrementStatsValue(StatisticsType.AvgDeleteTime, stats.Current);
                _statsCollector.IncrementStatsValue(StatisticsType.DeletesPerSec);
            }

            return(result);
        }
Пример #2
0
 public void Remove(object key, EvictionHint hint)
 {
     Sync.AcquireWriterLock(Timeout.Infinite);
     try
     {
         _evctPolicy.Remove(key, hint);
     }
     finally
     {
         Sync.ReleaseWriterLock();
     }
 }
Пример #3
0
        /// <summary>
        /// Remove a entrada associada com a chave informada.
        /// </summary>
        /// <param name="key">Chave da entrada que será removida.</param>
        /// <param name="removalReason"></param>
        /// <param name="isUserOperation"></param>
        /// <param name="operationContext"></param>
        /// <returns></returns>
        internal override CacheEntry RemoveInternal(object key, ItemRemoveReason removalReason, bool isUserOperation, OperationContext operationContext)
        {
            if (_cacheStore == null)
            {
                throw new InvalidOperationException();
            }
            CacheEntry entry = (CacheEntry)_cacheStore.Remove(key);

            if ((entry != null) && (_evictionPolicy != null))
            {
                _evictionPolicy.Remove(key, entry.EvictionHint);
            }
            return(entry);
        }
Пример #4
0
        /// <summary>
        /// Removes the object and key pair from the cache. The key is specified as parameter.
        /// Moreover it take a removal reason and a boolean specifying if a notification should
        /// be raised.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="removalReason">reason for the removal.</param>
        /// <param name="notify">boolean specifying to raise the event.</param>
        /// <returns>item value</returns>
        internal override CacheEntry RemoveInternal(object key, ItemRemoveReason removalReason, bool isUserOperation, OperationContext operationContext, bool cloneEntry, bool needUserPayload)
        {
            if (_cacheStore == null)
            {
                throw new InvalidOperationException();
            }

            CacheEntry e = (CacheEntry)_cacheStore.Remove(key);

            if (e != null)
            {
                //Entry is no more part of store
                e.IsStored = false;

                if (_evictionPolicy != null && e.EvictionHint != null)
                {
                    _evictionPolicy.Remove(key, e.EvictionHint);
                }

                if (_notifyCacheFull)
                {
                    _notifyCacheFull = false;
                }

                if (cloneEntry)
                {
                    var clone = e.DeepClone(operationContext.UseObjectPool ? _context.TransactionalPoolManager : _context.FakeObjectPool, true);
                    //return entry to the store pool
                    MiscUtil.ReturnEntryToPool(e, _context.StorePoolManager);
                    e = clone;
                }
            }

            if (_context.PerfStatsColl != null)
            {
                if (_evictionPolicy != null)
                {
                    _context.PerfStatsColl.SetEvictionIndexSize((long)_evictionPolicy.IndexInMemorySize);
                }

                if (_context.ExpiryMgr != null)
                {
                    _context.PerfStatsColl.SetExpirationIndexSize((long)_context.ExpiryMgr.IndexInMemorySize);
                }
            }
            return(e);
        }
Пример #5
0
        /// <summary>
        /// Removes the object and key pair from the cache. The key is specified as parameter.
        /// Moreover it take a removal reason and a boolean specifying if a notification should
        /// be raised.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="removalReason">reason for the removal.</param>
        /// <param name="notify">boolean specifying to raise the event.</param>
        /// <returns>item value</returns>
        internal override CacheEntry RemoveInternal(object key, ItemRemoveReason removalReason, bool isUserOperation, OperationContext operationContext)
        {
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("LocalCache.Remove", "");
            }

            if (_cacheStore == null)
            {
                throw new InvalidOperationException();
            }

            CacheEntry e = (CacheEntry)_cacheStore.Remove(key);

            if (e != null)
            {
                if (_evictionPolicy != null && e.EvictionHint != null)
                {
                    _evictionPolicy.Remove(key, e.EvictionHint);
                }

                if (_notifyCacheFull)
                {
                    _notifyCacheFull = false;
                }
            }

            if (_context.PerfStatsColl != null)
            {
                if (_evictionPolicy != null)
                {
                    _context.PerfStatsColl.SetEvictionIndexSize((long)_evictionPolicy.IndexInMemorySize);
                }

                if (_context.ExpiryMgr != null)
                {
                    _context.PerfStatsColl.SetExpirationIndexSize((long)_context.ExpiryMgr.IndexInMemorySize);
                }
            }

            return(e);
        }
Пример #6
0
        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)
                {
                    switch (hintPriority)
                    {
                    case CacheItemPriority.Low:
                        if (_index[0] == null)
                        {
                            _index[0] = new HashVector();
                        }
                        _index[0][key] = hint;
                        break;

                    case CacheItemPriority.BelowNormal:
                        if (_index[1] == null)
                        {
                            _index[1] = new HashVector();
                        }
                        _index[1][key] = hint;
                        break;

                    case CacheItemPriority.Normal:
                        if (_index[2] == null)
                        {
                            _index[2] = new HashVector();
                        }
                        _index[2][key] = hint;
                        break;

                    case CacheItemPriority.AboveNormal:
                        if (_index[3] == null)
                        {
                            _index[3] = new HashVector();
                        }
                        _index[3][key] = hint;
                        break;

                    case CacheItemPriority.High:
                        if (_index[4] == null)
                        {
                            _index[4] = new HashVector();
                        }
                        _index[4][key] = hint;
                        break;
                    }
                }
            }
        }
Пример #7
0
        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 Hashtable(25000, 0.7f);
                        }
                        _index[0][key] = hint;
                        changedIndex   = 0;
                        break;

                    case CacheItemPriority.BelowNormal:
                        if (_index[1] == null)
                        {
                            _index[1] = new Hashtable(25000, 0.7f);
                        }
                        _index[1][key] = hint;
                        changedIndex   = 1;
                        break;

                    case CacheItemPriority.Normal:
                        if (_index[2] == null)
                        {
                            _index[2] = new Hashtable(25000, 0.7f);
                        }
                        _index[2][key] = hint;
                        changedIndex   = 2;
                        break;

                    case CacheItemPriority.AboveNormal:
                        if (_index[3] == null)
                        {
                            _index[3] = new Hashtable(25000, 0.7f);
                        }
                        _index[3][key] = hint;
                        changedIndex   = 3;
                        break;

                    case CacheItemPriority.High:
                        if (_index[4] == null)
                        {
                            _index[4] = new Hashtable(25000, 0.7f);
                        }
                        _index[4][key] = hint;
                        changedIndex   = 4;
                        break;
                    }

                    if (changedIndex > -1 && _index[changedIndex].Count > _evictionIndexMaxCounts[changedIndex])
                    {
                        _evictionIndexMaxCounts[changedIndex] = _index[changedIndex].Count;
                    }
                }
            }
        }