Пример #1
0
        /// <summary>
        /// Selects an asynchronous producer, for
        /// the specified broker id and calls the send API on the selected
        /// producer to publish the data to the specified broker partition.
        /// </summary>
        /// <param name="poolData">The producer pool request object.</param>
        /// <remarks>
        /// Used for multi-topic request
        /// </remarks>
        public override void Send(IEnumerable <ProducerPoolData <TData> > poolData)
        {
            this.EnsuresNotDisposed();
            Guard.NotNull(poolData, "poolData");
            Dictionary <int, List <ProducerPoolData <TData> > > distinctBrokers = poolData.GroupBy(
                x => x.BidPid.BrokerId, x => x)
                                                                                  .ToDictionary(x => x.Key, x => x.ToList());

            foreach (var broker in distinctBrokers)
            {
                Logger.DebugFormat(CultureInfo.CurrentCulture, "Fetching async producer for broker id: {0}", broker.Key);
                IAsyncProducer producer;
                if (!asyncProducers.TryGetValue(broker.Key, out producer))
                {
                    var exception = new IllegalStateException(string.Format("Cannot find broker {0} in async producer collection", broker.Key));
                    exception.Data.Add("brokerId", broker.Key);
                    throw exception;
                }

                IEnumerable <ProducerRequest> requests = broker.Value.Select(x => new ProducerRequest(
                                                                                 x.Topic,
                                                                                 x.BidPid.PartId,
                                                                                 new BufferedMessageSet(x.Data.Select(y => this.Serializer.ToMessage(y)))));
                foreach (var request in requests)
                {
                    producer.Send(request);
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Commits final <see cref="T:byte[]"/>, trimming it if necessary and if <paramref name="trim"/>=true. </summary>
 public Reader Freeze(bool trim)
 {
     if (frozen)
     {
         throw IllegalStateException.Create("already frozen");
     }
     if (didSkipBytes)
     {
         throw IllegalStateException.Create("cannot freeze when Copy(BytesRef, BytesRef) was used");
     }
     if (trim && upto < blockSize)
     {
         var newBlock = new byte[upto];
         Array.Copy(currentBlock, 0, newBlock, 0, upto);
         currentBlock = newBlock;
     }
     if (currentBlock == null)
     {
         currentBlock = EMPTY_BYTES;
     }
     blocks.Add(currentBlock);
     blockEnd.Add(upto);
     frozen       = true;
     currentBlock = null;
     return(new PagedBytes.Reader(this));
 }
Пример #3
0
 /// <summary>
 /// Detect mis-use, where provided parent query in fact sometimes returns child documents.
 /// </summary>
 private void ValidateParentDoc()
 {
     if (_parentDoc != NO_MORE_DOCS && !_parentBits.Get(_parentDoc))
     {
         throw IllegalStateException.Create(INVALID_QUERY_MESSAGE + _parentDoc);
     }
 }
Пример #4
0
        /// <summary>
        /// Call at most <see cref="numValues"/> times to encode a non decreasing sequence of non negative numbers. </summary>
        /// <param name="x"> The next number to be encoded. </param>
        /// <exception cref="InvalidOperationException"> when called more than <see cref="numValues"/> times. </exception>
        /// <exception cref="ArgumentOutOfRangeException"> when:
        ///         <list type="bullet">
        ///         <item><description><paramref name="x"/> is smaller than an earlier encoded value, or</description></item>
        ///         <item><description><paramref name="x"/> is larger than <see cref="upperBound"/>.</description></item>
        ///         </list> </exception>
        public virtual void EncodeNext(long x)
        {
            if (numEncoded >= numValues)
            {
                throw IllegalStateException.Create("EncodeNext() called more than " + numValues + " times.");
            }
            if (lastEncoded > x)
            {
                throw new ArgumentOutOfRangeException(nameof(x), x + " smaller than previous " + lastEncoded); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention)
            }
            if (x > upperBound)
            {
                throw new ArgumentOutOfRangeException(nameof(x), x + " larger than upperBound " + upperBound); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention)
            }
            long highValue = x.TripleShift(numLowBits);

            EncodeUpperBits(highValue);
            EncodeLowerBits(x & lowerBitsMask);
            lastEncoded = x;
            // Add index entries:
            long indexValue = (currentEntryIndex + 1) * indexInterval;

            while (indexValue <= highValue)
            {
                long afterZeroBitPosition = indexValue + numEncoded;
                PackValue(afterZeroBitPosition, upperZeroBitPositionIndex, nIndexEntryBits, currentEntryIndex);
                currentEntryIndex += 1;
                indexValue        += indexInterval;
            }
            numEncoded++;
        }
Пример #5
0
        /// <summary>
        /// Start the update thread with the specified interval in milliseconds. For
        /// debugging purposes, you can optionally set the name to set on
        /// <see cref="ThreadJob.Name"/>. If you pass <c>null</c>, a default name
        /// will be set.
        /// </summary>
        /// <exception cref="InvalidOperationException"> if the thread has already been started </exception>
        public virtual void StartUpdateThread(long intervalInMilliseconds, string threadName)
        {
            UninterruptableMonitor.Enter(syncLock);
            try
            {
                EnsureOpen();
                if (updateThread != null && updateThread.IsAlive)
                {
                    throw IllegalStateException.Create("cannot start an update thread when one is running, must first call 'stopUpdateThread()'");
                }

                threadName   = threadName is null ? INFO_STREAM_COMPONENT : "ReplicationThread-" + threadName;
                updateThread = new ReplicationThread(intervalInMilliseconds, threadName, DoUpdate, HandleUpdateException, updateLock);
                updateThread.Start();
                // we rely on isAlive to return true in isUpdateThreadAlive, assert to be on the safe side
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(updateThread.IsAlive, "updateThread started but not alive?");
                }
            }
            finally
            {
                UninterruptableMonitor.Exit(syncLock);
            }
        }
