private bool TryGetDocumentsFromQueue(Etag nextDocEtag, ref List <JsonDocument> items) { JsonDocument result; nextDocEtag = HandleEtagGapsIfNeeded(nextDocEtag); bool hasDocs = false; while (items.Count < autoTuner.NumberOfItemsToIndexInSingleBatch && prefetchingQueue.TryPeek(out result) && nextDocEtag.CompareTo(result.Etag) >= 0) { // safe to do peek then dequeue because we are the only one doing the dequeues // and here we are single threaded prefetchingQueue.TryDequeue(out result); if (result.Etag != nextDocEtag) { continue; } items.Add(result); hasDocs = true; nextDocEtag = EtagUtil.Increment(nextDocEtag, 1); nextDocEtag = HandleEtagGapsIfNeeded(nextDocEtag); } return(hasDocs); }
private bool TryGetDocumentsFromQueue(Etag nextDocEtag, List <JsonDocument> items, int?take) { JsonDocument result; nextDocEtag = HandleEtagGapsIfNeeded(nextDocEtag); bool hasDocs = false; while (items.Count < autoTuner.NumberOfItemsToProcessInSingleBatch && prefetchingQueue.TryPeek(out result) && // we compare to current or _smaller_ so we will remove from the queue old versions // of documents that we have already loaded nextDocEtag.CompareTo(result.Etag) >= 0) { // safe to do peek then dequeue because we are the only one doing the dequeues // and here we are single threaded, but still, better to check if (prefetchingQueue.TryDequeue(out result) == false) { continue; } // this shouldn't happen, but... if (result == null) { continue; } if (result.Etag != nextDocEtag) { continue; } items.Add(result); hasDocs = true; if (take.HasValue && items.Count >= take.Value) { break; } nextDocEtag = Abstractions.Util.EtagUtil.Increment(nextDocEtag, 1); nextDocEtag = HandleEtagGapsIfNeeded(nextDocEtag); } return(hasDocs); }
private bool TryGetDocumentsFromQueue(Etag nextDocEtag, ref List <JsonDocument> items) { JsonDocument result; nextDocEtag = HandleEtagGapsIfNeeded(nextDocEtag); bool hasDocs = false; while (items.Count < autoTuner.NumberOfItemsToIndexInSingleBatch && prefetchingQueue.TryPeek(out result) && nextDocEtag.CompareTo(result.Etag) >= 0) { // safe to do peek then dequeue because we are the only one doing the dequeues // and here we are single threaded, but still, better to check if (prefetchingQueue.TryDequeue(out result) == false) { continue; } // this shouldn't happen, but... if (result == null) { continue; } if (result.Etag != nextDocEtag) { continue; } items.Add(result); hasDocs = true; nextDocEtag = Abstractions.Util.EtagUtil.Increment(nextDocEtag, 1); nextDocEtag = HandleEtagGapsIfNeeded(nextDocEtag); } return(hasDocs); }