Exemplo n.º 1
0
 public void PrefetchDocuments()
 {
     /*prefetchDisposable  = new WeakReference<IDisposable>(
         PrefetchingBehavior.DocumentBatchFrom(LastIndexedEtag, out JsonDocs));*/
     prefetchDisposable =
         PrefetchingBehavior.DocumentBatchFrom(LastIndexedEtag, out JsonDocs);
 }
Exemplo n.º 2
0
        protected override void ExecuteIndexingWork(IList <IndexToWorkOn> indexesToWorkOn)
        {
            indexesToWorkOn = context.Configuration.IndexingScheduler.FilterMapIndexes(indexesToWorkOn);

            var lastIndexedEtagForAllIndexes =
                indexesToWorkOn.Min(x => new ComparableByteArray(x.LastIndexedEtag.ToByteArray())).ToEtag();

            context.CancellationToken.ThrowIfCancellationRequested();

            var      operationCancelled = false;
            TimeSpan indexingDuration   = TimeSpan.Zero;
            var      lastEtag           = Etag.Empty;

            indexesToWorkOn.ForEach(x => x.Index.IsMapIndexingInProgress = true);

            List <JsonDocument> jsonDocs;

            using (prefetchingBehavior.DocumentBatchFrom(lastIndexedEtagForAllIndexes, out jsonDocs))
            {
                try
                {
                    if (Log.IsDebugEnabled)
                    {
                        Log.Debug("Found a total of {0} documents that requires indexing since etag: {1}: ({2})",
                                  jsonDocs.Count, lastIndexedEtagForAllIndexes, string.Join(", ", jsonDocs.Select(x => x.Key)));
                    }

                    context.ReportIndexingBatchStarted(jsonDocs.Count, jsonDocs.Sum(x => x.SerializedSizeOnDisk));

                    context.CancellationToken.ThrowIfCancellationRequested();

                    if (jsonDocs.Count <= 0)
                    {
                        return;
                    }

                    var sw = Stopwatch.StartNew();
                    lastEtag         = DoActualIndexing(indexesToWorkOn, jsonDocs);
                    indexingDuration = sw.Elapsed;
                }
                catch (OperationCanceledException)
                {
                    operationCancelled = true;
                }
                finally
                {
                    if (operationCancelled == false && jsonDocs != null && jsonDocs.Count > 0)
                    {
                        prefetchingBehavior.CleanupDocuments(lastEtag);
                        prefetchingBehavior.UpdateAutoThrottler(jsonDocs, indexingDuration);
                    }

                    prefetchingBehavior.BatchProcessingComplete();
                    indexesToWorkOn.ForEach(x => x.Index.IsMapIndexingInProgress = false);
                }
            }
        }