Ejemplo n.º 1
0
        private void StoreAggregationResult(TreePage page, Table table, AggregationResult result)
        {
            using (_treeReductionStats.StoringReduceResult.Start())
            {
                var pageNumber      = Bits.SwapBytes(page.PageNumber);
                var numberOfOutputs = result.Count;

                using (table.Allocate(out TableValueBuilder tvb))
                {
                    tvb.Add(pageNumber);
                    tvb.Add(page.NumberOfEntries);
                    tvb.Add(numberOfOutputs);

                    foreach (var output in result.GetOutputsToStore())
                    {
                        tvb.Add(output.BasePointer, output.Size);
                    }

                    table.Set(tvb);
                }
            }
        }
Ejemplo n.º 2
0
        private void StoreAggregationResult(long modifiedPage, int aggregatedEntries, Table table, AggregationResult result, IndexingStatsScope stats)
        {
            using (_treeReductionStats.StoringReduceResult.Start())
            {
                var pageNumber      = Bits.SwapBytes(modifiedPage);
                var numberOfOutputs = result.Count;

                var tvb = new TableValueBuilder
                {
                    pageNumber,
                    aggregatedEntries,
                    numberOfOutputs
                };

                foreach (var output in result.GetOutputsToStore())
                {
                    tvb.Add(output.BasePointer, output.Size);
                }

                table.Set(tvb);
            }
        }
Ejemplo n.º 3
0
        private void HandleNestedValuesReduction(TransactionOperationContext indexContext, IndexingStatsScope stats,
                                                 MapReduceResultsStore modifiedStore,
                                                 Lazy <IndexWriteOperation> writer, LazyStringValue reduceKeyHash, CancellationToken token)
        {
            EnsureValidNestedValuesReductionStats(stats);

            var numberOfEntriesToReduce = 0;

            try
            {
                var section = modifiedStore.GetNestedResultsSection();

                if (section.IsModified == false)
                {
                    return;
                }

                using (_nestedValuesReductionStats.NestedValuesRead.Start())
                {
                    numberOfEntriesToReduce += section.GetResults(indexContext, _aggregationBatch.Items);
                }

                stats.RecordReduceAttempts(numberOfEntriesToReduce);

                AggregationResult result = null;

                try
                {
                    using (_nestedValuesReductionStats.NestedValuesAggregation.Start())
                    {
                        result = AggregateOn(_aggregationBatch.Items, indexContext, _nestedValuesReductionStats.NestedValuesAggregation, token);
                    }

                    if (section.IsNew == false)
                    {
                        writer.Value.DeleteReduceResult(reduceKeyHash, stats);
                    }

                    foreach (var output in result.GetOutputs())
                    {
                        writer.Value.IndexDocument(reduceKeyHash, null, output, stats, indexContext);
                    }
                }
                finally
                {
                    result?.Dispose();
                }

                _index.ReducesPerSec?.MarkSingleThreaded(numberOfEntriesToReduce);
                _metrics.MapReduceIndexes.ReducedPerSec.Mark(numberOfEntriesToReduce);

                stats.RecordReduceSuccesses(numberOfEntriesToReduce);

                _index.UpdateThreadAllocations(indexContext, writer, stats, IndexingWorkType.Reduce);
            }
            catch (Exception e) when(e.IsIndexError())
            {
                _index.ErrorIndexIfCriticalException(e);

                HandleReductionError(e, reduceKeyHash, writer, stats, updateStats: true, page: null, numberOfNestedValues: numberOfEntriesToReduce);
            }
        }