コード例 #1
0
        protected override void WriteIndexUtilizationInfo(IndexUtilizationInfo indexUtilizationInfo)
        {
            QueryMetricsTextWriter.AppendHeaderToStringBuilder(this.stringBuilder, QueryMetricsTextWriter.UtilizedIndexes, indentLevel: 1);

            foreach (IndexUtilizationData indexUtilizationData in indexUtilizationInfo.UtilizedIndexes)
            {
                WriteIndexUtilizationData(indexUtilizationData);
            }

            QueryMetricsTextWriter.AppendHeaderToStringBuilder(this.stringBuilder, QueryMetricsTextWriter.PotentialIndexes, indentLevel: 1);

            foreach (IndexUtilizationData indexUtilizationData in indexUtilizationInfo.PotentialIndexes)
            {
                WriteIndexUtilizationData(indexUtilizationData);
            }

            void WriteIndexUtilizationData(IndexUtilizationData indexUtilizationData)
            {
                QueryMetricsTextWriter.AppendHeaderToStringBuilder(this.stringBuilder, $"{QueryMetricsTextWriter.FilterExpression}: {indexUtilizationData.FilterExpression}", indentLevel: 2);
                QueryMetricsTextWriter.AppendHeaderToStringBuilder(this.stringBuilder, $"{QueryMetricsTextWriter.IndexExpression}: {indexUtilizationData.IndexDocumentExpression}", indentLevel: 2);
                QueryMetricsTextWriter.AppendHeaderToStringBuilder(this.stringBuilder, $"{QueryMetricsTextWriter.FilterExpressionPrecision}: {indexUtilizationData.FilterExpressionPrecision}", indentLevel: 2);
                //QueryMetricsTextWriter.AppendHeaderToStringBuilder(stringBuilder, $"{QueryMetricsTextWriter.IndexPlanFullFidelity}: {indexUtilizationData.IndexPlanFullFidelity}", indentLevel: 2); //currently not exposed to the users
                QueryMetricsTextWriter.AppendHeaderToStringBuilder(this.stringBuilder, IndexUtilizationSeparator, indentLevel: 2);
            }
        }
コード例 #2
0
        internal QueryMetrics(
            long retrievedDocumentCount,
            long retrievedDocumentSize,
            long outputDocumentCount,
            long outputDocumentSize,
            long indexHitDocumentCount,
            IndexUtilizationInfo indexUtilizationInfo,
            TimeSpan totalQueryExecutionTime,
            QueryPreparationTimes queryPreparationTimes,
            TimeSpan indexLookupTime,
            TimeSpan documentLoadTime,
            TimeSpan vmExecutionTime,
            RuntimeExecutionTimes runtimeExecutionTimes,
            TimeSpan documentWriteTime,
            ClientSideMetrics clientSideMetrics)
        {
            if (queryPreparationTimes == null)
            {
                throw new ArgumentNullException($"{nameof(queryPreparationTimes)} can not be null.");
            }

            if (runtimeExecutionTimes == null)
            {
                throw new ArgumentNullException($"{nameof(runtimeExecutionTimes)} can not be null.");
            }

            if (clientSideMetrics == null)
            {
                throw new ArgumentNullException($"{nameof(clientSideMetrics)} can not be null.");
            }

            this.retrievedDocumentCount  = retrievedDocumentCount;
            this.retrievedDocumentSize   = retrievedDocumentSize;
            this.outputDocumentCount     = outputDocumentCount;
            this.outputDocumentSize      = outputDocumentSize;
            this.indexHitDocumentCount   = indexHitDocumentCount;
            this.indexUtilizationInfo    = indexUtilizationInfo;
            this.totalQueryExecutionTime = totalQueryExecutionTime;
            this.queryPreparationTimes   = queryPreparationTimes;
            this.indexLookupTime         = indexLookupTime;
            this.documentLoadTime        = documentLoadTime;
            this.vmExecutionTime         = vmExecutionTime;
            this.runtimeExecutionTimes   = runtimeExecutionTimes;
            this.documentWriteTime       = documentWriteTime;
            this.clientSideMetrics       = clientSideMetrics;
            this.queryEngineTimes        = new QueryEngineTimes(indexLookupTime, documentLoadTime, vmExecutionTime, documentWriteTime, runtimeExecutionTimes);
        }
