- java.lang.Object
-
- org.apache.lucene.index.DocumentsWriterPerThread
-
- All Implemented Interfaces:
java.util.concurrent.locks.Lock
,Accountable
final class DocumentsWriterPerThread extends java.lang.Object implements Accountable, java.util.concurrent.locks.Lock
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
DocumentsWriterPerThread.FlushedSegment
-
Field Summary
Fields Modifier and Type Field Description private boolean
aborted
private java.lang.Throwable
abortingException
(package private) Codec
codec
private int[]
deleteDocIDs
(package private) DocumentsWriterDeleteQueue
deleteQueue
private DocumentsWriterDeleteQueue.DeleteSlice
deleteSlice
(package private) TrackingDirectoryWrapper
directory
private boolean
enableTestPoints
private FieldInfos.Builder
fieldInfos
private java.util.Set<java.lang.String>
filesToDelete
private SetOnce<java.lang.Boolean>
flushPending
private SetOnce<java.lang.Boolean>
hasFlushed
private IndexingChain
indexingChain
private LiveIndexWriterConfig
indexWriterConfig
private static boolean
INFO_VERBOSE
private InfoStream
infoStream
private long
lastCommittedBytesUsed
private java.util.concurrent.locks.ReentrantLock
lock
private java.text.NumberFormat
nf
private int
numDeletedDocIds
private int
numDocsInRAM
private IndexingChain.ReservedField<NumericDocValuesField>
parentField
private java.util.concurrent.atomic.AtomicLong
pendingNumDocs
private BufferedUpdates
pendingUpdates
private SegmentInfo
segmentInfo
-
Fields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE
-
-
Constructor Summary
Constructors Constructor Description DocumentsWriterPerThread(int indexMajorVersionCreated, java.lang.String segmentName, Directory directoryOrig, Directory directory, LiveIndexWriterConfig indexWriterConfig, DocumentsWriterDeleteQueue deleteQueue, FieldInfos.Builder fieldInfos, java.util.concurrent.atomic.AtomicLong pendingNumDocs, boolean enableTestPoints)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
abort()
Called if we hit an exception at a bad time (when updating the index files) and must discard all currently buffered docs.private java.lang.Iterable<? extends IndexableField>
addParentField(java.lang.Iterable<? extends IndexableField> doc, IndexableField parentField)
(package private) void
commitLastBytesUsed(long delta)
Commits the currentramBytesUsed()
and stores it's value for later reuse.private void
deleteLastDocs(int docCount)
private long
finishDocuments(DocumentsWriterDeleteQueue.Node<?> deleteNode, int docIdUpTo)
(package private) DocumentsWriterPerThread.FlushedSegment
flush(DocumentsWriter.FlushNotifications flushNotifications)
Flush all pending docs to a new segmentjava.util.Collection<Accountable>
getChildResources()
Returns nested resources of this class.(package private) long
getCommitLastBytesUsedDelta()
Calculates the delta between the last committed bytes used and the currently used ram.(package private) long
getLastCommittedBytesUsed()
Returns the last committed bytes for this DWPT.int
getNumDocsInRAM()
Returns the number of RAM resident documents in thisDocumentsWriterPerThread
(package private) SegmentInfo
getSegmentInfo()
Get current segment info we are writing.(package private) boolean
hasFlushed()
Returnstrue
iff this DWPT has been flushed(package private) boolean
isAborted()
(package private) boolean
isFlushPending()
Returns true iff this DWPT is marked as flush pending(package private) boolean
isHeldByCurrentThread()
Returns true if the DWPT's lock is held by the current threadvoid
lock()
void
lockInterruptibly()
private void
maybeAbort(java.lang.String location, DocumentsWriter.FlushNotifications flushNotifications)
java.util.concurrent.locks.Condition
newCondition()
private void
onAbortingException(java.lang.Throwable throwable)
(package private) java.util.Set<java.lang.String>
pendingFilesToDelete()
(package private) FrozenBufferedUpdates
prepareFlush()
Prepares this DWPT for flushing.long
ramBytesUsed()
Return the memory usage of this object in bytes.private void
reserveOneDoc()
Anything that will add N docs to the index should reserve first to make sure it's allowed.(package private) void
sealFlushedSegment(DocumentsWriterPerThread.FlushedSegment flushedSegment, Sorter.DocMap sortMap, DocumentsWriter.FlushNotifications flushNotifications)
Seals theSegmentInfo
for the new flushed segment and persists the deleted documentsFixedBitSet
.(package private) void
setFlushPending()
Sets this DWPT as flush pending.private FixedBitSet
sortLiveDocs(Bits liveDocs, Sorter.DocMap sortMap)
(package private) void
testPoint(java.lang.String message)
java.lang.String
toString()
boolean
tryLock()
boolean
tryLock(long time, java.util.concurrent.TimeUnit unit)
void
unlock()
(package private) long
updateDocuments(java.lang.Iterable<? extends java.lang.Iterable<? extends IndexableField>> docs, DocumentsWriterDeleteQueue.Node<?> deleteNode, DocumentsWriter.FlushNotifications flushNotifications, java.lang.Runnable onNewDocOnRAM)
-
-
-
Field Detail
-
abortingException
private java.lang.Throwable abortingException
-
INFO_VERBOSE
private static final boolean INFO_VERBOSE
- See Also:
- Constant Field Values
-
codec
final Codec codec
-
directory
final TrackingDirectoryWrapper directory
-
indexingChain
private final IndexingChain indexingChain
-
pendingUpdates
private final BufferedUpdates pendingUpdates
-
segmentInfo
private final SegmentInfo segmentInfo
-
aborted
private boolean aborted
-
flushPending
private SetOnce<java.lang.Boolean> flushPending
-
lastCommittedBytesUsed
private volatile long lastCommittedBytesUsed
-
hasFlushed
private SetOnce<java.lang.Boolean> hasFlushed
-
fieldInfos
private final FieldInfos.Builder fieldInfos
-
infoStream
private final InfoStream infoStream
-
numDocsInRAM
private int numDocsInRAM
-
deleteQueue
final DocumentsWriterDeleteQueue deleteQueue
-
deleteSlice
private final DocumentsWriterDeleteQueue.DeleteSlice deleteSlice
-
nf
private final java.text.NumberFormat nf
-
pendingNumDocs
private final java.util.concurrent.atomic.AtomicLong pendingNumDocs
-
indexWriterConfig
private final LiveIndexWriterConfig indexWriterConfig
-
enableTestPoints
private final boolean enableTestPoints
-
lock
private final java.util.concurrent.locks.ReentrantLock lock
-
deleteDocIDs
private int[] deleteDocIDs
-
numDeletedDocIds
private int numDeletedDocIds
-
parentField
private final IndexingChain.ReservedField<NumericDocValuesField> parentField
-
filesToDelete
private final java.util.Set<java.lang.String> filesToDelete
-
-
Constructor Detail
-
DocumentsWriterPerThread
DocumentsWriterPerThread(int indexMajorVersionCreated, java.lang.String segmentName, Directory directoryOrig, Directory directory, LiveIndexWriterConfig indexWriterConfig, DocumentsWriterDeleteQueue deleteQueue, FieldInfos.Builder fieldInfos, java.util.concurrent.atomic.AtomicLong pendingNumDocs, boolean enableTestPoints)
-
-
Method Detail
-
onAbortingException
private void onAbortingException(java.lang.Throwable throwable)
-
isAborted
final boolean isAborted()
-
abort
void abort() throws java.io.IOException
Called if we hit an exception at a bad time (when updating the index files) and must discard all currently buffered docs. This resets our state, discarding any docs added since last flush.- Throws:
java.io.IOException
-
testPoint
final void testPoint(java.lang.String message)
-
reserveOneDoc
private void reserveOneDoc()
Anything that will add N docs to the index should reserve first to make sure it's allowed.
-
updateDocuments
long updateDocuments(java.lang.Iterable<? extends java.lang.Iterable<? extends IndexableField>> docs, DocumentsWriterDeleteQueue.Node<?> deleteNode, DocumentsWriter.FlushNotifications flushNotifications, java.lang.Runnable onNewDocOnRAM) throws java.io.IOException
- Throws:
java.io.IOException
-
addParentField
private java.lang.Iterable<? extends IndexableField> addParentField(java.lang.Iterable<? extends IndexableField> doc, IndexableField parentField)
-
finishDocuments
private long finishDocuments(DocumentsWriterDeleteQueue.Node<?> deleteNode, int docIdUpTo)
-
deleteLastDocs
private void deleteLastDocs(int docCount)
-
getNumDocsInRAM
public int getNumDocsInRAM()
Returns the number of RAM resident documents in thisDocumentsWriterPerThread
-
prepareFlush
FrozenBufferedUpdates prepareFlush()
Prepares this DWPT for flushing. This method will freeze and return theDocumentsWriterDeleteQueue
s global buffer and apply all pending deletes to this DWPT.
-
flush
DocumentsWriterPerThread.FlushedSegment flush(DocumentsWriter.FlushNotifications flushNotifications) throws java.io.IOException
Flush all pending docs to a new segment- Throws:
java.io.IOException
-
maybeAbort
private void maybeAbort(java.lang.String location, DocumentsWriter.FlushNotifications flushNotifications) throws java.io.IOException
- Throws:
java.io.IOException
-
pendingFilesToDelete
java.util.Set<java.lang.String> pendingFilesToDelete()
-
sortLiveDocs
private FixedBitSet sortLiveDocs(Bits liveDocs, Sorter.DocMap sortMap)
-
sealFlushedSegment
void sealFlushedSegment(DocumentsWriterPerThread.FlushedSegment flushedSegment, Sorter.DocMap sortMap, DocumentsWriter.FlushNotifications flushNotifications) throws java.io.IOException
Seals theSegmentInfo
for the new flushed segment and persists the deleted documentsFixedBitSet
.- Throws:
java.io.IOException
-
getSegmentInfo
SegmentInfo getSegmentInfo()
Get current segment info we are writing.
-
ramBytesUsed
public long ramBytesUsed()
Description copied from interface:Accountable
Return the memory usage of this object in bytes. Negative values are illegal.- Specified by:
ramBytesUsed
in interfaceAccountable
-
getChildResources
public java.util.Collection<Accountable> getChildResources()
Description copied from interface:Accountable
Returns nested resources of this class. The result should be a point-in-time snapshot (to avoid race conditions).- Specified by:
getChildResources
in interfaceAccountable
- See Also:
Accountables
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
isFlushPending
boolean isFlushPending()
Returns true iff this DWPT is marked as flush pending
-
setFlushPending
void setFlushPending()
Sets this DWPT as flush pending. This can only be set once.
-
getLastCommittedBytesUsed
long getLastCommittedBytesUsed()
Returns the last committed bytes for this DWPT. This method can be called without acquiring the DWPTs lock.
-
commitLastBytesUsed
void commitLastBytesUsed(long delta)
Commits the currentramBytesUsed()
and stores it's value for later reuse. The last committed bytes used can be retrieved viagetLastCommittedBytesUsed()
-
getCommitLastBytesUsedDelta
long getCommitLastBytesUsedDelta()
Calculates the delta between the last committed bytes used and the currently used ram.- Returns:
- the delta between the current
ramBytesUsed()
and the currentgetLastCommittedBytesUsed()
- See Also:
commitLastBytesUsed(long)
-
lock
public void lock()
- Specified by:
lock
in interfacejava.util.concurrent.locks.Lock
-
lockInterruptibly
public void lockInterruptibly() throws java.lang.InterruptedException
- Specified by:
lockInterruptibly
in interfacejava.util.concurrent.locks.Lock
- Throws:
java.lang.InterruptedException
-
tryLock
public boolean tryLock()
- Specified by:
tryLock
in interfacejava.util.concurrent.locks.Lock
-
tryLock
public boolean tryLock(long time, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
tryLock
in interfacejava.util.concurrent.locks.Lock
- Throws:
java.lang.InterruptedException
-
isHeldByCurrentThread
boolean isHeldByCurrentThread()
Returns true if the DWPT's lock is held by the current thread- See Also:
ReentrantLock.isHeldByCurrentThread()
-
unlock
public void unlock()
- Specified by:
unlock
in interfacejava.util.concurrent.locks.Lock
-
newCondition
public java.util.concurrent.locks.Condition newCondition()
- Specified by:
newCondition
in interfacejava.util.concurrent.locks.Lock
-
hasFlushed
boolean hasFlushed()
Returnstrue
iff this DWPT has been flushed
-
-