示例#1
0
 public PagedIndexQuery(List <byte[]> indexIdList,
                        int pageSize,
                        int pageNum,
                        string targetIndexName,
                        List <string> tagsFromIndexes,
                        TagSort tagSort,
                        CriterionList criterionList,
                        int maxItemsPerIndex,
                        bool excludeData,
                        bool getIndexHeader)
 {
     Init(indexIdList,
          null,
          pageSize,
          pageNum,
          targetIndexName,
          tagsFromIndexes,
          tagSort,
          maxItemsPerIndex,
          excludeData,
          getIndexHeader,
          null,
          false,
          null,
          null,
          null,
          false);
 }
示例#2
0
 private void Init(List <byte[]> indexIdList,
                   List <int> primaryIdList,
                   int pageSize,
                   int pageNum,
                   string targetIndexName,
                   List <string> tagsFromIndexes,
                   TagSort tagSort,
                   int maxItemsPerIndex,
                   bool excludeData,
                   bool getIndexHeader,
                   Dictionary <byte[], IndexIdParams> indexIdParamsMapping,
                   bool getPageableItemCount,
                   Filter filter,
                   FullDataIdInfo fullDataIdInfo,
                   IndexCondition indexCondition,
                   bool clientSidePaging)
 {
     IndexIdList          = indexIdList;
     PrimaryIdList        = primaryIdList;
     PageSize             = pageSize;
     PageNum              = pageNum;
     TargetIndexName      = targetIndexName;
     TagsFromIndexes      = tagsFromIndexes;
     TagSort              = tagSort;
     MaxItemsPerIndex     = maxItemsPerIndex;
     ExcludeData          = excludeData;
     GetIndexHeader       = getIndexHeader;
     IndexIdParamsMapping = indexIdParamsMapping;
     GetPageableItemCount = getPageableItemCount;
     Filter           = filter;
     FullDataIdInfo   = fullDataIdInfo;
     IndexCondition   = indexCondition;
     ClientSidePaging = clientSidePaging;
 }
 private void Init(List <byte[]> indexIdList,
                   List <int> primaryIdList,
                   string targetIndexName,
                   List <string> tagsFromIndexes,
                   TagSort tagSort,
                   int maxItems,
                   bool excludeData,
                   bool getIndexHeader,
                   Dictionary <byte[], IndexIdParams> indexIdParamsMapping,
                   bool getAdditionalAvailableItemCount,
                   Filter filter,
                   FullDataIdInfo fullDataIdInfo,
                   IndexCondition indexCondition,
                   bool clientSideSubsetProcessingRequired,
                   CapCondition capCondition,
                   GetIndexHeaderType getIndexHeaderType)
 {
     IndexIdList                     = indexIdList;
     PrimaryIdList                   = primaryIdList;
     TargetIndexName                 = targetIndexName;
     TagsFromIndexes                 = tagsFromIndexes;
     TagSort                         = tagSort;
     MaxItems                        = maxItems;
     ExcludeData                     = excludeData;
     GetIndexHeader                  = getIndexHeader;
     IndexIdParamsMapping            = indexIdParamsMapping;
     GetAdditionalAvailableItemCount = getAdditionalAvailableItemCount;
     Filter         = filter;
     FullDataIdInfo = fullDataIdInfo;
     IndexCondition = indexCondition;
     ClientSideSubsetProcessingRequired = clientSideSubsetProcessingRequired;
     CapCondition       = capCondition;
     GetIndexHeaderType = getIndexHeaderType;
 }
        public override void Deserialize(IPrimitiveReader reader, int version)
        {
            //Offset
            Offset = reader.ReadInt32();

            //Span
            Span = reader.ReadInt32();

            //TargetIndexName
            TargetIndexName = reader.ReadString();

            //TagsFromIndexes
            ushort count = reader.ReadUInt16();

            if (count > 0)
            {
                TagsFromIndexes = new List <string>(count);
                for (ushort i = 0; i < count; i++)
                {
                    TagsFromIndexes.Add(reader.ReadString());
                }
            }

            //TagSort
            if (reader.ReadByte() != 0)
            {
                TagSort = new TagSort();
                Serializer.Deserialize(reader.BaseStream, TagSort);
            }

            //IndexIdList
            count = reader.ReadUInt16();
            if (count > 0)
            {
                IndexIdList = new List <byte[]>(count);
                ushort len;
                for (ushort i = 0; i < count; i++)
                {
                    len = reader.ReadUInt16();
                    if (len > 0)
                    {
                        IndexIdList.Add(reader.ReadBytes(len));
                    }
                }
            }

            //Read a byte to account for deprecated CriterionList
            reader.ReadByte();

            //MaxItemsPerIndex
            MaxItems = reader.ReadInt32();

            //ExcludeData
            ExcludeData = reader.ReadBoolean();

            //GetIndexHeader
            GetIndexHeader = reader.ReadBoolean();

            //GetPageableItemCount
            GetAdditionalAvailableItemCount = reader.ReadBoolean();

            //PrimaryIdList
            count = reader.ReadUInt16();
            if (count > 0)
            {
                PrimaryIdList = new List <int>(count);
                for (ushort i = 0; i < count; i++)
                {
                    PrimaryIdList.Add(reader.ReadInt32());
                }
            }

            //Filter
            byte b = reader.ReadByte();

            if (b != 0)
            {
                FilterType filterType = (FilterType)b;
                Filter = FilterFactory.CreateFilter(reader, filterType);
            }

            //IndexIdParamsMapping
            count = reader.ReadUInt16();
            if (count > 0)
            {
                IndexIdParamsMapping = new Dictionary <byte[], IndexIdParams>(count, new ByteArrayEqualityComparer());
                byte[]        indexId;
                IndexIdParams indexIdParam;
                ushort        len;

                for (ushort i = 0; i < count; i++)
                {
                    len     = reader.ReadUInt16();
                    indexId = null;
                    if (len > 0)
                    {
                        indexId = reader.ReadBytes(len);

                        indexIdParam = new IndexIdParams();
                        Serializer.Deserialize(reader.BaseStream, indexIdParam);

                        IndexIdParamsMapping.Add(indexId, indexIdParam);
                    }
                }
            }

            //FullDataIdInfo
            if (reader.ReadBoolean())
            {
                FullDataIdInfo = new FullDataIdInfo();
                Serializer.Deserialize(reader.BaseStream, FullDataIdInfo);
            }

            //ClientSideSubsetProcessingRequired
            ClientSideSubsetProcessingRequired = reader.ReadBoolean();

            if (version >= 2)
            {
                //CapCondition
                if (reader.ReadBoolean())
                {
                    CapCondition = new CapCondition();
                    Serializer.Deserialize(reader.BaseStream, CapCondition);
                }
            }

            if (version >= 3)
            {
                //GetIndexHeaderType
                GetIndexHeaderType = (GetIndexHeaderType)reader.ReadByte();
            }
        }