Пример #6
0
            // NOTE: acceptDocs applies (and is checked) only in the child document space
            public override Scorer GetScorer(AtomicReaderContext readerContext, IBits acceptDocs)
            {
                Scorer parentScorer = _parentWeight.GetScorer(readerContext, null);

                if (parentScorer is null)
                {
                    // No matches
                    return(null);
                }

                // NOTE: we cannot pass acceptDocs here because this
                // will (most likely, justifiably) cause the filter to
                // not return a FixedBitSet but rather a
                // BitsFilteredDocIdSet.  Instead, we filter by
                // acceptDocs when we score:
                DocIdSet parents = _parentsFilter.GetDocIdSet(readerContext, null);

                if (parents is null)
                {
                    // No matches
                    return(null);
                }
                if (!(parents is FixedBitSet))
                {
                    throw IllegalStateException.Create("parentFilter must return FixedBitSet; got " + parents);
                }

                return(new ToChildBlockJoinScorer(this, parentScorer, (FixedBitSet)parents, _doScores, acceptDocs));
            }
Пример #7
0
        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
        {
            IDictionary <string, FunctionValues> valuesCache = (IDictionary <string, FunctionValues>)context["valuesCache"];

            if (valuesCache == null)
            {
                valuesCache = new Dictionary <string, FunctionValues>();
                context     = new Hashtable(context)
                {
                    ["valuesCache"] = valuesCache
                };
            }
            FunctionValues[] externalValues = new FunctionValues[expression.Variables.Length];
            for (int i = 0; i < variables.Length; ++i)
            {
                string externalName = expression.Variables[i];
                if (!valuesCache.TryGetValue(externalName, out FunctionValues values))
                {
                    values = variables[i].GetValues(context, readerContext);
                    if (values == null)
                    {
                        // LUCENENET specific: Changed from RuntimeException to InvalidOperationException to match .NET conventions
#pragma warning disable IDE0016 // Use 'throw' expression
                        throw IllegalStateException.Create($"Internal error. External ({externalName}) does not exist.");
#pragma warning restore IDE0016 // Use 'throw' expression
                    }
                    valuesCache[externalName] = values;
                }
                externalValues[i] = values;
            }
            return(new ExpressionFunctionValues(this, expression, externalValues));
        }