コード例 #3
0
        /// <summary>
        /// Creates a new IndexUtilizationInfo from the backend delimited string.
        /// </summary>
        /// <param name="delimitedString">The backend delimted string to desrialize from.</param>
        /// <param name="result">The parsed index utilization info</param>
        /// <returns>A new IndexUtilizationInfo from the backend delimited string.</returns>
        internal static bool TryCreateFromDelimitedString(string delimitedString, out IndexUtilizationInfo result)
        {
            if (delimitedString == null)
            {
                result = IndexUtilizationInfo.Empty;
                return(true);
            }
            try
            {
                string indexString = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(delimitedString));

                result = JsonConvert.DeserializeObject <IndexUtilizationInfo>(indexString);
                if (result == null)
                {
                    result = IndexUtilizationInfo.Empty;
                }
                return(true);
            }
            catch
            {
                result = IndexUtilizationInfo.Empty;
                return(false);
            }
        }
コード例 #4
0
        protected override async Task <DocumentFeedResponse <CosmosElement> > ExecuteInternalAsync(CancellationToken token)
        {
            CollectionCache collectionCache = await this.Client.GetCollectionCacheAsync();

            PartitionKeyRangeCache partitionKeyRangeCache = await this.Client.GetPartitionKeyRangeCacheAsync();

            IDocumentClientRetryPolicy retryPolicyInstance = this.Client.ResetSessionTokenRetryPolicy.GetRequestPolicy();

            retryPolicyInstance = new InvalidPartitionExceptionRetryPolicy(retryPolicyInstance);
            if (base.ResourceTypeEnum.IsPartitioned())
            {
                retryPolicyInstance = new PartitionKeyRangeGoneRetryPolicy(
                    collectionCache,
                    partitionKeyRangeCache,
                    PathsHelper.GetCollectionPath(base.ResourceLink),
                    retryPolicyInstance);
            }

            return(await BackoffRetryUtility <DocumentFeedResponse <CosmosElement> > .ExecuteAsync(
                       async() =>
            {
                this.fetchExecutionRangeAccumulator.BeginFetchRange();
                ++this.retries;
                Tuple <DocumentFeedResponse <CosmosElement>, string> responseAndPartitionIdentifier = await this.ExecuteOnceAsync(retryPolicyInstance, token);
                DocumentFeedResponse <CosmosElement> response = responseAndPartitionIdentifier.Item1;
                string partitionIdentifier = responseAndPartitionIdentifier.Item2;
                if (!string.IsNullOrEmpty(response.ResponseHeaders[HttpConstants.HttpHeaders.QueryMetrics]))
                {
                    this.fetchExecutionRangeAccumulator.EndFetchRange(
                        partitionIdentifier,
                        response.ActivityId,
                        response.Count,
                        this.retries);
                    response = new DocumentFeedResponse <CosmosElement>(
                        response,
                        response.Count,
                        response.Headers,
                        response.UseETagAsContinuation,
                        new Dictionary <string, QueryMetrics>
                    {
                        {
                            partitionIdentifier,
                            new QueryMetrics(
                                BackendMetrics.ParseFromDelimitedString(response.ResponseHeaders[HttpConstants.HttpHeaders.QueryMetrics]),
                                IndexUtilizationInfo.CreateFromString(response.ResponseHeaders[HttpConstants.HttpHeaders.IndexUtilization]),
                                new ClientSideMetrics(
                                    this.retries,
                                    response.RequestCharge,
                                    this.fetchExecutionRangeAccumulator.GetExecutionRanges()))
                        }
                    },
                        response.RequestStatistics,
                        response.DisallowContinuationTokenMessage,
                        response.ResponseLengthBytes);
                }

                this.retries = -1;
                return response;
            },
                       retryPolicyInstance,
                       token));
        }
コード例 #5
0
 protected abstract void WriteIndexUtilizationInfo(IndexUtilizationInfo indexUtilizationInfo);
コード例 #6
0
 protected override void WriteIndexUtilizationInfo(IndexUtilizationInfo indexUtilizationInfo)
 {
     // Do nothing
 }