private StorageItem LoadItem(BaseReference reference) { if (m_inStreamOper) { Global.Tracer.Assert(condition: false, "ScalabilityCache should not Load during serialization"); } StorageItem storageItem = null; try { m_inStreamOper = true; m_deserializationTimer.Start(); long num = m_offsetMap.Retrieve(reference.Id); if (num >= 0) { storageItem = (StorageItem)m_storage.Retrieve(num, out long persistedSize); storageItem.Offset = num; storageItem.PersistedSize = persistedSize; storageItem.UpdateSize(); storageItem.HasBeenUnPinned = true; } else { Global.Tracer.Assert(condition: false); } } finally { m_inStreamOper = false; m_deserializationTimer.Stop(); } CacheItem(reference, storageItem, fromDeserialize: true); return(storageItem); }
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; }
internal void UnlinkReferences(bool updateId) { if (Reference != null) { if (updateId) { Reference.Id = Id; } Reference.Item = null; } if (m_otherReferences != null) { while (m_otherReferences.Count > 0) { BaseReference baseReference = m_otherReferences.Dequeue(); baseReference.Item = null; if (updateId) { baseReference.Id = Id; } } } Reference = null; m_otherReferences = null; }
internal override void Pin(BaseReference reference) { StorageItem item = (StorageItem)reference.Item; if (item == null) { if (CacheTryGetValue(reference.Id, out item)) { reference.Item = item; item.AddReference(reference); if (item.InQueue == InQueueState.InQueue) { m_cachePriority.Bump(item); } } else { item = LoadItem(reference); } } else if (item.InQueue == InQueueState.InQueue) { m_cachePriority.Bump(item); } item.PinCount++; }
private void WriteItem(BaseReference itemRef) { ItemHolder item = itemRef.Item; IStorable item2 = item.Item; ReferenceID id = itemRef.Id; long num = m_storage.Allocate(item2); if (id.HasMultiPart && !id.IsTemporary) { m_partitionManager.UpdateTreePartitionOffset(id, num); if (itemRef.PinCount == 0) { CacheRemoveValue(id); } } else { id = new ReferenceID(num); id.IsTemporary = false; id.HasMultiPart = false; itemRef.Id = id; } if (itemRef.PinCount == 0) { item.Item = null; item.Reference = null; itemRef.Item = null; } }
internal void CacheSetValue(ReferenceID id, BaseReference value) { if (m_cacheLookup == null) { m_cacheLookup = new SegmentedDictionary <ReferenceID, BaseReference>(503, 17, ReferenceIDEqualityComparer.Instance); } m_cacheLookup[id] = value; }
internal sealed override void ReferenceValueCallback(BaseReference reference) { if (reference.InQueue == InQueueState.Exempt) { m_cachePriority.Bump(reference.Item); } base.ReferenceValueCallback(reference); }
internal override IStorable Retrieve(BaseReference reference) { if (!CacheTryGetValue(reference.Id, out StorageItem item)) { item = LoadItem(reference); } PeriodicOperationCheck(); return(item.Item); }
internal sealed override void UpdateTargetSize(BaseReference reference, int sizeDeltaBytes) { m_cacheSizeBytes += sizeDeltaBytes; m_totalAuditedBytes += sizeDeltaBytes; if (!reference.Id.IsTemporary) { m_cacheFreeableBytes += sizeDeltaBytes; } }
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); }
public bool TryCreateReference(IStorable refTarget, out BaseReference newReference) { Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType objectType = refTarget.GetObjectType(); if (TryMapObjectTypeToReferenceType(objectType, out Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType referenceType)) { return(TryCreateReference(referenceType, out newReference)); } newReference = null; return(false); }
protected BaseReference AllocateAndPin(IStorable obj, int initialSize) { Global.Tracer.Assert(obj != null, "Cannot allocate reference to null"); BaseReference baseReference = CreateReference(obj); baseReference.Init(this, GenerateTempId()); CacheItem(baseReference, obj, fromDeserialize: false, initialSize); baseReference.PinValue(); return(baseReference); }
internal bool CacheTryGetValue(ReferenceID id, out BaseReference item) { item = null; bool result = false; if (m_cacheLookup != null) { result = m_cacheLookup.TryGetValue(id, out item); } return(result); }
protected sealed override void FulfillInProgressFree() { int num = m_cachePriority.Count; while (m_inProgressFreeBytes > 0 && num > 0) { num--; ItemHolder itemHolder = m_cachePriority.Peek(); BaseReference reference = itemHolder.Reference; if (reference.PinCount == 0) { m_cachePriority.ExtractLRU(); reference.InQueue = InQueueState.None; if (itemHolder.Item != null) { UpdateStatsForRemovedItem(reference, ref m_inProgressFreeBytes); CacheRemoveValue(reference.Id); itemHolder.Item = null; itemHolder.Reference = null; reference.Item = null; } } else { m_cachePriority.Bump(itemHolder); } } if (m_inProgressFreeBytes <= 0) { return; } using (IDecumulator <BaseReference> decumulator = m_serializationQueue.GetDecumulator()) { while (m_inProgressFreeBytes > 0 && decumulator.MoveNext()) { BaseReference current = decumulator.Current; decumulator.RemoveCurrent(); if (current.Item != null) { if (current.PinCount == 0) { UpdateStatsForRemovedItem(current, ref m_inProgressFreeBytes); } WriteItem(current); if (current.PinCount > 0) { EnqueueItem(current); CacheSetValue(current.Id, current); } } } } }
public sealed override IReference <T> GenerateFixedReference <T>(T obj) { BaseReference baseReference = CreateReference(obj); baseReference.Init(this, GenerateTempId()); ItemHolder itemHolder = new ItemHolder(); itemHolder.Reference = baseReference; itemHolder.Item = obj; baseReference.Item = itemHolder; baseReference.InQueue = InQueueState.InQueue; return((IReference <T>)baseReference); }
public void AddReference(BaseReference newReference) { if (Reference == null) { Reference = newReference; return; } if (m_otherReferences == null) { m_otherReferences = new LinkedBucketedQueue <BaseReference>(5); } m_otherReferences.Enqueue(newReference); }
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); }
private IReference <T> InternalAllocate <T>(T obj, int priority, bool startPinned, int initialSize) where T : IStorable { Global.Tracer.Assert(obj != null, "Cannot allocate reference to null"); BaseReference baseReference = CreateReference(obj); baseReference.Init(this, m_offsetMap.GenerateTempId()); CacheItem(baseReference, obj, priority, initialSize); if (startPinned) { baseReference.PinValue(); } return((IReference <T>)baseReference); }
private static List <Declaration> BuildDeclarations() { return(new List <Declaration>(8) { BaseReference.GetDeclaration(), ScalableList <StorageItem> .GetDeclaration(), ScalableDictionary <int, StorageItem> .GetDeclaration(), ScalableDictionaryNode.GetDeclaration(), ScalableDictionaryValues.GetDeclaration(), StorageItem.GetDeclaration(), StorableArray.GetDeclaration(), ScalableHybridListEntry.GetDeclaration() }); }
public override bool Equals(object obj) { if (obj == null) { return(false); } BaseReference baseReference = obj as BaseReference; if (baseReference == null) { return(false); } return(m_id == baseReference.m_id); }
public bool TryCreateReference(IStorable refTarget, out BaseReference newReference) { switch (refTarget.GetObjectType()) { case Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.StorableArray: return(TryCreateReference(Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.StorableArrayReference, out newReference)); case Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.ScalableDictionaryNode: return(TryCreateReference(Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.ScalableDictionaryNodeReference, out newReference)); default: newReference = null; return(false); } }
public bool TryCreateReference(ObjectType referenceObjectType, out BaseReference newReference) { bool flag = false; newReference = null; for (int i = 0; i < m_referenceCreators.Length; i++) { if (flag) { break; } flag = m_referenceCreators[i].TryCreateReference(referenceObjectType, out newReference); } return(flag); }
internal override void ReferenceSerializeCallback(BaseReference reference) { ReferenceID id = reference.Id; if (id.IsTemporary) { StorageItem storageItem = (StorageItem)reference.Item; ReferenceID referenceID = m_offsetMap.GenerateId(id); if (id != referenceID) { reference.Id = referenceID; storageItem.Id = referenceID; CacheRemoveValue(id); } CacheSetValue(reference.Id, storageItem); } }
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; }
public IPersistable CreateRIFObject(Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType objectType, ref IntermediateFormatReader context) { IPersistable newObject = null; bool flag = false; bool flag2 = false; for (int i = 0; i < m_objectCreators.Length; i++) { if (flag) { break; } flag = m_objectCreators[i].TryCreateObject(objectType, out newObject); } if (!flag) { flag2 = true; BaseReference newReference = null; for (int j = 0; j < m_referenceCreators.Length; j++) { if (flag) { break; } flag = m_referenceCreators[j].TryCreateReference(objectType, out newReference); } newObject = newReference; } if (flag) { newObject.Deserialize(context); if (flag2) { BaseReference baseReference = (BaseReference)newObject; newObject = baseReference.ScalabilityCache.PoolReference(baseReference); } } else { Global.Tracer.Assert(false, "Cannot create object of type: {0}", objectType); } return(newObject); }
internal override void UnPin(BaseReference reference) { StorageItem storageItem = (StorageItem)reference.Item; if (--storageItem.PinCount == 0) { if (storageItem.InQueue == InQueueState.None) { EnqueueItem(storageItem); } if (!storageItem.HasBeenUnPinned) { int num = storageItem.UpdateSize(); m_cacheSizeBytes += num; m_totalAuditedBytes += num; storageItem.HasBeenUnPinned = true; } } }
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); }
private void EnqueueItem(BaseReference itemRef) { Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType objectType = itemRef.GetObjectType(); if (objectType == Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.SubReportInstanceReference) { if (m_pinnedItems == null) { m_pinnedItems = new LinkedBucketedQueue <BaseReference>(25); } m_pinnedItems.Enqueue(itemRef); return; } ReferenceID id = itemRef.Id; if (!id.IsTemporary && (!id.HasMultiPart || m_partitionManager.GetTreePartitionOffset(id) != TreePartitionManager.EmptyTreePartitionOffset)) { m_cachePriority.Add(itemRef.Item); itemRef.InQueue = InQueueState.Exempt; } }
private void CacheItem(BaseReference reference, IStorable item, bool fromDeserialize, int newItemSize) { ItemHolder itemHolder = new ItemHolder(); itemHolder.Reference = reference; itemHolder.Item = item; reference.Item = itemHolder; FreeCacheSpace(newItemSize, m_cacheFreeableBytes); if (fromDeserialize) { CacheSetValue(reference.Id, reference); m_cacheFreeableBytes += newItemSize; } else { m_totalAuditedBytes += newItemSize; } m_cacheSizeBytes += newItemSize; EnqueueItem(reference); }
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); }