internal override void Free(BaseReference reference)
        {
            if (reference == null)
            {
                return;
            }
            ReferenceID id = reference.Id;

            if (CacheTryGetValue(id, out StorageItem item))
            {
                CacheRemoveValue(id);
            }
            if (item == null)
            {
                item = (StorageItem)reference.Item;
            }
            if (item != null)
            {
                if (item.InQueue == InQueueState.InQueue)
                {
                    m_cachePriority.Remove(item);
                }
                int num = ItemSizes.SizeOf(item);
                m_cacheSizeBytes    -= num;
                m_totalAuditedBytes -= num;
                m_totalFreedBytes   += num;
                UpdatePeakCacheSize();
                item.Item = null;
                item.UnlinkReferences(updateId: false);
            }
            reference.Item = null;
        }
 protected override void FulfillInProgressFree()
 {
     m_storage.FreezeAllocations = true;
     while (m_inProgressFreeBytes > 0 && m_cachePriority.Count > 0)
     {
         StorageItem storageItem = m_cachePriority.ExtractLRU();
         storageItem.InQueue = InQueueState.None;
         if (storageItem.Item != null && storageItem.PinCount == 0)
         {
             CacheRemoveValue(storageItem.Id);
             int num = ItemSizes.SizeOf(storageItem);
             storageItem.Flush(m_storage, m_offsetMap);
             m_cacheSizeBytes -= num;
             if (m_cacheSizeBytes < 0)
             {
                 m_cacheSizeBytes = 0L;
             }
             m_inProgressFreeBytes -= num;
             if (m_inProgressFreeBytes < 0)
             {
                 m_inProgressFreeBytes = 0L;
             }
         }
     }
     m_storage.FreezeAllocations = false;
 }
Пример #3
0
        public int UpdateSize()
        {
            int size = m_size;

            m_size = CalculateSize(ItemSizes.SizeOf(Item));
            return(m_size - size);
        }
Пример #4
0
        private IDisposable SetAndPin(int index, T item, bool fromAdd)
        {
            CheckIndex(index, m_count - 1);
            IDisposable result;

            if (m_array != null)
            {
                result = m_array.PinValue();
                m_array.Value().Array[index] = item;
                if (fromAdd)
                {
                    m_array.UpdateSize(ItemSizes.SizeOfInObjectArray(item));
                }
            }
            else
            {
                int bucketIndex = GetBucketIndex(index);
                IReference <StorableArray> reference          = m_buckets[bucketIndex];
                UnPinCascadeHolder         unPinCascadeHolder = new UnPinCascadeHolder();
                unPinCascadeHolder.AddCleanupRef(reference.PinValue());
                m_buckets.PinContainingBucket(bucketIndex, unPinCascadeHolder);
                result = unPinCascadeHolder;
                reference.Value().Array[GetIndexInBucket(index)] = item;
                if (fromAdd)
                {
                    reference.UpdateSize(ItemSizes.SizeOfInObjectArray(item));
                }
            }
            return(result);
        }
Пример #5
0
 private void SetValue(int index, T value, bool fromAdd)
 {
     CheckIndex(index, m_count - 1);
     if (m_array != null)
     {
         using (m_array.PinValue())
         {
             m_array.Value().Array[index] = value;
             if (fromAdd)
             {
                 m_array.UpdateSize(ItemSizes.SizeOfInObjectArray(value));
             }
         }
     }
     else
     {
         IReference <StorableArray> reference = m_buckets[GetBucketIndex(index)];
         using (reference.PinValue())
         {
             reference.Value().Array[GetIndexInBucket(index)] = value;
             if (fromAdd)
             {
                 reference.UpdateSize(ItemSizes.SizeOfInObjectArray(value));
             }
         }
     }
     m_version++;
 }
Пример #6
0
        internal void SetTreePartitionContentsAndPin <T>(IReference <T> emptyPartitionRef, T contents) where T : IStorable
        {
            BaseReference baseReference = (BaseReference)emptyPartitionRef;

            m_partitionManager.TreeHasChanged = true;
            CacheItem(baseReference, contents, fromDeserialize: false, ItemSizes.SizeOf(contents));
            baseReference.PinValue();
            CacheSetValue(baseReference.Id, baseReference);
        }