Пример #8
0
        protected abstract void Dispose(bool disposing); // LUCENENET: Refactored from DoClose()

        /// <summary>
        /// Expert: decreases the refCount of this TaxonomyReader instance. If the
        /// refCount drops to 0 this taxonomy reader is closed.
        /// </summary>
        public void DecRef()
        {
            EnsureOpen();
            int rc = refCount.DecrementAndGet();

            if (rc == 0)
            {
                bool success = false;
                try
                {
                    Dispose(true); // LUCENENET specific - changed from DoClose() to Dispose(bool)
                    closed  = true;
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        // Put reference back on failure
                        refCount.IncrementAndGet();
                    }
                }
            }
            else if (rc < 0)
            {
                throw IllegalStateException.Create("too many decRef calls: refCount is " + rc + " after decrement");
            }
        }
Пример #9
0
 private void CheckNotFinished()
 {
     if (m_finished)
     {
         throw IllegalStateException.Create("Already finished");
     }
 }
Пример #10
0
 private void CheckIfFrozen()
 {
     if (frozen)
     {
         throw IllegalStateException.Create("this FieldType is already frozen and cannot be changed");
     }
 }
Пример #11
0
        /// <summary>
        /// Releases resources used by the <see cref="SearcherLifetimeManager"/> and
        /// if overridden in a derived class, optionally releases unmanaged resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources;
        /// <c>false</c> to release only unmanaged resources.</param>

        // LUCENENET specific - implemented proper dispose pattern
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                lock (this)
                {
                    _closed = true;
                    IList <SearcherTracker> toClose = new List <SearcherTracker>(_searchers.Values.Select(item => item.Value));

                    // Remove up front in case exc below, so we don't
                    // over-decRef on double-close:
                    foreach (var tracker in toClose)
                    {
                        _searchers.TryRemove(tracker.Version, out Lazy <SearcherTracker> _);
                    }

                    IOUtils.Dispose(toClose);

                    // Make some effort to catch mis-use:
                    if (_searchers.Count != 0)
                    {
                        throw IllegalStateException.Create("another thread called record while this SearcherLifetimeManager instance was being disposed; not all searchers were disposed");
                    }
                }
            }
        }
Пример #12
0
            /// <summary/>
            /// <exception cref="InvalidOperationException"></exception>
            public virtual void DecRef()
            {
                if (refCount <= 0)
                {
                    throw IllegalStateException.Create("this revision is already released");
                }

                var rc = refCount.DecrementAndGet();

                if (rc == 0)
                {
                    bool success = false;
                    try
                    {
                        Revision.Release();
                        success = true;
                    }
                    finally
                    {
                        if (!success)
                        {
                            // Put reference back on failure
                            refCount.IncrementAndGet();
                        }
                    }
                }
                else if (rc < 0)
                {
                    throw IllegalStateException.Create(string.Format("too many decRef calls: refCount is {0} after decrement", rc));
                }
            }
Пример #13
0
        private void Add(int doc, long?value)  // LUCENENET specific: Marked private instead of public and changed the value parameter type
        {
            // TODO: if the Sorter interface changes to take long indexes, we can remove that limitation
            if (size == int.MaxValue)
            {
                throw IllegalStateException.Create("cannot support more than System.Int32.MaxValue doc/value entries");
            }

            long?val = value;

            if (val == null)
            {
                val = NumericDocValuesUpdate.MISSING;
            }

            // grow the structures to have room for more elements
            if (docs.Count == size)
            {
                docs          = docs.Grow(size + 1);
                values        = values.Grow(size + 1);
                docsWithField = FixedBitSet.EnsureCapacity(docsWithField, (int)docs.Count);
            }

            if (val != NumericDocValuesUpdate.MISSING)
            {
                // only mark the document as having a value in that field if the value wasn't set to null (MISSING)
                docsWithField.Set(size);
            }

            docs.Set(size, doc);
            values.Set(size, val.Value);
            ++size;
        }
