public class NRTWorkspaceImpl extends AbstractWorkspaceImpl implements DirectoryBasedReaderProvider
Workspace
implementation taking advantage of NRT Lucene features.
IndexReader
instances are obtained directly from the IndexWriter
, which is not forced
to flush all pending changes to the Directory
structure.
Lucene requires in its current version to flush delete operations, or the IndexReader
s
retrieved via NRT will include deleted Document instances in queries; flushing delete operations
happens to be quite expensive so this Workspace
implementation attempts to detect when such
a flush operation is needed.
Applying write operations flags "indexReader requirements" with needs for either normal flush
or flush including deletes, but does not update IndexReader
instances. The IndexReader
s
are updated only if and when a fresh IndexReader
is requested via openIndexReader()
.
This method will check if it can return the last opened IndexReader
or in case of the reader being stale
open a fresh reader from the current IndexWriter
.
Generation counters are used to track need-at-least version versus last-updated-at version:
shared state is avoided between index writers and reader threads to avoid high complexity.
The method afterTransactionApplied(boolean, boolean)
might trigger multiple times flagging
the index to be dirty without triggering an actual IndexReader
refresh, so the version counters
can have gaps: method refreshReaders()
will always jump to latest seen version, as it will
refresh the index to satisfy both kinds of flush requirements (writes and deletes).
We keep a reference IndexReader
in the currentReader
atomic reference as a fast path
for multiple read events when the index is not dirty.
This class implements both Workspace
and ReaderProvider
.
writerHolder
Constructor and Description |
---|
NRTWorkspaceImpl(DirectoryBasedIndexManager indexManager,
WorkerBuildContext buildContext,
Properties cfg) |
Modifier and Type | Method and Description |
---|---|
void |
afterTransactionApplied(boolean someFailureHappened,
boolean streaming)
Invoked after all changes of a transaction are applied.
|
void |
closeIndexReader(IndexReader reader) |
void |
flush()
Makes sure eventually pending changes are made visible to IndexReaders.
|
CommitPolicy |
getCommitPolicy()
Get the commit policy applied to the workspace
|
void |
initialize(DirectoryBasedIndexManager indexManager,
Properties props) |
void |
notifyWorkApplied(LuceneWork work)
Some workspaces need this to determine for example the kind of flush operations which are safe
to apply.
|
DirectoryReader |
openIndexReader() |
void |
stop() |
areSingleTermDeletesSafe, closeIndexWriter, getAnalyzer, getDocumentBuilder, getEntitiesInIndexManager, getIndexName, getIndexWriter, getIndexWriter, getIndexWriterDelegate, getIndexWriterDelegate, incrementModificationCounter, isDeleteByTermEnforced, optimizerPhase, performOptimization, shutDownNow
public NRTWorkspaceImpl(DirectoryBasedIndexManager indexManager, WorkerBuildContext buildContext, Properties cfg)
public void afterTransactionApplied(boolean someFailureHappened, boolean streaming)
Workspace
Workspace.getIndexWriter()
in a finally block
as implementations might rely on counters to release the IndexWriter.afterTransactionApplied
in interface Workspace
afterTransactionApplied
in class AbstractWorkspaceImpl
someFailureHappened
- usually false, set to true if errors
where caught while using the IndexWriterstreaming
- if no immediate visibility of the change is required (hint for performance)public DirectoryReader openIndexReader()
openIndexReader
in interface ReaderProvider
public void closeIndexReader(IndexReader reader)
closeIndexReader
in interface ReaderProvider
public void initialize(DirectoryBasedIndexManager indexManager, Properties props)
initialize
in interface DirectoryBasedReaderProvider
public void stop()
stop
in interface DirectoryBasedReaderProvider
public void flush()
Workspace
flush
in interface Workspace
flush
in class AbstractWorkspaceImpl
public void notifyWorkApplied(LuceneWork work)
Workspace
notifyWorkApplied
in interface Workspace
work
- the LuceneWork which was just processedpublic CommitPolicy getCommitPolicy()
Workspace
getCommitPolicy
in interface Workspace
CommitPolicy
Copyright © 2006-2017 Red Hat, Inc. All Rights Reserved