private static void ValidateQuery(MultiIndexContainsQuery multiIndexContainsQuery, IndexTypeMapping indexTypeMapping, IndexStoreContext storeContext, short typeId, out short relatedTypeId) { relatedTypeId = -1; if (string.IsNullOrEmpty(multiIndexContainsQuery.TargetIndexName)) { multiIndexContainsQuery.TargetIndexName = IndexServerUtils.CheckQueryTargetIndexName(indexTypeMapping); } if (!indexTypeMapping.IndexCollection.Contains(multiIndexContainsQuery.TargetIndexName)) { throw new Exception("Invalid TargetIndexName - " + multiIndexContainsQuery.TargetIndexName); } if (!multiIndexContainsQuery.ExcludeData) { if (multiIndexContainsQuery.FullDataIdInfo != null && multiIndexContainsQuery.FullDataIdInfo.RelatedTypeName != null) { if (!storeContext.TryGetTypeId(multiIndexContainsQuery.FullDataIdInfo.RelatedTypeName, out relatedTypeId)) { LoggingUtil.Log.ErrorFormat("Invalid RelatedCacheTypeName - {0}", multiIndexContainsQuery.FullDataIdInfo.RelatedTypeName); throw new Exception("Invalid RelatedTypeId for TypeId - " + multiIndexContainsQuery.FullDataIdInfo.RelatedTypeName); } } else if (!storeContext.TryGetRelatedIndexTypeId(typeId, out relatedTypeId)) { LoggingUtil.Log.ErrorFormat("Invalid RelatedTypeId for TypeId - {0}", typeId); throw new Exception("Invalid RelatedTypeId for TypeId - " + typeId); } } }
/// <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 (intersectionQuery.IsSingleClusterQuery && intersectionQuery.IndexIdList.Count == 1) { throw new Exception("Intersection requires minimum two Index Ids in the IndexIdList"); } if (string.IsNullOrEmpty(intersectionQuery.TargetIndexName)) { intersectionQuery.TargetIndexName = IndexServerUtils.CheckQueryTargetIndexName(indexTypeMapping); } 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> /// Validates the query. /// </summary> /// <param name="indexTypeMapping">The index type mapping.</param> /// <param name="query">The query.</param> /// <param name="messageContext">The message context.</param> protected override void ValidateQuery(IndexTypeMapping indexTypeMapping, BaseMultiIndexIdQuery <SpanQueryResult> query, MessageContext messageContext) { SpanQuery spanQuery = query as SpanQuery; if (spanQuery == null) { throw new Exception(string.Format("Invalid span query, failed to cast")); } if (string.IsNullOrEmpty(spanQuery.TargetIndexName)) { spanQuery.TargetIndexName = IndexServerUtils.CheckQueryTargetIndexName(indexTypeMapping); } if (!indexTypeMapping.IndexCollection.Contains(query.TargetIndexName)) { throw new Exception("Invalid TargetIndexName - " + query.TargetIndexName); } if (query.IndexIdList == null || query.IndexIdList.Count == 0) { throw new Exception("No IndexIdList present on the query"); } if (query.PrimaryIdList != null && query.PrimaryIdList.Count != query.IndexIdList.Count) { throw new Exception("PrimaryIdList.Count does not match with IndexIdList.Count"); } if (spanQuery.Offset < 1 && spanQuery.Span != 0) { throw new Exception("SpanQuery.Offset should be greater than zero except when SpanQuery.Span is zero"); } }
/// <summary> /// Validates the query. /// </summary> /// <param name="indexTypeMapping">The index type mapping.</param> /// <param name="firstLastQuery">The first last query.</param> private static void ValidateQuery(IndexTypeMapping indexTypeMapping, FirstLastQuery firstLastQuery) { if (string.IsNullOrEmpty(firstLastQuery.TargetIndexName)) { firstLastQuery.TargetIndexName = IndexServerUtils.CheckQueryTargetIndexName(indexTypeMapping); } if (!indexTypeMapping.IndexCollection.Contains(firstLastQuery.TargetIndexName)) { throw new Exception("Invalid TargetIndexName - " + firstLastQuery.TargetIndexName); } if (firstLastQuery.IndexId == null || firstLastQuery.IndexId.Length == 0) { throw new Exception("No IndexId present on the FirstLastQuery"); } if ((firstLastQuery.FirstPageSize < 1) && (firstLastQuery.LastPageSize < 1)) { throw new Exception("Atleast one of FirstLastQuery.FirstPageSize and FirstLastQuery.LastPageSize should be greater than 1"); } }
/// <summary> /// Validates the query. /// </summary> /// <param name="indexTypeMapping">The index type mapping.</param> /// <param name="getRangeQuery">The get range query.</param> private static void ValidateQuery(IndexTypeMapping indexTypeMapping, GetRangeQuery getRangeQuery) { if (string.IsNullOrEmpty(getRangeQuery.TargetIndexName)) { getRangeQuery.TargetIndexName = IndexServerUtils.CheckQueryTargetIndexName(indexTypeMapping); } if (!indexTypeMapping.IndexCollection.Contains(getRangeQuery.TargetIndexName)) { throw new Exception("Invalid TargetIndexName - " + getRangeQuery.TargetIndexName); } if (getRangeQuery.IndexId == null || getRangeQuery.IndexId.Length == 0) { throw new Exception("No IndexId present on the GetRangeQuery"); } if ((getRangeQuery.Offset < 1) || (getRangeQuery.ItemNum < 1)) { throw new Exception("Both GetRangeQuery.Offset and GetRangeQuery.ItemNum should be greater than 1"); } }
/// <summary> /// Validates the query. /// </summary> /// <param name="indexTypeMapping">The index type mapping.</param> /// <param name="randomQuery">The random query.</param> private static void ValidateQuery(IndexTypeMapping indexTypeMapping, RandomQuery randomQuery) { if (string.IsNullOrEmpty(randomQuery.TargetIndexName)) { randomQuery.TargetIndexName = IndexServerUtils.CheckQueryTargetIndexName(indexTypeMapping); } if (!indexTypeMapping.IndexCollection.Contains(randomQuery.TargetIndexName)) { throw new Exception("Invalid TargetIndexName - " + randomQuery.TargetIndexName); } if (randomQuery.IndexId == null || randomQuery.IndexId.Length == 0) { throw new Exception("No IndexId present on the RandomQuery"); } if (randomQuery.Count < 1) { throw new Exception("Both RandomQuery.Count should be greater than 1"); } }
/// <summary> /// Validates the query. /// </summary> /// <param name="indexTypeMapping">The index type mapping.</param> /// <param name="query">The query.</param> /// <param name="messageContext">The message context.</param> protected override void ValidateQuery(IndexTypeMapping indexTypeMapping, BaseMultiIndexIdQuery <PagedIndexQueryResult> query, MessageContext messageContext) { if (string.IsNullOrEmpty(query.TargetIndexName)) { query.TargetIndexName = IndexServerUtils.CheckQueryTargetIndexName(indexTypeMapping); } if (!indexTypeMapping.IndexCollection.Contains(query.TargetIndexName)) { throw new Exception("Invalid TargetIndexName - " + query.TargetIndexName); } if (query.IndexIdList == null || query.IndexIdList.Count == 0) { throw new Exception("No IndexIdList present on the query"); } if (query.PrimaryIdList != null && query.PrimaryIdList.Count != query.IndexIdList.Count) { throw new Exception("PrimaryIdList.Count does not match with IndexIdList.Count"); } PerformQueryOverride(indexTypeMapping, query, messageContext); }
/// <summary> /// Processes the specified contains index query. /// </summary> /// <param name="containsIndexQuery">The contains index query.</param> /// <param name="messageContext">The message context.</param> /// <param name="storeContext">The store context.</param> /// <returns>ContainsIndexQueryResult</returns> internal static ContainsIndexQueryResult Process(ContainsIndexQuery containsIndexQuery, MessageContext messageContext, IndexStoreContext storeContext) { ContainsIndexQueryResult containsIndexQueryResult; MultiItemResult multiItemResult = null; byte[] metadata = null; MetadataPropertyCollection metadataPropertyCollection = null; bool indexExists = false; int indexSize = -1; int virtualCount = -1; try { IndexTypeMapping indexTypeMapping = storeContext.StorageConfiguration.CacheIndexV3StorageConfig.IndexTypeMappingCollection[messageContext.TypeId]; #region Check TargetIndexName if (string.IsNullOrEmpty(containsIndexQuery.TargetIndexName)) { containsIndexQuery.TargetIndexName = IndexServerUtils.CheckQueryTargetIndexName(indexTypeMapping); } if (!indexTypeMapping.IndexCollection.Contains(containsIndexQuery.TargetIndexName)) { throw new Exception("Invalid TargetIndexName - " + containsIndexQuery.TargetIndexName); } #endregion Index targetIndexInfo = indexTypeMapping.IndexCollection[containsIndexQuery.TargetIndexName]; int indexCap = targetIndexInfo.MaxIndexSize; List <CacheIndexInternal> internalCacheIndexList = new List <CacheIndexInternal>(); #region Get TargetIndex CacheIndexInternal cacheIndexInternal = IndexServerUtils.GetCacheIndexInternal(storeContext, messageContext.TypeId, messageContext.PrimaryId, containsIndexQuery.IndexId, targetIndexInfo.ExtendedIdSuffix, containsIndexQuery.TargetIndexName, 0, null, true, null, false, false, targetIndexInfo.PrimarySortInfo, targetIndexInfo.LocalIdentityTagList, targetIndexInfo.StringHashCodeDictionary, null, targetIndexInfo.IsMetadataPropertyCollection, null, containsIndexQuery.DomainSpecificProcessingType, storeContext.DomainSpecificConfig, null, null, false); #endregion if (cacheIndexInternal != null) { internalCacheIndexList.Add(cacheIndexInternal); indexExists = true; indexSize = cacheIndexInternal.OutDeserializationContext.TotalCount; virtualCount = cacheIndexInternal.VirtualCount; // update the performance counter PerformanceCounters.Instance.SetCounterValue( PerformanceCounterEnum.NumOfItemsInIndexPerContainsIndexQuery, messageContext.TypeId, indexSize); PerformanceCounters.Instance.SetCounterValue( PerformanceCounterEnum.NumOfItemsReadPerContainsIndexQuery, messageContext.TypeId, cacheIndexInternal.OutDeserializationContext.ReadItemCount); int searchIndex; IndexDataItem indexDataItem; foreach (IndexItem queryIndexItem in containsIndexQuery.IndexItemList) { #region Search item in index searchIndex = internalCacheIndexList[0].Search(queryIndexItem); #endregion if (searchIndex > -1) { if (multiItemResult == null) { multiItemResult = new MultiItemResult(containsIndexQuery.IndexId); } indexDataItem = new IndexDataItem(InternalItemAdapter.ConvertToIndexItem(internalCacheIndexList[0].GetItem(searchIndex), internalCacheIndexList[0].InDeserializationContext)); #region Get extra tags if (containsIndexQuery.TagsFromIndexes != null && containsIndexQuery.TagsFromIndexes.Count != 0) { foreach (string indexName in containsIndexQuery.TagsFromIndexes) { Index indexInfo = indexTypeMapping.IndexCollection[indexName]; CacheIndexInternal indexInternal = IndexServerUtils.GetCacheIndexInternal(storeContext, messageContext.TypeId, messageContext.PrimaryId, containsIndexQuery.IndexId, indexInfo.ExtendedIdSuffix, indexName, 0, null, true, null, false, false, indexInfo.PrimarySortInfo, indexInfo.LocalIdentityTagList, indexInfo.StringHashCodeDictionary, null, indexInfo.IsMetadataPropertyCollection, null, containsIndexQuery.DomainSpecificProcessingType, storeContext.DomainSpecificConfig, null, null, false); if (indexInternal != null) { // update the performance counter PerformanceCounters.Instance.SetCounterValue( PerformanceCounterEnum.NumOfItemsInIndexPerContainsIndexQuery, messageContext.TypeId, indexInternal.OutDeserializationContext.TotalCount); PerformanceCounters.Instance.SetCounterValue( PerformanceCounterEnum.NumOfItemsReadPerContainsIndexQuery, messageContext.TypeId, indexInternal.OutDeserializationContext.ReadItemCount); internalCacheIndexList.Add(indexInternal); IndexServerUtils.GetTags(indexInternal, queryIndexItem, indexDataItem); } } } #endregion multiItemResult.Add(indexDataItem); } } #region Get data if (!containsIndexQuery.ExcludeData && multiItemResult != null) { byte[] extendedId; List <RelayMessage> dataStoreMessages = new List <RelayMessage>(multiItemResult.Count); short relatedTypeId; if (containsIndexQuery.FullDataIdInfo != null && containsIndexQuery.FullDataIdInfo.RelatedTypeName != null) { if (!storeContext.TryGetTypeId(containsIndexQuery.FullDataIdInfo.RelatedTypeName, out relatedTypeId)) { LoggingUtil.Log.ErrorFormat("Invalid RelatedCacheTypeName - {0}", containsIndexQuery.FullDataIdInfo.RelatedTypeName); throw new Exception("Invalid RelatedTypeId for TypeId - " + containsIndexQuery.FullDataIdInfo.RelatedTypeName); } } else if (!storeContext.TryGetRelatedIndexTypeId(messageContext.TypeId, out relatedTypeId)) { LoggingUtil.Log.ErrorFormat("Invalid RelatedTypeId for TypeId - {0}", messageContext.TypeId); throw new Exception("Invalid RelatedTypeId for TypeId - " + messageContext.TypeId); } foreach (IndexDataItem resultItem in multiItemResult) { extendedId = DataTierUtil.GetFullDataId(containsIndexQuery.IndexId, resultItem, containsIndexQuery.FullDataIdInfo != null && containsIndexQuery.FullDataIdInfo.RelatedTypeName != null ? containsIndexQuery.FullDataIdInfo.FullDataIdFieldList : indexTypeMapping.FullDataIdFieldList); dataStoreMessages.Add(new RelayMessage(relatedTypeId, IndexCacheUtils.GeneratePrimaryId(extendedId), extendedId, MessageType.Get)); } storeContext.ForwarderComponent.HandleMessages(dataStoreMessages); int i = 0; foreach (IndexDataItem resultItem in multiItemResult) { if (dataStoreMessages[i].Payload != null) { resultItem.Data = dataStoreMessages[i].Payload.ByteArray; } i++; } } #endregion #region Get metadata if (containsIndexQuery.GetMetadata) { if (indexTypeMapping.MetadataStoredSeperately) { IndexServerUtils.GetMetadataStoredSeperately(indexTypeMapping, messageContext.TypeId, messageContext.PrimaryId, containsIndexQuery.IndexId, storeContext, out metadata, out metadataPropertyCollection); } else { IndexServerUtils.GetMetadataStoredWithIndex(indexTypeMapping, internalCacheIndexList, out metadata, out metadataPropertyCollection); } } #endregion } containsIndexQueryResult = new ContainsIndexQueryResult(multiItemResult, metadata, metadataPropertyCollection, indexSize, indexExists, virtualCount, indexCap, null); } catch (Exception ex) { containsIndexQueryResult = new ContainsIndexQueryResult(null, null, null, -1, false, -1, 0, ex.Message); LoggingUtil.Log.ErrorFormat("TypeId {0} -- Error processing ContainsIndexQuery : {1}", messageContext.TypeId, ex); } return(containsIndexQueryResult); }