Class ReaderPool

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    final class ReaderPool
    extends java.lang.Object
    implements java.io.Closeable
    Holds shared SegmentReader instances. IndexWriter uses SegmentReaders for 1) applying deletes/DV updates, 2) doing merges, 3) handing out a real-time reader. This pool reuses instances of the SegmentReaders in all these places if it is in "near real-time mode" (getReader() has been called on this instance).
    • Field Detail

      • directory

        private final Directory directory
      • originalDirectory

        private final Directory originalDirectory
      • completedDelGenSupplier

        private final java.util.function.LongSupplier completedDelGenSupplier
      • softDeletesField

        private final java.lang.String softDeletesField
      • poolReaders

        private volatile boolean poolReaders
      • closed

        private final java.util.concurrent.atomic.AtomicBoolean closed
    • Method Detail

      • assertInfoIsLive

        boolean assertInfoIsLive​(SegmentCommitInfo info)
        Asserts this info still exists in IW's segment infos
      • drop

        boolean drop​(SegmentCommitInfo info)
              throws java.io.IOException
        Drops reader for the given SegmentCommitInfo if it's pooled
        Returns:
        true if a reader is pooled
        Throws:
        java.io.IOException
      • ramBytesUsed

        long ramBytesUsed()
        Returns the sum of the ram used by all the buffered readers and updates in MB
      • anyDeletions

        boolean anyDeletions()
        Returns true iff any of the buffered readers and updates has at least one pending delete
      • enableReaderPooling

        void enableReaderPooling()
        Enables reader pooling for this pool. This should be called once the readers in this pool are shared with an outside resource like an NRT reader. Once reader pooling is enabled a ReadersAndUpdates will be kept around in the reader pool on calling release(ReadersAndUpdates, boolean) until the segment get dropped via calls to drop(SegmentCommitInfo) or dropAll() or close(). Reader pooling is disabled upon construction but can't be disabled again once it's enabled.
      • isReaderPoolingEnabled

        boolean isReaderPoolingEnabled()
      • release

        boolean release​(ReadersAndUpdates rld,
                        boolean assertInfoLive)
                 throws java.io.IOException
        Releases the ReadersAndUpdates. This should only be called if the get(SegmentCommitInfo, boolean) is called with the create paramter set to true.
        Returns:
        true if any files were written by this release call.
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • writeAllDocValuesUpdates

        boolean writeAllDocValuesUpdates()
                                  throws java.io.IOException
        Writes all doc values updates to disk if there are any.
        Returns:
        true iff any files where written
        Throws:
        java.io.IOException
      • writeDocValuesUpdatesForMerge

        boolean writeDocValuesUpdatesForMerge​(java.util.List<SegmentCommitInfo> infos)
                                       throws java.io.IOException
        Writes all doc values updates to disk if there are any.
        Returns:
        true iff any files where written
        Throws:
        java.io.IOException
      • getReadersByRam

        java.util.List<ReadersAndUpdates> getReadersByRam()
        Returns a list of all currently maintained ReadersAndUpdates sorted by it's ram consumption largest to smallest. This list can also contain readers that don't consume any ram at this point ie. don't have any updates buffered.
      • dropAll

        void dropAll()
              throws java.io.IOException
        Remove all our references to readers, and commits any pending changes.
        Throws:
        java.io.IOException
      • commit

        boolean commit​(SegmentInfos infos)
                throws java.io.IOException
        Commit live docs changes for the segment readers for the provided infos.
        Throws:
        java.io.IOException - If there is a low-level I/O error
      • anyDocValuesChanges

        boolean anyDocValuesChanges()
        Returns true iff there are any buffered doc values updates. Otherwise false.
      • noDups

        private boolean noDups()