Пример #14
0
 private void EnsureIndexIsRead()
 {
     if (index == null)
     {
         throw IllegalStateException.Create("terms index was not loaded when this reader was created");
     }
 }
Пример #15
0
        public override void Merge(DocValuesFieldUpdates other)
        {
            BinaryDocValuesFieldUpdates otherUpdates = (BinaryDocValuesFieldUpdates)other;
            int newSize = size + otherUpdates.size;

            if (newSize > int.MaxValue)
            {
                throw IllegalStateException.Create("cannot support more than System.Int32.MaxValue doc/value entries; size=" + size + " other.size=" + otherUpdates.size);
            }
            docs          = docs.Grow(newSize);
            offsets       = offsets.Grow(newSize);
            lengths       = lengths.Grow(newSize);
            docsWithField = FixedBitSet.EnsureCapacity(docsWithField, (int)docs.Count);
            for (int i = 0; i < otherUpdates.size; i++)
            {
                int doc = (int)otherUpdates.docs.Get(i);
                if (otherUpdates.docsWithField.Get(i))
                {
                    docsWithField.Set(size);
                }
                docs.Set(size, doc);
                offsets.Set(size, values.Length + otherUpdates.offsets.Get(i)); // correct relative offset
                lengths.Set(size, otherUpdates.lengths.Get(i));
                ++size;
            }
            values.Append(otherUpdates.values);
        }
Пример #16
0
        /// <summary>
        /// USed to get the versioned operation response. It contains version information of the data in the server.
        /// </summary>
        /// <param name="transport"></param>
        /// <param name="param"></param>
        /// <returns>Version data on the entry picked</returns>
        protected VersionedOperationResponse returnVersionedOperationResponse(Transport transport, HeaderParams param)
        {
            byte respStatus = readHeaderAndValidate(transport, param);

            if (logger.IsTraceEnabled)
            {
                logger.Trace("Read response status : " + respStatus);
            }
            VersionedOperationResponse.RspCode code;
            if (respStatus == NO_ERROR_STATUS)
            {
                code = VersionedOperationResponse.RspCode.SUCCESS;
            }
            else if (respStatus == NOT_PUT_REMOVED_REPLACED_STATUS)
            {
                code = VersionedOperationResponse.RspCode.MODIFIED_KEY;
            }
            else if (respStatus == KEY_DOES_NOT_EXIST_STATUS)
            {
                code = VersionedOperationResponse.RspCode.NO_SUCH_KEY;
            }
            else
            {
                IllegalStateException e = new IllegalStateException("Unknown response status: " + respStatus);
                logger.Warn(e);
                throw e;
            }
            byte[] prevValue = returnPossiblePrevValue(transport);
            return(new VersionedOperationResponse(prevValue, code));
        }
Пример #17
0
        /// <summary>
        /// Decrements the reference counting of this object. When reference counting
        /// hits 0, calls <see cref="Release()"/>.
        /// </summary>
        public void DecRef()
        {
            int rc = refCount.DecrementAndGet();

            if (rc == 0)
            {
                bool success = false;
                try
                {
                    Release();
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        // Put reference back on failure
                        refCount.IncrementAndGet();
                    }
                }
            }
            else if (rc < 0)
            {
                throw IllegalStateException.Create("too many DecRef() calls: refCount is " + rc + " after decrement");
            }
        }
Пример #18
0
        /// <summary>
        /// This method is called every time a child is processed.
        /// </summary>
        /// <param name="queryTree">the query node child to be processed</param>
        /// <exception cref="QueryNodeException">if something goes wrong during the query node processing</exception>
        protected virtual void ProcessChildren(IQueryNode queryTree)
        {
            IList <IQueryNode> children = queryTree.GetChildren();
            ChildrenList       newChildren;

            if (children != null && children.Count > 0)
            {
                newChildren = AllocateChildrenList();

                try
                {
                    foreach (IQueryNode child in children)
                    {
                        var child2 = ProcessIteration(child);

                        if (child2 == null)
                        {
                            // LUCENENET: Changed from NullPointerException to InvalidOperationException (which isn't caught anywhere outside of tests)
                            throw IllegalStateException.Create($"{this.GetType().Name}.PostProcessNode() must not return 'null'.");
                        }

                        newChildren.Add(child2);
                    }

                    IList <IQueryNode> orderedChildrenList = SetChildrenOrder(newChildren);

                    queryTree.Set(orderedChildrenList);
                }
                finally
                {
                    newChildren.beingUsed = false;
                }
            }
        }
