public List <IPrimaryRelayMessageQuery> SplitQuery(int numClustersInGroup)
        {
            IntersectionQuery intersectionQuery;
            List <IPrimaryRelayMessageQuery> queryList = new List <IPrimaryRelayMessageQuery>();
            Dictionary <int, Triple <List <byte[]>, List <int>, Dictionary <byte[], IntersectionQueryParams> > > clusterParamsMapping;

            IndexCacheUtils.SplitIndexIdsByCluster(IndexIdList, PrimaryIdList, intersectionQueryParamsMapping, numClustersInGroup, out clusterParamsMapping);

            if (clusterParamsMapping.Count == 1)
            {
                //This means that the query is not spilt across more than multiple clusters and the MaxResultItems criteria can be applied on the server
                IsSingleClusterQuery = true;
            }

            foreach (KeyValuePair <int, Triple <List <byte[]>, List <int>, Dictionary <byte[], IntersectionQueryParams> > > clusterParam in clusterParamsMapping)
            {
                intersectionQuery = new IntersectionQuery(this)
                {
                    primaryId     = clusterParam.Key,
                    IndexIdList   = clusterParam.Value.First,
                    PrimaryIdList = clusterParam.Value.Second,
                    intersectionQueryParamsMapping = clusterParam.Value.Third
                };
                queryList.Add(intersectionQuery);
            }
            return(queryList);
        }
Beispiel #2
0
 public IntersectionQuery(IntersectionQuery query)
 {
     Init(query.indexIdList,
          query.primaryIdList,
          query.targetIndexName,
          query.excludeData,
          query.getIndexHeader,
          query.intersectionQueryParamsMapping,
          query.filter,
          null);
 }
Beispiel #3
0
 public IntersectionQuery(IntersectionQuery query)
 {
     Init(query.IndexIdList,
          query.PrimaryIdList,
          query.TargetIndexName,
          query.ExcludeData,
          query.GetIndexHeader,
          query.Filter,
          query.FullDataIdInfo,
          query.Count,
          query.IndexCondition,
          query.MaxResultItems,
          query.IsSingleClusterQuery,
          query.DomainSpecificProcessingType);
 }
        public List <IPrimaryRelayMessageQuery> SplitQuery(int numClustersInGroup)
        {
            IntersectionQuery intersectionQuery;
            List <IPrimaryRelayMessageQuery> queryList = new List <IPrimaryRelayMessageQuery>();
            Dictionary <int, Triple <List <byte[]>, List <int>, Dictionary <byte[], IntersectionQueryParams> > > clusterParamsMapping;

            IndexCacheUtils.SplitIndexIdsByCluster(indexIdList, primaryIdList, intersectionQueryParamsMapping, numClustersInGroup, out clusterParamsMapping);

            foreach (KeyValuePair <int, Triple <List <byte[]>, List <int>, Dictionary <byte[], IntersectionQueryParams> > > clusterParam in clusterParamsMapping)
            {
                intersectionQuery = new IntersectionQuery(this)
                {
                    primaryId     = clusterParam.Key,
                    indexIdList   = clusterParam.Value.First,
                    primaryIdList = clusterParam.Value.Second,
                    intersectionQueryParamsMapping = clusterParam.Value.Third
                };
                queryList.Add(intersectionQuery);
            }
            return(queryList);
        }
 private void Init(Filter filter, IntersectionQuery baseQuery)
 {
     this.filter    = filter;
     this.baseQuery = baseQuery;
 }
 internal IntersectionQueryParams(IntersectionQuery baseQuery)
 {
     Init(null, baseQuery);
 }
 public IntersectionQuery(IntersectionQuery query)
 {
     Init(query.indexIdList,
         query.primaryIdList,
         query.targetIndexName,
         query.excludeData,
         query.getIndexHeader,
         query.intersectionQueryParamsMapping,
         query.filter,
         null);
 }
        /// <summary>
        /// Validates the query.
        /// </summary>
        /// <param name="indexTypeMapping">The index type mapping.</param>
        /// <param name="intersectionQuery">The intersection query.</param>
        private static void ValidateQuery(IndexTypeMapping indexTypeMapping, IntersectionQuery intersectionQuery)
        {
            if (!indexTypeMapping.IndexCollection.Contains(intersectionQuery.TargetIndexName))
            {
                throw new Exception("Invalid TargetIndexName - " + intersectionQuery.TargetIndexName);
            }

            if (intersectionQuery.PrimaryIdList != null && intersectionQuery.PrimaryIdList.Count != intersectionQuery.IndexIdList.Count)
            {
                throw new Exception("PrimaryIdList.Count does not match with IndexIdList.Count");
            }

            if (!intersectionQuery.ExcludeData && FullDataIdContainsIndexId(indexTypeMapping.FullDataIdFieldList))
            {
                throw new Exception("IntersectionQuery.ExcludeData cannot be set to true since FullDataId contains IndexId");
            }
        }
        /// <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;
        }
 public BaseClusteredIntersectionQuery(IntersectionQuery query)
     : base(query)
 {
 }
Beispiel #11
0
 public VirtualClusteredIntersectionQuery(IntersectionQuery query, string cacheTypeName)
     : base(query)
 {
     Init(cacheTypeName);
 }
 private void Init(Filter filter, IntersectionQuery baseQuery)
 {
     this.filter = filter;
     this.baseQuery = baseQuery;
 }
 internal IntersectionQueryParams(IntersectionQuery baseQuery)
 {
     Init(null, baseQuery);
 }