示例#5
0
        public override string ToString()
        {
            var stb = new StringBuilder();

            stb.Append("(").Append("TargetIndexName: ").Append(TargetIndexName).Append("),");

            stb.Append("(").Append("TagsFromIndexes Count: ").Append(TagsFromIndexes == null ? "Null" : TagsFromIndexes.Count.ToString());
            if (TagsFromIndexes != null && TagsFromIndexes.Count > 0)
            {
                foreach (var indexName in TagsFromIndexes)
                {
                    stb.Append("(").Append(" IndexName: ").Append(indexName).Append("),");
                }
            }
            stb.Append("),");

            stb.Append("(").Append("TagSort: ").Append(TagSort == null ? "Null" : TagSort.ToString()).Append("),");

            stb.Append("(").Append("IndexIdList Count: ").Append(IndexIdList == null ? "Null" : IndexIdList.Count.ToString());
            if (IndexIdList != null && IndexIdList.Count > 0)
            {
                foreach (var indexId in IndexIdList)
                {
                    stb.Append("(").Append(" IndexId: ").Append(IndexCacheUtils.GetReadableByteArray(indexId)).Append("),");
                }
            }
            stb.Append("),");

            stb.Append("(").Append("MaxItems: ").Append(MaxItems).Append("),");

            stb.Append("(").Append("ExcludeData: ").Append(ExcludeData).Append("),");

            stb.Append("(").Append("GetIndexHeader: ").Append(GetIndexHeader).Append("),");

            stb.Append("(").Append("GetAdditionalAvailableItemCount: ").Append(GetAdditionalAvailableItemCount).Append("),");

            stb.Append("(").Append("PrimaryIdList").Append(PrimaryIdList == null ? "Null" : PrimaryIdList.Count.ToString());
            if (PrimaryIdList != null && PrimaryIdList.Count > 0)
            {
                foreach (var primaryId in PrimaryIdList)
                {
                    stb.Append("(").Append("PrimaryId: ").Append(primaryId).Append("),");
                }
            }
            stb.Append("),");

            if (Filter == null)
            {
                stb.Append("(").Append("Total Filter Count: ").Append(0);
            }
            else
            {
                stb.Append("(").Append("Total Filter Count: ").Append(Filter.FilterCount).Append(" ").Append("Filter Info - ").Append(Filter.ToString());
            }
            stb.Append("),");
            stb.Append("(").Append("IndexCondition: ").Append(IndexCondition == null ? "Null" : IndexCondition.ToString()).Append("),");
            stb.Append("(").Append("IndexIdParamsMapping Count: ").Append(IndexIdParamsMapping == null ? "Null" : IndexIdParamsMapping.Count.ToString());
            if (IndexIdParamsMapping != null && IndexIdParamsMapping.Count > 0)
            {
                foreach (var indexIdParam in IndexIdParamsMapping)
                {
                    stb.Append("(");
                    stb.Append("(").Append(" IndexId: ").Append(IndexCacheUtils.GetReadableByteArray(indexIdParam.Key)).Append("),");
                    stb.Append("(").Append("IndexIdParams: ").Append(indexIdParam.Value).Append("),");
                    stb.Append("),");
                }
            }
            stb.Append("),");
            stb.Append("(").Append("CapCondition: ").Append(CapCondition == null ? "Null" : CapCondition.ToString()).Append("),");
            stb.Append("(").Append("GetIndexHeaderType: ").Append(GetIndexHeaderType.ToString()).Append("),");
            stb.Append("(").Append("ClientSideSubsetProcessingRequired: ").Append(ClientSideSubsetProcessingRequired).Append("),");
            stb.Append("(").Append("MaxMergeCount: ").Append(MaxMergeCount).Append("),");
            stb.Append("(").Append("DomainSpecificProcessingType: ").Append(DomainSpecificProcessingType).Append("),");
            stb.Append("(").Append("GroupBy: ").Append(GroupBy == null ? "Null" : GroupBy.ToString()).Append("),");

            return(stb.ToString());
        }