Пример #7
0
        private void UpdateStatsForRemovedItem(BaseReference itemRef, ref long bytesToFree)
        {
            long num  = ItemSizes.SizeOf(itemRef.Item.Item);
            long num2 = m_cacheSizeBytes - num;
            long num3 = m_cacheFreeableBytes - num;

            if (num3 < 0)
            {
                num3 = 0L;
            }
            if (num2 < num3)
            {
                num2 = num3;
            }
            m_cacheFreeableBytes = num3;
            m_cacheSizeBytes     = num2;
            bytesToFree         -= num;
        }
        private void CacheItem(BaseReference reference, StorageItem item, bool fromDeserialize)
        {
            reference.Item = item;
            item.AddReference(reference);
            int num = ItemSizes.SizeOf(item);

            FreeCacheSpace(num, m_cacheSizeBytes);
            if (fromDeserialize)
            {
                CacheSetValue(reference.Id, item);
            }
            else
            {
                m_totalAuditedBytes += num;
            }
            m_cacheSizeBytes += num;
            EnqueueItem(item);
            (item.Item as ISelfReferential)?.SetReference(reference);
        }
Пример #9
0
        private IStorable LoadItem(BaseReference reference)
        {
            if (m_inStreamOper)
            {
                Global.Tracer.Assert(condition: false, "PartitionedTreeScalabilityCache should not Load during serialization");
            }
            IStorable storable = null;

            try
            {
                m_inStreamOper = true;
                m_deserializationTimer.Start();
                ReferenceID id = reference.Id;
                long        num;
                if (!id.IsTemporary && id.HasMultiPart)
                {
                    num = m_partitionManager.GetTreePartitionOffset(id);
                    if (num < 0)
                    {
                        return(null);
                    }
                }
                else
                {
                    num = reference.Id.Value;
                }
                if (num < 0)
                {
                    Global.Tracer.Assert(false, "Invalid offset for item.  ReferenceID: {0}, Offset: {1}", id, num);
                }
                storable = (IStorable)m_storage.Retrieve(num, out long _);
            }
            finally
            {
                m_inStreamOper = false;
                m_deserializationTimer.Stop();
            }
            CacheItem(reference, storable, fromDeserialize: true, ItemSizes.SizeOf(storable));
            return(storable);
        }
Пример #10
0
 internal sealed override void UnPin(BaseReference reference)
 {
     if (reference.PinCount == 0 && (reference.Id.IsTemporary || reference.Id.HasMultiPart) && reference.InQueue == InQueueState.None)
     {
         reference.InQueue = InQueueState.InQueue;
         m_serializationQueue.Enqueue(reference);
         if (!m_lockedDownForFlush)
         {
             ItemHolder item = reference.Item;
             IStorable  obj  = null;
             if (item != null)
             {
                 obj = item.Item;
             }
             m_cacheFreeableBytes += ItemSizes.SizeOf(obj);
         }
     }
     if (!m_lockedDownForFlush)
     {
         PeriodicOperationCheck();
     }
 }
Пример #11
0
        internal sealed override IStorable Retrieve(BaseReference reference)
        {
            if (reference.Item == null)
            {
                ReferenceID id = reference.Id;
                if (CacheTryGetValue(id, out BaseReference item) && item.Item != null)
                {
                    IStorable item2 = item.Item.Item;
                    CacheItem(reference, item2, fromDeserialize: true, ItemSizes.SizeOf(item2));
                }
                else
                {
                    LoadItem(reference);
                }
            }
            IStorable result = null;

            if (reference.Item != null)
            {
                result = reference.Item.Item;
            }
            return(result);
        }
