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.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 Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicBoolean
closed
private java.util.function.LongSupplier
completedDelGenSupplier
private Directory
directory
private FieldInfos.FieldNumbers
fieldNumbers
private InfoStream
infoStream
private Directory
originalDirectory
private boolean
poolReaders
private java.util.Map<SegmentCommitInfo,ReadersAndUpdates>
readerMap
private SegmentInfos
segmentInfos
private java.lang.String
softDeletesField
-
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) boolean
anyDeletions()
Returnstrue
iff any of the buffered readers and updates has at least one pending delete(package private) boolean
anyDocValuesChanges()
Returnstrue
iff there are any buffered doc values updates.(package private) boolean
assertInfoIsLive(SegmentCommitInfo info)
Asserts this info still exists in IW's segment infosvoid
close()
(package private) boolean
commit(SegmentInfos infos)
Commit live docs changes for the segment readers for the provided infos.(package private) boolean
drop(SegmentCommitInfo info)
Drops reader for the givenSegmentCommitInfo
if it's pooled(package private) void
dropAll()
Remove all our references to readers, and commits any pending changes.(package private) void
enableReaderPooling()
Enables reader pooling for this pool.(package private) ReadersAndUpdates
get(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) boolean
isReaderPoolingEnabled()
private PendingDeletes
newPendingDeletes(SegmentCommitInfo info)
private PendingDeletes
newPendingDeletes(SegmentReader reader, SegmentCommitInfo info)
private boolean
noDups()
(package private) long
ramBytesUsed()
Returns the sum of the ram used by all the buffered readers and updates in MB(package private) boolean
release(ReadersAndUpdates rld, boolean assertInfoLive)
Releases theReadersAndUpdates
.(package private) boolean
writeAllDocValuesUpdates()
Writes all doc values updates to disk if there are any.(package private) boolean
writeDocValuesUpdatesForMerge(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 givenSegmentCommitInfo
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()
Returnstrue
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 aReadersAndUpdates
will 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:
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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.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()
Returnstrue
iff 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()
-
-