/// <summary> /// Determines whether sort field is a part of local id from the specified local identity tag list. /// </summary> /// <param name="localIdentityTagList">The local identity tag list.</param> /// <param name="primarySortInfo">The primary sort info.</param> /// <returns> /// <c>true</c> if [is sort field part of local id] [the specified local identity tag list]; otherwise, <c>false</c>. /// </returns> private static bool IsSortFieldPartOfLocalId(List <string> localIdentityTagList, PrimarySortInfo primarySortInfo) { if (!primarySortInfo.IsTag) { return(true); } //Search sortField in localIdentityTagList foreach (string tagName in localIdentityTagList) { if (string.Compare(tagName, primarySortInfo.FieldName) == 0) { return(true); } } return(false); }
internal InDeserializationContext(int maxItemsPerIndex, string indexName, byte[] indexId, short typeId, Filter filter, bool inclusiveFilter, TagHashCollection tagHashCollection, bool deserializeHeaderOnly, bool collectFilteredItems, PrimarySortInfo primarySortInfo, List <string> localIdentityTagNames, StringHashCollection stringHashCollection, Dictionary <int, bool> stringHashCodeDictionary, IndexCondition indexCondition, CapCondition capCondition, bool isMetadataPropertyCollection, MetadataPropertyCollection metadataPropertyCollection, DomainSpecificProcessingType domainSpecificProcessingType, DomainSpecificConfig domainSpecificConfig, string getDistinctValuesFieldName, GroupBy groupBy) { MaxItemsPerIndex = maxItemsPerIndex; IndexName = indexName; IndexId = indexId; TypeId = typeId; Filter = filter; InclusiveFilter = inclusiveFilter; TagHashCollection = tagHashCollection; DeserializeHeaderOnly = deserializeHeaderOnly; CollectFilteredItems = collectFilteredItems; PrimarySortInfo = primarySortInfo; LocalIdentityTagNames = localIdentityTagNames; StringHashCollection = stringHashCollection; StringHashCodeDictionary = stringHashCodeDictionary; IndexCondition = indexCondition; CapCondition = capCondition; IsMetadataPropertyCollection = isMetadataPropertyCollection; MetadataPropertyCollection = metadataPropertyCollection; DomainSpecificProcessingType = domainSpecificProcessingType; DomainSpecificConfig = domainSpecificConfig; GetDistinctValuesFieldName = getDistinctValuesFieldName; GroupBy = groupBy; SetEnterExitCondition(); }
/// <summary> /// Gets the CacheIndexInternal. /// </summary> /// <param name="storeContext">The store context.</param> /// <param name="typeId">The type id.</param> /// <param name="primaryId">The primary id.</param> /// <param name="indexId">The index id.</param> /// <param name="extendedIdSuffix">The extended id suffix.</param> /// <param name="indexName">Name of the index.</param> /// <param name="count">The count.</param> /// <param name="filter">The filter.</param> /// <param name="inclusiveFilter">if set to <c>true</c> includes the items that pass the filter; otherwise , <c>false</c>.</param> /// <param name="indexCondition">The index condition.</param> /// <param name="deserializeHeaderOnly">if set to <c>true</c> if just CacheIndexInternal header is to be deserialized; otherwise, <c>false</c>.</param> /// <param name="getFilteredItems">if set to <c>true</c> get filtered items; otherwise, <c>false</c>.</param> /// <param name="primarySortInfo">The primary sort info.</param> /// <param name="localIdentityTagNames">The local identity tag names.</param> /// <param name="stringHashCodeDictionary">The string hash code dictionary.</param> /// <param name="capCondition">The cap condition.</param> /// <returns>CacheIndexInternal</returns> internal static CacheIndexInternal GetCacheIndexInternal(IndexStoreContext storeContext, short typeId, int primaryId, byte[] indexId, short extendedIdSuffix, string indexName, int count, Filter filter, bool inclusiveFilter, IndexCondition indexCondition, bool deserializeHeaderOnly, bool getFilteredItems, PrimarySortInfo primarySortInfo, List<string> localIdentityTagNames, Dictionary<int, bool> stringHashCodeDictionary, CapCondition capCondition) { CacheIndexInternal cacheIndexInternal = null; byte[] extendedId = FormExtendedId(indexId, extendedIdSuffix); RelayMessage getMsg = new RelayMessage(typeId, primaryId, extendedId, MessageType.Get); storeContext.IndexStorageComponent.HandleMessage(getMsg); if (getMsg.Payload != null) //CacheIndex exists { cacheIndexInternal = new CacheIndexInternal { InDeserializationContext = new InDeserializationContext { TypeId = getMsg.TypeId, TagHashCollection = storeContext.TagHashCollection, IndexId = indexId, IndexName = indexName, MaxItemsPerIndex = count, Filter = filter, InclusiveFilter = inclusiveFilter, IndexCondition = indexCondition, DeserializeHeaderOnly = deserializeHeaderOnly, CollectFilteredItems = getFilteredItems, PrimarySortInfo = primarySortInfo, LocalIdentityTagNames = localIdentityTagNames, StringHashCollection = storeContext.StringHashCollection, StringHashCodeDictionary = stringHashCodeDictionary, CapCondition = capCondition } }; // This mess is required until Moods 2.0 migrated to have IVersionSerializable version of CacheIndexInternal // ** TBD - Should be removed later if (LegacySerializationUtil.Instance.IsSupported(getMsg.TypeId)) { MemoryStream stream = new MemoryStream(getMsg.Payload.ByteArray); cacheIndexInternal.Deserialize(new CompactBinaryReader(stream)); } else { getMsg.GetObject(cacheIndexInternal); } } return cacheIndexInternal; }
/// <summary> /// Gets the CacheIndexInternal. /// </summary> /// <param name="storeContext">The store context.</param> /// <param name="typeId">The type id.</param> /// <param name="primaryId">The primary id.</param> /// <param name="indexId">The index id.</param> /// <param name="extendedIdSuffix">The extended id suffix.</param> /// <param name="indexName">Name of the index.</param> /// <param name="count">The count.</param> /// <param name="filter">The filter.</param> /// <param name="inclusiveFilter">if set to <c>true</c> includes the items that pass the filter; otherwise , <c>false</c>.</param> /// <param name="indexCondition">The index condition.</param> /// <param name="deserializeHeaderOnly">if set to <c>true</c> if just CacheIndexInternal header is to be deserialized; otherwise, <c>false</c>.</param> /// <param name="getFilteredItems">if set to <c>true</c> get filtered items; otherwise, <c>false</c>.</param> /// <param name="primarySortInfo">The primary sort info.</param> /// <param name="localIdentityTagNames">The local identity tag names.</param> /// <param name="stringHashCodeDictionary">The string hash code dictionary.</param> /// <param name="capCondition">The cap condition.</param> /// <returns>CacheIndexInternal</returns> internal static CacheIndexInternal GetCacheIndexInternal(IndexStoreContext storeContext, short typeId, int primaryId, byte[] indexId, short extendedIdSuffix, string indexName, int count, Filter filter, bool inclusiveFilter, IndexCondition indexCondition, bool deserializeHeaderOnly, bool getFilteredItems, PrimarySortInfo primarySortInfo, List <string> localIdentityTagNames, Dictionary <int, bool> stringHashCodeDictionary, CapCondition capCondition) { CacheIndexInternal cacheIndexInternal = null; byte[] extendedId = FormExtendedId(indexId, extendedIdSuffix); RelayMessage getMsg = new RelayMessage(typeId, primaryId, extendedId, MessageType.Get); storeContext.IndexStorageComponent.HandleMessage(getMsg); if (getMsg.Payload != null) //CacheIndex exists { cacheIndexInternal = new CacheIndexInternal { InDeserializationContext = new InDeserializationContext { TypeId = getMsg.TypeId, TagHashCollection = storeContext.TagHashCollection, IndexId = indexId, IndexName = indexName, MaxItemsPerIndex = count, Filter = filter, InclusiveFilter = inclusiveFilter, IndexCondition = indexCondition, DeserializeHeaderOnly = deserializeHeaderOnly, CollectFilteredItems = getFilteredItems, PrimarySortInfo = primarySortInfo, LocalIdentityTagNames = localIdentityTagNames, StringHashCollection = storeContext.StringHashCollection, StringHashCodeDictionary = stringHashCodeDictionary, CapCondition = capCondition } }; // This mess is required until Moods 2.0 migrated to have IVersionSerializable version of CacheIndexInternal // ** TBD - Should be removed later if (LegacySerializationUtil.Instance.IsSupported(getMsg.TypeId)) { MemoryStream stream = new MemoryStream(getMsg.Payload.ByteArray); cacheIndexInternal.Deserialize(new CompactBinaryReader(stream)); } else { getMsg.GetObject(cacheIndexInternal); } } return(cacheIndexInternal); }
/// <summary> /// Gets the CacheIndexInternal. /// </summary> /// <param name="storeContext">The store context.</param> /// <param name="typeId">The type id.</param> /// <param name="primaryId">The primary id.</param> /// <param name="indexId">The index id.</param> /// <param name="extendedIdSuffix">The extended id suffix.</param> /// <param name="indexName">Name of the index.</param> /// <param name="maxItemsPerIndex">The maxItemsPerIndex.</param> /// <param name="filter">The filter.</param> /// <param name="inclusiveFilter">if set to <c>true</c> includes the items that pass the filter; otherwise , <c>false</c>.</param> /// <param name="indexCondition">The index condition.</param> /// <param name="deserializeHeaderOnly">if set to <c>true</c> if just CacheIndexInternal header is to be deserialized; otherwise, <c>false</c>.</param> /// <param name="getFilteredItems">if set to <c>true</c> get filtered items; otherwise, <c>false</c>.</param> /// <param name="primarySortInfo">The primary sort info.</param> /// <param name="localIdentityTagNames">The local identity tag names.</param> /// <param name="stringHashCodeDictionary">The string hash code dictionary.</param> /// <param name="capCondition">The cap condition.</param> /// <param name="isMetadataPropertyCollection">if set to <c>true</c> metadata represents a property collection; otherwise , <c>false</c>.</param> /// <param name="metadataPropertyCollection">The MetadataPropertyCollection.</param> /// <param name="domainSpecificProcessingType">The DomainSpecificProcessingType.</param> /// <param name="domainSpecificConfig">The DomainSpecificConfig.</param> /// <param name="getDistinctValuesFieldName">The distinct value field name.</param> /// <param name="groupBy">The GroupBy clause.</param> /// <param name="forceFullGet">indicate whether or not use full get.</param> /// <returns>CacheIndexInternal</returns> internal static CacheIndexInternal GetCacheIndexInternal(IndexStoreContext storeContext, short typeId, int primaryId, byte[] indexId, short extendedIdSuffix, string indexName, int maxItemsPerIndex, Filter filter, bool inclusiveFilter, IndexCondition indexCondition, bool deserializeHeaderOnly, bool getFilteredItems, PrimarySortInfo primarySortInfo, List <string> localIdentityTagNames, Dictionary <int, bool> stringHashCodeDictionary, CapCondition capCondition, bool isMetadataPropertyCollection, MetadataPropertyCollection metadataPropertyCollection, DomainSpecificProcessingType domainSpecificProcessingType, DomainSpecificConfig domainSpecificConfig, string getDistinctValuesFieldName, GroupBy groupBy, bool forceFullGet) { CacheIndexInternal cacheIndexInternal = null; byte[] extendedId = FormExtendedId(indexId, extendedIdSuffix); //RelayMessage getMsg = new RelayMessage(typeId, primaryId, extendedId, MessageType.Get); //storeContext.IndexStorageComponent.HandleMessage(getMsg); Stream myStream; ResourcePoolItem <MemoryStream> pooledStreamItem = null; MemoryStream pooledStream; try { int indexLevelGetSize = storeContext.StorageConfiguration.CacheIndexV3StorageConfig.IndexTypeMappingCollection[typeId]. IndexCollection[indexName].PartialGetSizeInBytes; bool isFullGet = forceFullGet ? true : (indexLevelGetSize <= 0 && storeContext.PartialGetLength <= 0); if (isFullGet) { byte[] cacheBytes = BinaryStorageAdapter.Get( storeContext.IndexStorageComponent, typeId, primaryId, extendedId); if (cacheBytes != null) { myStream = new MemoryStream(cacheBytes); } else { return(null); } } else { int partialGetSize = indexLevelGetSize == 0 ? storeContext.PartialGetLength : indexLevelGetSize; // get a memory stream from the memory pool pooledStreamItem = storeContext.MemoryPool.GetItem(); pooledStream = pooledStreamItem.Item; myStream = new SmartStream( storeContext.IndexStorageComponent, typeId, primaryId, extendedId, partialGetSize, pooledStream); BerkeleyBinaryStorePerformanceCounters.Instance.IncrementCounter( BerkeleyBinaryStorePerformanceCounterEnum.PartialGetPerSec, 1); } if (myStream.Length > 0) //CacheIndex exists, this check is just for SmartStream { cacheIndexInternal = new CacheIndexInternal { InDeserializationContext = new InDeserializationContext(maxItemsPerIndex, indexName, indexId, typeId, filter, inclusiveFilter, storeContext.TagHashCollection, deserializeHeaderOnly, getFilteredItems, primarySortInfo, localIdentityTagNames, storeContext.StringHashCollection, stringHashCodeDictionary, indexCondition, capCondition, isMetadataPropertyCollection, metadataPropertyCollection, domainSpecificProcessingType, domainSpecificConfig, getDistinctValuesFieldName, groupBy) }; if (!isFullGet) { // skip the bdb entry header myStream.Read(new byte[BdbHeaderSize], 0, BdbHeaderSize); } // This mess is required until Moods 2.0 migrated to have IVersionSerializable version of CacheIndexInternal // ** TBD - Should be removed later if (LegacySerializationUtil.Instance.IsSupported(typeId)) { cacheIndexInternal.Deserialize(new CompactBinaryReader(myStream)); } else { int version = myStream.ReadByte(); try { cacheIndexInternal.Deserialize(new CompactBinaryReader(myStream), version); } catch (Exception ex) { LoggingUtil.Log.ErrorFormat( "The deserialization has an exception: primary id : {0}, index id : {1}, extendedid : {2}, extendedIdSuffix : {3}, version : {4} info : {5}", primaryId, ByteArrayToString(indexId, 0), ByteArrayToString(extendedId, 0), extendedIdSuffix, version, ex.ToString()); if (myStream.Length > 0) { myStream.Seek(0, SeekOrigin.Begin); byte[] ba = new byte[10]; myStream.Read(ba, 0, 10); LoggingUtil.Log.ErrorFormat("The first 10 bytes of the stream are {0}", ByteArrayToString(ba, 0)); } throw; } } // update SmartStream perf counters if (!isFullGet) { SmartStream mySmartStream = (SmartStream)myStream; BerkeleyBinaryStorePerformanceCounters.Instance.IncrementCounter( BerkeleyBinaryStorePerformanceCounterEnum.AvgDbGetPerPartialGet, mySmartStream.DatabaseAccessTime); BerkeleyBinaryStorePerformanceCounters.Instance.IncrementCounter( BerkeleyBinaryStorePerformanceCounterEnum.AvgDbGetPerPartialGetBase, 1); BerkeleyBinaryStorePerformanceCounters.Instance.IncrementCounter( BerkeleyBinaryStorePerformanceCounterEnum.AvgBytesPerPartialGet, mySmartStream.Position); BerkeleyBinaryStorePerformanceCounters.Instance.IncrementCounter( BerkeleyBinaryStorePerformanceCounterEnum.AvgBytesPerPartialGetBase, 1); } } } finally { // release the pooled stream if (storeContext.MemoryPool != null && pooledStreamItem != null) { storeContext.MemoryPool.ReleaseItem(pooledStreamItem); } } return(cacheIndexInternal); }
/// <summary> /// Determines whether sort field is a part of local id from the specified local identity tag list. /// </summary> /// <param name="localIdentityTagList">The local identity tag list.</param> /// <param name="primarySortInfo">The primary sort info.</param> /// <returns> /// <c>true</c> if [is sort field part of local id] [the specified local identity tag list]; otherwise, <c>false</c>. /// </returns> private static bool IsSortFieldPartOfLocalId(List<string> localIdentityTagList, PrimarySortInfo primarySortInfo) { if (!primarySortInfo.IsTag) { return true; } //Search sortField in localIdentityTagList foreach (string tagName in localIdentityTagList) { if (string.Compare(tagName, primarySortInfo.FieldName) == 0) { return true; } } return false; }