Пример #12
0
 public sealed override IReference <T> AllocateAndPin <T>(T obj, int priority)
 {
     return((IReference <T>)AllocateAndPin(obj, ItemSizes.SizeOf(obj)));
 }
        public override IReference <T> GenerateFixedReference <T>(T obj)
        {
            BaseReference baseReference = CreateReference(obj);

            baseReference.Init(this, m_offsetMap.GenerateTempId());
            StorageItem storageItem = (StorageItem)(baseReference.Item = new StorageItem(baseReference.Id, -1, obj, ItemSizes.SizeOf(obj)));

            storageItem.AddReference(baseReference);
            storageItem.InQueue         = InQueueState.Exempt;
            storageItem.HasBeenUnPinned = true;
            (obj as ISelfReferential)?.SetReference(baseReference);
            return((IReference <T>)baseReference);
        }
 public override IReference <T> AllocateAndPin <T>(T obj, int priority)
 {
     return(InternalAllocate(obj, priority, startPinned: true, ItemSizes.SizeOf(obj)));
 }
        private bool Insert(ScalableDictionaryNodeReference nodeRef, int hashCode, TKey key, TValue value, bool add, int level, bool updateSize, out IDisposable cleanupRef)
        {
            IDisposable            disposable             = nodeRef.PinValue();
            ScalableDictionaryNode scalableDictionaryNode = nodeRef.Value();
            bool flag = false;
            int  num  = HashToSlot(scalableDictionaryNode, hashCode, level);
            IScalableDictionaryEntry scalableDictionaryEntry = scalableDictionaryNode.Entries[num];

            if (scalableDictionaryEntry == null)
            {
                ScalableDictionaryValues scalableDictionaryValues = new ScalableDictionaryValues(m_valuesCapacity);
                scalableDictionaryValues.Keys[0]   = key;
                scalableDictionaryValues.Values[0] = value;
                scalableDictionaryValues.Count++;
                scalableDictionaryNode.Entries[num] = scalableDictionaryValues;
                flag       = true;
                cleanupRef = disposable;
                if (!m_useFixedReferences && updateSize)
                {
                    int sizeBytesDelta = ItemSizes.SizeOfInObjectArray(key) + ItemSizes.SizeOfInObjectArray(value) + scalableDictionaryValues.EmptySize;
                    nodeRef.UpdateSize(sizeBytesDelta);
                }
            }
            else
            {
                switch (scalableDictionaryEntry.GetObjectType())
                {
                case Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.ScalableDictionaryNodeReference:
                {
                    ScalableDictionaryNodeReference nodeRef2 = scalableDictionaryEntry as ScalableDictionaryNodeReference;
                    flag = Insert(nodeRef2, hashCode, key, value, add, level + 1, updateSize, out cleanupRef);
                    break;
                }

                case Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.ScalableDictionaryValues:
                {
                    ScalableDictionaryValues scalableDictionaryValues2 = scalableDictionaryEntry as ScalableDictionaryValues;
                    bool flag2 = false;
                    cleanupRef = null;
                    for (int i = 0; i < scalableDictionaryValues2.Count; i++)
                    {
                        if (m_comparer.Equals(key, (TKey)scalableDictionaryValues2.Keys[i]))
                        {
                            if (add)
                            {
                                Global.Tracer.Assert(condition: false, "ScalableDictionary: An element with the same key already exists within the Dictionary");
                            }
                            scalableDictionaryValues2.Values[i] = value;
                            flag2      = true;
                            flag       = false;
                            cleanupRef = disposable;
                            break;
                        }
                    }
                    if (flag2)
                    {
                        break;
                    }
                    if (scalableDictionaryValues2.Count < scalableDictionaryValues2.Capacity)
                    {
                        int count = scalableDictionaryValues2.Count;
                        scalableDictionaryValues2.Keys[count]   = key;
                        scalableDictionaryValues2.Values[count] = value;
                        scalableDictionaryValues2.Count++;
                        flag       = true;
                        cleanupRef = disposable;
                        if (!m_useFixedReferences && updateSize)
                        {
                            nodeRef.UpdateSize(ItemSizes.SizeOfInObjectArray(key));
                            nodeRef.UpdateSize(ItemSizes.SizeOfInObjectArray(value));
                        }
                        break;
                    }
                    ScalableDictionaryNodeReference scalableDictionaryNodeReference = BuildNode(level + 1, m_nodeCapacity);
                    scalableDictionaryNode.Entries[num] = scalableDictionaryNodeReference;
                    using (scalableDictionaryNodeReference.PinValue())
                    {
                        if (!m_useFixedReferences && updateSize)
                        {
                            int num2 = ItemSizes.SizeOfInObjectArray(scalableDictionaryValues2);
                            nodeRef.UpdateSize(num2 * -1);
                            scalableDictionaryNodeReference.UpdateSize(num2);
                        }
                        for (int j = 0; j < scalableDictionaryValues2.Count; j++)
                        {
                            TKey key2 = (TKey)scalableDictionaryValues2.Keys[j];
                            Insert(scalableDictionaryNodeReference, GetHashCode(key2), key2, (TValue)scalableDictionaryValues2.Values[j], add: false, level + 1, updateSize: false, out IDisposable cleanupRef2);
                            cleanupRef2.Dispose();
                        }
                        flag = Insert(scalableDictionaryNodeReference, hashCode, key, value, add, level + 1, updateSize, out cleanupRef);
                    }
                    break;
                }

                default:
                    Global.Tracer.Assert(condition: false, "Unknown ObjectType");
                    cleanupRef = null;
                    break;
                }
            }
            if (flag)
            {
                scalableDictionaryNode.Count++;
            }
            if (disposable != cleanupRef)
            {
                disposable.Dispose();
            }
            return(flag);
        }