Пример #19
0
        /// <summary>
        /// Release a snapshot by generation. </summary>
        protected internal virtual void ReleaseGen(long gen)
        {
            if (!initCalled)
            {
                throw IllegalStateException.Create("this instance is not being used by IndexWriter; be sure to use the instance returned from writer.Config.IndexDeletionPolicy");
            }
            int?refCount = m_refCounts[gen];

            if (refCount == null)
            {
                throw new ArgumentException("commit gen=" + gen + " is not currently snapshotted");
            }
            int refCountInt = (int)refCount;

            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(refCountInt > 0);
            }
            refCountInt--;
            if (refCountInt == 0)
            {
                m_refCounts.Remove(gen);
                m_indexCommits.Remove(gen);
            }
            else
            {
                m_refCounts[gen] = refCountInt;
            }
        }
Пример #20
0
        protected override SearcherAndTaxonomy RefreshIfNeeded(SearcherAndTaxonomy @ref)
        {
            // Must re-open searcher first, otherwise we may get a
            // new reader that references ords not yet known to the
            // taxonomy reader:
            IndexReader r         = @ref.Searcher.IndexReader;
            IndexReader newReader = DirectoryReader.OpenIfChanged((DirectoryReader)r);

            if (newReader == null)
            {
                return(null);
            }
            else
            {
                var tr = TaxonomyReader.OpenIfChanged(@ref.TaxonomyReader);
                if (tr == null)
                {
                    @ref.TaxonomyReader.IncRef();
                    tr = @ref.TaxonomyReader;
                }
                else if (taxoWriter != null && taxoWriter.TaxonomyEpoch != taxoEpoch)
                {
                    IOUtils.Dispose(newReader, tr);
                    throw IllegalStateException.Create("DirectoryTaxonomyWriter.ReplaceTaxonomy() was called, which is not allowed when using SearcherTaxonomyManager");
                }

                return(new SearcherAndTaxonomy(SearcherManager.GetSearcher(searcherFactory, newReader), tr));
            }
        }
Пример #21
0
            public override bool IncrementToken()
            {
                if (str == null)
                {
                    throw IllegalStateException.Create("Consumer did not call Reset().");
                }
                ClearAttributes();
                // cache loop instance vars (performance)
                string s      = str;
                int    len    = s.Length;
                int    i      = pos;
                bool   letter = isLetter;

                int    start = 0;
                string text;

                do
                {
                    // find beginning of token
                    text = null;
                    while (i < len && !IsTokenChar(s[i], letter))
                    {
                        i++;
                    }

                    if (i < len) // found beginning; now find end of token
                    {
                        start = i;
                        while (i < len && IsTokenChar(s[i], letter))
                        {
                            i++;
                        }

                        text = s.Substring(start, i - start);
                        if (toLowerCase)
                        {
                            text = text.ToLower(); // LUCENENET: Since this class is obsolete, we aren't going to bother with passing culture in the constructor.
                        }
                        //          if (toLowerCase) {
                        ////            use next line once JDK 1.5 String.toLowerCase() performance regression is fixed
                        ////            see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6265809
                        //            text = s.substring(start, i).toLowerCase();
                        ////            char[] chars = new char[i-start];
                        ////            for (int j=start; j < i; j++) chars[j-start] = Character.toLowerCase(s.charAt(j));
                        ////            text = new String(chars);
                        //          } else {
                        //            text = s.substring(start, i);
                        //          }
                    }
                } while (text != null && IsStopWord(text));

                pos = i;
                if (text == null)
                {
                    return(false);
                }
                termAtt.SetEmpty().Append(text);
                offsetAtt.SetOffset(CorrectOffset(start), CorrectOffset(i));
                return(true);
            }
