Ejemplo n.º 1
0
        /// <summary>
        /// Processes the get range query.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="messageContext">The message context.</param>
        private void ProcessGetRangeQuery(RelayMessage message, MessageContext messageContext)
        {
            GetRangeQueryResult getRangeQueryResult = GetRangeQueryProcessor.Process(message.GetQueryObject <GetRangeQuery>(),
                                                                                     messageContext,
                                                                                     storeContext);
            bool compressOption = storeContext.GetCompressOption(message.TypeId);

            message.Payload = new RelayPayload(message.TypeId,
                                               message.Id,
                                               Serializer.Serialize(getRangeQueryResult, compressOption),
                                               compressOption);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes the specified get range query.
        /// </summary>
        /// <param name="getRangeQuery">The get range query.</param>
        /// <param name="messageContext">The message context.</param>
        /// <param name="storeContext">The store context.</param>
        /// <returns>GetRangeQueryResult</returns>
        internal static GetRangeQueryResult Process(GetRangeQuery getRangeQuery, MessageContext messageContext, IndexStoreContext storeContext)
        {
            GetRangeQueryResult getRangeQueryResult;
            List <ResultItem>   resultItemList = null;
            bool indexExists  = false;
            int  indexSize    = -1;
            int  virtualCount = -1;

            byte[] metadata = null;
            MetadataPropertyCollection metadataPropertyCollection = null;

            try
            {
                IndexTypeMapping indexTypeMapping =
                    storeContext.StorageConfiguration.CacheIndexV3StorageConfig.IndexTypeMappingCollection[messageContext.TypeId];

                #region Validate Query

                ValidateQuery(indexTypeMapping, getRangeQuery);

                #endregion

                int maxItemsPerIndex = getRangeQuery.Offset - 1 + getRangeQuery.ItemNum;

                Index targetIndexInfo = indexTypeMapping.IndexCollection[getRangeQuery.TargetIndexName];
                int   indexCap        = targetIndexInfo.MaxIndexSize;

                #region Prepare Result

                #region Extract index and apply criteria

                if (indexTypeMapping.MetadataStoredSeperately)
                {
                    IndexServerUtils.GetMetadataStoredSeperately(indexTypeMapping,
                                                                 messageContext.TypeId,
                                                                 messageContext.PrimaryId,
                                                                 getRangeQuery.IndexId,
                                                                 storeContext,
                                                                 out metadata,
                                                                 out metadataPropertyCollection);
                }

                CacheIndexInternal targetIndex = IndexServerUtils.GetCacheIndexInternal(storeContext,
                                                                                        messageContext.TypeId,
                                                                                        messageContext.PrimaryId,
                                                                                        getRangeQuery.IndexId,
                                                                                        targetIndexInfo.ExtendedIdSuffix,
                                                                                        getRangeQuery.TargetIndexName,
                                                                                        maxItemsPerIndex,
                                                                                        getRangeQuery.Filter,
                                                                                        true,
                                                                                        getRangeQuery.IndexCondition,
                                                                                        false,
                                                                                        false,
                                                                                        targetIndexInfo.PrimarySortInfo,
                                                                                        targetIndexInfo.LocalIdentityTagList,
                                                                                        targetIndexInfo.StringHashCodeDictionary,
                                                                                        null,
                                                                                        targetIndexInfo.IsMetadataPropertyCollection,
                                                                                        metadataPropertyCollection,
                                                                                        getRangeQuery.DomainSpecificProcessingType,
                                                                                        storeContext.DomainSpecificConfig,
                                                                                        null,
                                                                                        null,
                                                                                        false);

                #endregion

                if (targetIndex != null)
                {
                    indexSize    = targetIndex.OutDeserializationContext.TotalCount;
                    virtualCount = targetIndex.VirtualCount;
                    indexExists  = true;

                    #region Dynamic tag sort

                    if (getRangeQuery.TagSort != null)
                    {
                        targetIndex.Sort(getRangeQuery.TagSort);
                    }

                    #endregion

                    // update perf counter
                    PerformanceCounters.Instance.SetCounterValue(
                        PerformanceCounterEnum.NumOfItemsInIndexPerGetRangeQuery,
                        messageContext.TypeId,
                        indexSize);

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

                    #region Populate resultLists

                    resultItemList = CacheIndexInternalAdapter.GetResultItemList(targetIndex, getRangeQuery.Offset, getRangeQuery.ItemNum);

                    #endregion

                    #region Get data

                    if (!getRangeQuery.ExcludeData)
                    {
                        DataTierUtil.GetData(resultItemList,
                                             null,
                                             storeContext,
                                             messageContext,
                                             indexTypeMapping.FullDataIdFieldList,
                                             getRangeQuery.FullDataIdInfo);
                    }

                    #endregion

                    #region Get metadata

                    if (getRangeQuery.GetMetadata && !indexTypeMapping.MetadataStoredSeperately)
                    {
                        IndexServerUtils.GetMetadataStoredWithIndex(indexTypeMapping,
                                                                    new List <CacheIndexInternal>(1)
                        {
                            targetIndex
                        },
                                                                    out metadata,
                                                                    out metadataPropertyCollection);
                    }

                    #endregion

                    #endregion
                }

                getRangeQueryResult = new GetRangeQueryResult(indexExists, indexSize, metadata, metadataPropertyCollection, resultItemList, virtualCount, indexCap, null);
            }
            catch (Exception ex)
            {
                getRangeQueryResult = new GetRangeQueryResult(false, -1, null, null, null, -1, 0, ex.Message);
                LoggingUtil.Log.ErrorFormat("TypeId {0} -- Error processing GetRangeQuery : {1}", messageContext.TypeId, ex);
            }
            return(getRangeQueryResult);
        }