Package org.apache.lucene.index
Class ReaderPool
- java.lang.Object
-
- org.apache.lucene.index.ReaderPool
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
final class ReaderPool extends java.lang.Object implements java.io.CloseableHolds 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 Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicBooleanclosedprivate java.util.function.LongSuppliercompletedDelGenSupplierprivate Directorydirectoryprivate FieldInfos.FieldNumbersfieldNumbersprivate InfoStreaminfoStreamprivate DirectoryoriginalDirectoryprivate booleanpoolReadersprivate java.util.Map<SegmentCommitInfo,ReadersAndUpdates>readerMapprivate SegmentInfossegmentInfosprivate java.lang.StringsoftDeletesField
-
Constructor Summary
Constructors Constructor Description ReaderPool(Directory directory, Directory originalDirectory, SegmentInfos segmentInfos, FieldInfos.FieldNumbers fieldNumbers, java.util.function.LongSupplier completedDelGenSupplier, InfoStream infoStream, java.lang.String softDeletesField, StandardDirectoryReader reader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) booleananyDeletions()Returnstrueiff any of the buffered readers and updates has at least one pending delete(package private) booleananyDocValuesChanges()Returnstrueiff there are any buffered doc values updates.(package private) booleanassertInfoIsLive(SegmentCommitInfo info)Asserts this info still exists in IW's segment infosvoidclose()(package private) booleancommit(SegmentInfos infos)Commit live docs changes for the segment readers for the provided infos.(package private) booleandrop(SegmentCommitInfo info)Drops reader for the givenSegmentCommitInfoif it's pooled(package private) voiddropAll()Remove all our references to readers, and commits any pending changes.(package private) voidenableReaderPooling()Enables reader pooling for this pool.(package private) ReadersAndUpdatesget(SegmentCommitInfo info, boolean create)Obtain a ReadersAndLiveDocs instance from the readerPool.(package private) java.util.List<ReadersAndUpdates>getReadersByRam()Returns a list of all currently maintained ReadersAndUpdates sorted by it's ram consumption largest to smallest.(package private) booleanisReaderPoolingEnabled()private PendingDeletesnewPendingDeletes(SegmentCommitInfo info)private PendingDeletesnewPendingDeletes(SegmentReader reader, SegmentCommitInfo info)private booleannoDups()(package private) longramBytesUsed()Returns the sum of the ram used by all the buffered readers and updates in MB(package private) booleanrelease(ReadersAndUpdates rld, boolean assertInfoLive)Releases theReadersAndUpdates.(package private) booleanwriteAllDocValuesUpdates()Writes all doc values updates to disk if there are any.(package private) booleanwriteDocValuesUpdatesForMerge(java.util.List<SegmentCommitInfo> infos)Writes all doc values updates to disk if there are any.
-
-
-
Field Detail
-
readerMap
private final java.util.Map<SegmentCommitInfo,ReadersAndUpdates> readerMap
-
directory
private final Directory directory
-
originalDirectory
private final Directory originalDirectory
-
fieldNumbers
private final FieldInfos.FieldNumbers fieldNumbers
-
completedDelGenSupplier
private final java.util.function.LongSupplier completedDelGenSupplier
-
infoStream
private final InfoStream infoStream
-
segmentInfos
private final SegmentInfos segmentInfos
-
softDeletesField
private final java.lang.String softDeletesField
-
poolReaders
private volatile boolean poolReaders
-
closed
private final java.util.concurrent.atomic.AtomicBoolean closed
-
-
Constructor Detail
-
ReaderPool
ReaderPool(Directory directory, Directory originalDirectory, SegmentInfos segmentInfos, FieldInfos.FieldNumbers fieldNumbers, java.util.function.LongSupplier completedDelGenSupplier, InfoStream infoStream, java.lang.String softDeletesField, StandardDirectoryReader reader) throws java.io.IOException
- Throws:
java.io.IOException
-
-
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 givenSegmentCommitInfoif it's pooled- Returns:
trueif 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()
Returnstrueiff 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 aReadersAndUpdateswill be kept around in the reader pool on callingrelease(ReadersAndUpdates, boolean)until the segment get dropped via calls todrop(SegmentCommitInfo)ordropAll()orclose(). 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 theReadersAndUpdates. This should only be called if theget(SegmentCommitInfo, boolean)is called with the create paramter set to true.- Returns:
trueif any files were written by this release call.- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
writeAllDocValuesUpdates
boolean writeAllDocValuesUpdates() throws java.io.IOExceptionWrites all doc values updates to disk if there are any.- Returns:
trueiff 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:
trueiff 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.IOExceptionRemove 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()
Returnstrueiff there are any buffered doc values updates. Otherwisefalse.
-
get
ReadersAndUpdates get(SegmentCommitInfo info, boolean create)
Obtain a ReadersAndLiveDocs instance from the readerPool. If create is true, you must later callrelease(ReadersAndUpdates, boolean).
-
newPendingDeletes
private PendingDeletes newPendingDeletes(SegmentCommitInfo info)
-
newPendingDeletes
private PendingDeletes newPendingDeletes(SegmentReader reader, SegmentCommitInfo info)
-
noDups
private boolean noDups()
-
-