Пример #22
0
            public override int NextPosition()
            {
                if (doc != 0)
                {
                    throw IllegalStateException.Create();
                }
                else if (i >= termFreq - 1)
                {
                    throw IllegalStateException.Create("Read past last position");
                }

                ++i;

                if (payloadIndex != null)
                {
                    payload.Offset = basePayloadOffset + payloadIndex[positionIndex + i];
                    payload.Length = payloadIndex[positionIndex + i + 1] - payloadIndex[positionIndex + i];
                }

                if (positions == null)
                {
                    return(-1);
                }
                else
                {
                    return(positions[positionIndex + i]);
                }
            }
Пример #23
0
        public override Spans GetSpans(AtomicReaderContext context, IBits acceptDocs, IDictionary <Term, TermContext> termContexts)
        {
            TermState state;

            if (!termContexts.TryGetValue(m_term, out TermContext termContext) || termContext == null)
            {
                // this happens with span-not query, as it doesn't include the NOT side in extractTerms()
                // so we seek to the term now in this segment..., this sucks because its ugly mostly!
                Fields fields = context.AtomicReader.Fields;
                if (fields != null)
                {
                    Terms terms = fields.GetTerms(m_term.Field);
                    if (terms != null)
                    {
                        TermsEnum termsEnum = terms.GetEnumerator();
                        if (termsEnum.SeekExact(m_term.Bytes))
                        {
                            state = termsEnum.GetTermState();
                        }
                        else
                        {
                            state = null;
                        }
                    }
                    else
                    {
                        state = null;
                    }
                }
                else
                {
                    state = null;
                }
            }
            else
            {
                state = termContext.Get(context.Ord);
            }

            if (state == null) // term is not present in that reader
            {
                return(TermSpans.EMPTY_TERM_SPANS);
            }

            TermsEnum termsEnum_ = context.AtomicReader.GetTerms(m_term.Field).GetEnumerator();

            termsEnum_.SeekExact(m_term.Bytes, state);

            DocsAndPositionsEnum postings = termsEnum_.DocsAndPositions(acceptDocs, null, DocsAndPositionsFlags.PAYLOADS);

            if (postings != null)
            {
                return(new TermSpans(postings, m_term));
            }
            else
            {
                // term does exist, but has no positions
                throw IllegalStateException.Create("field \"" + m_term.Field + "\" was indexed without position data; cannot run SpanTermQuery (term=" + m_term.Text + ")");
            }
        }
Пример #24
0
            public override int NextPosition()
            {
                //if (Debugging.AssertsEnabled) Debugging.Assert((positions != null && nextPos < positions.Length) || startOffsets != null && nextPos < startOffsets.Length);

                // LUCENENET: The above assertion was for control flow when testing. In Java, it would throw an AssertionError, which is
                // caught by the BaseTermVectorsFormatTestCase.assertEquals(RandomTokenStream tk, FieldType ft, Terms terms) method in the
                // part that is checking for an error after reading to the end of the enumerator.

                // In .NET it is more natural to throw an InvalidOperationException in this case, since we would potentially get an
                // IndexOutOfRangeException if we didn't, which doesn't really provide good feedback as to what the cause is.
                // This matches the behavior of Lucene 8.x. See #267.
                if (((positions != null && nextPos < positions.Length) || startOffsets != null && nextPos < startOffsets.Length) == false)
                {
                    throw IllegalStateException.Create("Read past last position");
                }

                if (positions != null)
                {
                    return(positions[nextPos++]);
                }
                else
                {
                    nextPos++;
                    return(-1);
                }
            }