示例#6
0
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            //IndexId
            ushort len = reader.ReadUInt16();

            if (len > 0)
            {
                IndexId = reader.ReadBytes(len);
            }

            //Offset
            Offset = reader.ReadInt32();

            //ItemNum
            ItemNum = reader.ReadInt32();

            //TargetIndexName
            TargetIndexName = reader.ReadString();

            //Read a byte to account for deprecated CriterionList
            reader.ReadByte();

            //ExcludeData
            ExcludeData = reader.ReadBoolean();

            //GetMetadata
            GetMetadata = reader.ReadBoolean();

            if (version >= 2)
            {
                //Filter
                byte b = reader.ReadByte();
                if (b != 0)
                {
                    FilterType filterType = (FilterType)b;
                    Filter = FilterFactory.CreateFilter(reader, filterType);
                }
            }

            if (version == 3)
            {
                //FullDataIdInfo
                FullDataIdInfo = new FullDataIdInfo();
                Serializer.Deserialize(reader.BaseStream, FullDataIdInfo);
            }

            if (version >= 4)
            {
                //FullDataIdInfo
                if (reader.ReadBoolean())
                {
                    FullDataIdInfo = new FullDataIdInfo();
                    Serializer.Deserialize(reader.BaseStream, FullDataIdInfo);
                }

                //TagSort
                if (reader.ReadBoolean())
                {
                    TagSort = new TagSort();
                    Serializer.Deserialize(reader.BaseStream, TagSort);
                }
            }

            if (version >= 5)
            {
                //IndexCondition
                if (reader.ReadBoolean())
                {
                    IndexCondition = new IndexCondition();
                    Serializer.Deserialize(reader.BaseStream, IndexCondition);
                }
            }

            if (version >= 6)
            {
                //DomainSpecificProcessingType
                DomainSpecificProcessingType = (DomainSpecificProcessingType)reader.ReadByte();
            }
        }
		public VirtualPagedIndexQuery(List<byte[]> indexIdList, int pageSize, int pageNum, string targetIndexName, List<string> tagsFromIndexes, TagSort tagSort, CriterionList criterionList, int maxItemsPerIndex, bool excludeData, bool getIndexHeader, string cacheTypeName)
			: base(indexIdList, pageSize, pageNum, targetIndexName, tagsFromIndexes, tagSort, criterionList, maxItemsPerIndex, excludeData, getIndexHeader)
		{
			Init(cacheTypeName);
		}
        /// <summary>
        /// Processes the specified intersection query.
        /// </summary>
        /// <param name="intersectionQuery">The intersection query.</param>
        /// <param name="messageContext">The message context.</param>
        /// <param name="storeContext">The store context.</param>
        /// <returns>IntersectionQueryResult</returns>
        internal static IntersectionQueryResult Process(IntersectionQuery intersectionQuery, MessageContext messageContext, IndexStoreContext storeContext)
        {
            //Fetch each index (assume all indexes are local) and perform intersection and return the results
            IntersectionQueryResult intersectionQueryResult;
            List<IndexDataItem> resultItemList = null;
            Dictionary<byte[], IndexHeader> indexIdIndexHeaderMapping = new Dictionary<byte[], IndexHeader>(new ByteArrayEqualityComparer());
            List<string> localIdentityTagNames = null;
            bool isTagPrimarySort = false;
            string sortFieldName = null;
            List<SortOrder> sortOrderList = null;
            StringBuilder exceptionInfo = new StringBuilder();

            try
            {
                if (intersectionQuery.IndexIdList.Count > 0)
                {
                    IndexTypeMapping indexTypeMapping =
                        storeContext.StorageConfiguration.CacheIndexV3StorageConfig.IndexTypeMappingCollection[messageContext.TypeId];
                    ValidateQuery(indexTypeMapping, intersectionQuery);

                    #region Set sort vars
                    
                    Index targetIndexInfo = indexTypeMapping.IndexCollection[intersectionQuery.TargetIndexName];
                    localIdentityTagNames = indexTypeMapping.IndexCollection[intersectionQuery.TargetIndexName].LocalIdentityTagList;
                    bool sortFieldPartOfLocalId = IsSortFieldPartOfLocalId(localIdentityTagNames, targetIndexInfo.PrimarySortInfo);
                    TagSort itemIdTagSort = new TagSort("ItemId", false, new SortOrder(DataType.Int32, SortBy.ASC));
                    
                    if (!sortFieldPartOfLocalId)
                    {
                        //Set sort vars
                        isTagPrimarySort = itemIdTagSort.IsTag;
                        sortFieldName = itemIdTagSort.TagName;
                        sortOrderList = new List<SortOrder>(1) { itemIdTagSort.SortOrder };
                    }
                    else
                    {
                        isTagPrimarySort = targetIndexInfo.PrimarySortInfo.IsTag;
                        sortFieldName = targetIndexInfo.PrimarySortInfo.FieldName;
                        sortOrderList = targetIndexInfo.PrimarySortInfo.SortOrderList;
                    }
                    
                    #endregion

                    #region Fetch CacheIndexInternal and Intersect
                    
                    CacheIndexInternal targetIndex;
                    CacheIndexInternal resultCacheIndexInternal = null;
                    IntersectionQueryParams indexIdParam;
                    byte[] indexId;

                    for (int i = 0; i < intersectionQuery.IndexIdList.Count; i++)
                    {
                        #region Extract index and apply criteria
                        
                        indexId = intersectionQuery.IndexIdList[i];
                        indexIdParam = intersectionQuery.GetIntersectionQueryParamForIndexId(indexId);
                        targetIndex = IndexServerUtils.GetCacheIndexInternal(storeContext,
                            messageContext.TypeId,
                            (intersectionQuery.PrimaryIdList != null && i < intersectionQuery.PrimaryIdList.Count) ?
                                    intersectionQuery.PrimaryIdList[i] :
                                    IndexCacheUtils.GeneratePrimaryId(indexId),
                            indexId,
                            targetIndexInfo.ExtendedIdSuffix,
                            intersectionQuery.TargetIndexName,
                            0,
                            indexIdParam.Filter,
                            true,
                            null,
                            false,
                            false,
                            targetIndexInfo.PrimarySortInfo,
                            targetIndexInfo.LocalIdentityTagList,
                            targetIndexInfo.StringHashCodeDictionary,
                            null);
                        
                        #endregion

                        if (targetIndex != null)
                        {
                            if (targetIndex.Count < 0)
                            {
                                // No items in one of the indexes. Stop Interestion !!
                                resultCacheIndexInternal = null;
                                break;
                            }

                            PerformanceCounters.Instance.SetCounterValue(
                                PerformanceCounterEnum.NumOfItemsInIndexPerIntersectionQuery,
                                messageContext.TypeId,
                                targetIndex.OutDeserializationContext.TotalCount);

                            PerformanceCounters.Instance.SetCounterValue(
                                PerformanceCounterEnum.NumOfItemsReadPerIntersectionQuery,
                                messageContext.TypeId,
                                targetIndex.OutDeserializationContext.ReadItemCount);

                            if (!sortFieldPartOfLocalId)
                            {
                                //Need to sort indexes by item id
                                targetIndex.Sort(itemIdTagSort);
                            }

                            #region Intersection
                            
                            if (resultCacheIndexInternal == null)
                            {
                                // No need to perform intersection for first index
                                resultCacheIndexInternal = targetIndex;
                            }
                            else
                            {
                                IntersectionAlgo.Intersect(isTagPrimarySort,
                                                           sortFieldName,
                                                           localIdentityTagNames,
                                                           sortOrderList,
                                                           resultCacheIndexInternal.InternalItemList,
                                                           targetIndex.InternalItemList);
                                
                                if (resultCacheIndexInternal == null || resultCacheIndexInternal.Count < 1)
                                {
                                    // Unable to fetch one of the indexes. Stop Interestion !!
                                    resultCacheIndexInternal = null;
                                    indexIdIndexHeaderMapping = null;
                                    break;
                                }
                            }
                            
                            #endregion
                        }
                        else
                        {
                            // Unable to fetch one of the indexes. Stop Interestion !!
                            resultCacheIndexInternal = null;
                            indexIdIndexHeaderMapping = null;
                            break;
                        }

                        #region Get MetaData
                        
                        if (intersectionQuery.GetIndexHeader)
                        {
                            if (!indexIdIndexHeaderMapping.ContainsKey(indexId))
                            {
                                indexIdIndexHeaderMapping.Add(indexId,
                                    GetIndexHeader(targetIndex, indexTypeMapping, messageContext.TypeId, IndexCacheUtils.GeneratePrimaryId(indexId), storeContext));
                            }
                        }
                        
                        #endregion
                    }
                    if (resultCacheIndexInternal != null && resultCacheIndexInternal.Count > 0)
                    {
                        resultItemList = CacheIndexInternalAdapter.GetIndexDataItemList(resultCacheIndexInternal, 1, int.MaxValue);
                    }
                    
                    #endregion

                    #region Get data
                    
                    if (!intersectionQuery.ExcludeData && resultItemList != null && resultItemList.Count > 0)
                    {
                        DataTierUtil.GetData(resultItemList, 
                            storeContext, 
                            messageContext, 
                            indexTypeMapping.FullDataIdFieldList, 
                            intersectionQuery.FullDataIdInfo);
                    }
                    
                    #endregion
                }

                intersectionQueryResult = new IntersectionQueryResult(resultItemList,
                         indexIdIndexHeaderMapping,
                         localIdentityTagNames,
                         isTagPrimarySort,
                         sortFieldName,
                         sortOrderList,
                         exceptionInfo.ToString());

                // update performance counter
                PerformanceCounters.Instance.SetCounterValue(
                    PerformanceCounterEnum.IndexLookupAvgPerIntersectionQuery,
                    messageContext.TypeId,
                    intersectionQuery.IndexIdList.Count);
            }
            catch (Exception ex)
            {
                exceptionInfo.Append(" | " + ex.Message);
                intersectionQueryResult = new IntersectionQueryResult(null, null, null, false, null, null, exceptionInfo.ToString());
                LoggingUtil.Log.ErrorFormat("TypeId {0} -- Error processing IntersectionQuery : {1}", messageContext.TypeId, ex);
            }
            return intersectionQueryResult;
        }
 /// <summary>
 /// Sorts according to the specified tag sort.
 /// </summary>
 /// <param name="tagSort">The tag sort.</param>
 internal void Sort(TagSort tagSort)
 {
     InternalItemList.Sort(tagSort);
 }
 public VirtualPagedIndexQuery(List <byte[]> indexIdList, int pageSize, int pageNum, string targetIndexName, List <string> tagsFromIndexes, TagSort tagSort, CriterionList criterionList, int maxItemsPerIndex, bool excludeData, bool getIndexHeader, string cacheTypeName)
     : base(indexIdList, pageSize, pageNum, targetIndexName, tagsFromIndexes, tagSort, criterionList, maxItemsPerIndex, excludeData, getIndexHeader)
 {
     Init(cacheTypeName);
 }