Пример #25
0
        public UnionDocsAndPositionsEnum(IBits liveDocs, AtomicReaderContext context, Term[] terms, IDictionary <Term, TermContext> termContexts, TermsEnum termsEnum)
        {
            ICollection <DocsAndPositionsEnum> docsEnums = new LinkedList <DocsAndPositionsEnum>();

            for (int i = 0; i < terms.Length; i++)
            {
                Term      term      = terms[i];
                TermState termState = termContexts[term].Get(context.Ord);
                if (termState is null)
                {
                    // Term doesn't exist in reader
                    continue;
                }
                termsEnum.SeekExact(term.Bytes, termState);
                DocsAndPositionsEnum postings = termsEnum.DocsAndPositions(liveDocs, null, DocsAndPositionsFlags.NONE);
                if (postings is null)
                {
                    // term does exist, but has no positions
                    throw IllegalStateException.Create("field \"" + term.Field + "\" was indexed without position data; cannot run PhraseQuery (term=" + term.Text + ")");
                }
                _cost += postings.GetCost();
                docsEnums.Add(postings);
            }

            _queue   = new DocsQueue(docsEnums);
            _posList = new Int32Queue();
        }
        /// <summary>
        /// Constructor with the given index directory and callback to notify when the indexes were updated.
        /// </summary>
        /// <exception cref="IOException"></exception>
        public IndexAndTaxonomyReplicationHandler(Directory indexDirectory, Directory taxonomyDirectory, Func <bool?> callback)
        {
            this.indexDirectory    = indexDirectory;
            this.taxonomyDirectory = taxonomyDirectory;
            this.callback          = callback;

            currentVersion       = null;
            currentRevisionFiles = null;

            bool indexExists    = DirectoryReader.IndexExists(indexDirectory);
            bool taxonomyExists = DirectoryReader.IndexExists(taxonomyDirectory);

            if (indexExists != taxonomyExists)
            {
                throw IllegalStateException.Create(string.Format("search and taxonomy indexes must either both exist or not: index={0} taxo={1}", indexExists, taxonomyExists));
            }

            if (indexExists)
            {
                IndexCommit indexCommit    = IndexReplicationHandler.GetLastCommit(indexDirectory);
                IndexCommit taxonomyCommit = IndexReplicationHandler.GetLastCommit(taxonomyDirectory);

                currentRevisionFiles = IndexAndTaxonomyRevision.RevisionFiles(indexCommit, taxonomyCommit);
                currentVersion       = IndexAndTaxonomyRevision.RevisionVersion(indexCommit, taxonomyCommit);

                WriteToInfoStream(
                    string.Format("constructor(): currentVersion={0} currentRevisionFiles={1}", currentVersion, currentRevisionFiles),
                    string.Format("constructor(): indexCommit={0} taxoCommit={1}", indexCommit, taxonomyCommit));
            }
        }
Пример #27
0
        /// <summary>
        /// Add data from another stat, for aggregation.
        /// </summary>
        /// <param name="stat2">The added stat data.</param>
        public virtual void Add(TaskStats stat2)
        {
            numRuns    += stat2.NumRuns;
            elapsed    += stat2.Elapsed;
            maxTotMem  += stat2.MaxTotMem;
            maxUsedMem += stat2.MaxUsedMem;
            count      += stat2.Count;
            if (round != stat2.round)
            {
                round = -1; // no meaning if aggregating tasks of different round.
            }

            if (countsByTime != null && stat2.countsByTime != null)
            {
                if (countsByTimeStepMSec != stat2.countsByTimeStepMSec)
                {
                    throw IllegalStateException.Create("different by-time msec step");
                }
                if (countsByTime.Length != stat2.countsByTime.Length)
                {
                    throw IllegalStateException.Create("different by-time msec count");
                }
                for (int i = 0; i < stat2.countsByTime.Length; i++)
                {
                    countsByTime[i] += stat2.countsByTime[i];
                }
            }
        }
Пример #28
0
        public override void Merge(DocValuesFieldUpdates other)
        {
            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(other is NumericDocValuesFieldUpdates);
            }
            NumericDocValuesFieldUpdates otherUpdates = (NumericDocValuesFieldUpdates)other;

            if (size + otherUpdates.size > int.MaxValue)
            {
                throw IllegalStateException.Create("cannot support more than System.Int32.MaxValue doc/value entries; size=" + size + " other.size=" + otherUpdates.size);
            }
            docs          = docs.Grow(size + otherUpdates.size);
            values        = values.Grow(size + otherUpdates.size);
            docsWithField = FixedBitSet.EnsureCapacity(docsWithField, (int)docs.Count);
            for (int i = 0; i < otherUpdates.size; i++)
            {
                int doc = (int)otherUpdates.docs.Get(i);
                if (otherUpdates.docsWithField.Get(i))
                {
                    docsWithField.Set(size);
                }
                docs.Set(size, doc);
                values.Set(size, otherUpdates.values.Get(i));
                ++size;
            }
        }
Пример #29
0
 public override void Run()
 {
     foreach (int q in queries)
     {
         Query query = new TermQuery(new Term("fld", "" + q));
         try
         {
             TopDocs topDocs = searcher.Search(query, 1);
             if (topDocs.TotalHits != 1)
             {
                 Console.WriteLine(query);
                 throw IllegalStateException.Create("Expected 1 hit, got " + topDocs.TotalHits);
             }
             Document sdoc = rd.Document(topDocs.ScoreDocs[0].Doc);
             if (sdoc is null || sdoc.Get("fld") is null)
             {
                 throw IllegalStateException.Create("Could not find document " + q);
             }
             if (!Convert.ToString(q, CultureInfo.InvariantCulture).Equals(sdoc.Get("fld"), StringComparison.Ordinal))
             {
                 throw IllegalStateException.Create("Expected " + q + ", but got " + sdoc.Get("fld"));
             }
         }
         catch (Exception e) when(e.IsException())
         {
             ex.CompareAndSet(null, e);
         }
     }
 }
            /// <summary>
            /// Called initially, and whenever <see cref="Visit(Lucene.Net.Spatial.Prefix.Tree.Cell)"/>
            /// returns true.
            /// </summary>
            /// <exception cref="IOException"></exception>
            private void AddIntersectingChildren()
            {
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(thisTerm != null);
                }
                Cell cell = curVNode.cell;

                if (cell.Level >= m_outerInstance.m_detailLevel)
                {
                    throw IllegalStateException.Create("Spatial logic error");
                }
                //Check for adjacent leaf (happens for indexed non-point shapes)
                if (m_hasIndexedLeaves && cell.Level != 0)
                {
                    //If the next indexed term just adds a leaf marker ('+') to cell,
                    // then add all of those docs
                    if (Debugging.AssertsEnabled)
                    {
                        Debugging.Assert(StringHelper.StartsWith(thisTerm, curVNodeTerm));                          //TODO refactor to use method on curVNode.cell
                    }
                    scanCell = m_outerInstance.m_grid.GetCell(thisTerm.Bytes, thisTerm.Offset, thisTerm.Length, scanCell);
                    if (scanCell.Level == cell.Level && scanCell.IsLeaf)
                    {
                        VisitLeaf(scanCell);
                        //advance
                        if (!m_termsEnum.MoveNext())
                        {
                            return;// all done
                        }
                        thisTerm = m_termsEnum.Term;
                    }
                }

                //Decide whether to continue to divide & conquer, or whether it's time to
                // scan through terms beneath this cell.
                // Scanning is a performance optimization trade-off.

                //TODO use termsEnum.docFreq() as heuristic
                bool scan = cell.Level >= ((AbstractVisitingPrefixTreeFilter)m_outerInstance).m_prefixGridScanLevel;//simple heuristic

                if (!scan)
                {
                    //Divide & conquer (ultimately termsEnum.seek())

                    IEnumerator <Cell> subCellsIter = FindSubCellsToVisit(cell);
                    if (!subCellsIter.MoveNext())
                    {
                        return;//not expected
                    }
                    curVNode.children = new VNodeCellIterator(subCellsIter, new VNode(curVNode));
                }
                else
                {
                    //Scan (loop of termsEnum.next())

                    Scan(m_outerInstance.m_detailLevel);
                }
            }