Class IndexInfo
- java.lang.Object
-
- org.alfresco.repo.search.impl.lucene.index.IndexInfo
-
- All Implemented Interfaces:
IndexMonitor
public class IndexInfo extends java.lang.Object implements IndexMonitor
The information that makes up an index. IndexInfoVersion Repeated information of the form- Index Type.
- sub-directory name.
- Status
- Indexes, sub indexes, and overlays must be committed. Status is ACTIVE, MERGING, COMPLETING_INDEX
- Delta: Transaction status
- Overlay: Transaction status
The index structure is duplicated to two files. If one is currupted the second is used.
TODO:
- make the index sharing configurable
- use a thread pool for deletions, merging and index deletions
- something to control the maximum number of overlays to limit the number of things layered together for searching
- look at lucene locking again post 2.0, to see if it is improved
- clean up old data files (that are not old index entries) - should be a config option
- Author:
- Andy Hind
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceIndexInfo.LockWork<Result>
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringMAIN_READER
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddApplicationListener(org.springframework.context.ApplicationListener listener)Registers a listener for events on this index.voidcloseDelta(java.lang.String id)Make sure the writer and reader for TX data are closed.voidcloseDeltaIndexReader(java.lang.String id)Manage closing and unregistering an index reader.voidcloseDeltaIndexWriter(java.lang.String id)Manage closing and unregistering an index writer .voiddelete(java.lang.String deltaId)static voiddestroy()voiddestroyInstance()<R> RdoReadOnly(IndexInfo.LockWork<R> lockWork)longgetActualSize()Gets the actual size of the index in bytes.java.util.Set<java.lang.String>getDeletions(java.lang.String id)Get the deletions for a given index (there is no check if they should be applied that is up to the calling layer)org.apache.lucene.index.IndexReadergetDeltaIndexReader(java.lang.String id)This method should only be called from one thread as it is bound to a transaction.org.apache.lucene.index.IndexWritergetDeltaIndexWriter(java.lang.String id, org.apache.lucene.analysis.Analyzer analyzer)Manage getting a lucene index writer for transactional data - looks after registration and checking there is no active reader.static IndexInfogetIndexInfo(java.io.File file, LuceneConfig config)Get the IndexInfo object based in the given directory.org.apache.lucene.index.IndexReadergetMainIndexReferenceCountingReadOnlyIndexReader()Get the main reader for committed index dataorg.apache.lucene.index.IndexReadergetMainIndexReferenceCountingReadOnlyIndexReader(java.lang.String id, java.util.Set<java.lang.String> deletions, java.util.Set<java.lang.String> containerDeletions, boolean deleteOnlyNodes)Get the main index reader augmented with the specified TX data As above but we add the TX dataintgetNumberOfDocuments()Gets the number of documents in the index.intgetNumberOfFields()Gets the number of fields known to the index.intgetNumberOfIndexedFields()Gets the number of indexed fields.java.lang.StringgetRelativePath()Gets the relative path of the index directory.java.util.Map<java.lang.String,java.lang.Integer>getStatusSnapshot()Gets a snapshot of the statuses of the individual entries in this index.longgetUsedSize()Gets the size used on disk by the index directory.static voidmain(java.lang.String[] args)Helper to print out index informationvoidsetPreparedState(java.lang.String id, java.util.Set<java.lang.String> toDelete, java.util.Set<java.lang.String> containersToDelete, long documents, boolean deleteNodesOnly)Set the aux data for the index entry for a transactional unit of work.voidsetStatus(java.lang.String id, TransactionStatus state, java.util.Set<org.apache.lucene.index.Term> toDelete, java.util.Set<org.apache.lucene.index.Term> read)java.lang.StringtoString()
-
-
-
Field Detail
-
MAIN_READER
public static final java.lang.String MAIN_READER
- See Also:
- Constant Field Values
-
-
Method Detail
-
destroy
public static void destroy()
-
destroyInstance
public void destroyInstance()
-
delete
public void delete(java.lang.String deltaId)
-
getIndexInfo
public static IndexInfo getIndexInfo(java.io.File file, LuceneConfig config) throws IndexerException
Get the IndexInfo object based in the given directory. There is only one object per directory per JVM.- Parameters:
file- Fileconfig- LuceneConfig- Returns:
- IndexInfo
- Throws:
IndexerException
-
getDeltaIndexReader
public org.apache.lucene.index.IndexReader getDeltaIndexReader(java.lang.String id) throws java.io.IOExceptionThis method should only be called from one thread as it is bound to a transaction.- Parameters:
id- String- Returns:
- IndexReader
- Throws:
java.io.IOException
-
getDeltaIndexWriter
public org.apache.lucene.index.IndexWriter getDeltaIndexWriter(java.lang.String id, org.apache.lucene.analysis.Analyzer analyzer) throws java.io.IOExceptionManage getting a lucene index writer for transactional data - looks after registration and checking there is no active reader.- Parameters:
id- Stringanalyzer- Analyzer- Returns:
- IndexWriter
- Throws:
java.io.IOException
-
closeDeltaIndexReader
public void closeDeltaIndexReader(java.lang.String id) throws java.io.IOExceptionManage closing and unregistering an index reader.- Parameters:
id- String- Throws:
java.io.IOException
-
closeDeltaIndexWriter
public void closeDeltaIndexWriter(java.lang.String id) throws java.io.IOExceptionManage closing and unregistering an index writer .- Parameters:
id- String- Throws:
java.io.IOException
-
closeDelta
public void closeDelta(java.lang.String id) throws java.io.IOExceptionMake sure the writer and reader for TX data are closed.- Parameters:
id- String- Throws:
java.io.IOException
-
getDeletions
public java.util.Set<java.lang.String> getDeletions(java.lang.String id) throws java.io.IOExceptionGet the deletions for a given index (there is no check if they should be applied that is up to the calling layer)- Parameters:
id- String- Throws:
java.io.IOException
-
setPreparedState
public void setPreparedState(java.lang.String id, java.util.Set<java.lang.String> toDelete, java.util.Set<java.lang.String> containersToDelete, long documents, boolean deleteNodesOnly) throws java.io.IOExceptionSet the aux data for the index entry for a transactional unit of work.- Parameters:
id- - the tx idtoDelete- - noderefs that should be deleted from previous indexes (not this one)documents- - the number of docs in the indexdeleteNodesOnly- - should deletions on apply to nodes (ie not to containers)- Throws:
java.io.IOException
-
getMainIndexReferenceCountingReadOnlyIndexReader
public org.apache.lucene.index.IndexReader getMainIndexReferenceCountingReadOnlyIndexReader() throws java.io.IOExceptionGet the main reader for committed index data- Returns:
- IndexReader
- Throws:
java.io.IOException
-
getMainIndexReferenceCountingReadOnlyIndexReader
public org.apache.lucene.index.IndexReader getMainIndexReferenceCountingReadOnlyIndexReader(java.lang.String id, java.util.Set<java.lang.String> deletions, java.util.Set<java.lang.String> containerDeletions, boolean deleteOnlyNodes) throws java.io.IOExceptionGet the main index reader augmented with the specified TX data As above but we add the TX data- Parameters:
id- StringdeleteOnlyNodes- boolean- Returns:
- IndexReader
- Throws:
java.io.IOException
-
setStatus
public void setStatus(java.lang.String id, TransactionStatus state, java.util.Set<org.apache.lucene.index.Term> toDelete, java.util.Set<org.apache.lucene.index.Term> read) throws java.io.IOException- Throws:
java.io.IOException
-
doReadOnly
public <R> R doReadOnly(IndexInfo.LockWork<R> lockWork)
-
main
public static void main(java.lang.String[] args) throws java.lang.ThrowableHelper to print out index information- Parameters:
args- String[]- Throws:
java.lang.Throwable
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getRelativePath
public java.lang.String getRelativePath()
Description copied from interface:IndexMonitorGets the relative path of the index directory.- Specified by:
getRelativePathin interfaceIndexMonitor- Returns:
- the relative path
-
getStatusSnapshot
public java.util.Map<java.lang.String,java.lang.Integer> getStatusSnapshot()
Description copied from interface:IndexMonitorGets a snapshot of the statuses of the individual entries in this index.- Specified by:
getStatusSnapshotin interfaceIndexMonitor- Returns:
- a map of entry status names to entry counts
-
getActualSize
public long getActualSize() throws java.io.IOExceptionDescription copied from interface:IndexMonitorGets the actual size of the index in bytes.- Specified by:
getActualSizein interfaceIndexMonitor- Returns:
- the actual size in bytes
- Throws:
java.io.IOException- Signals that an I/O exception has occurred.
-
getUsedSize
public long getUsedSize() throws java.io.IOExceptionDescription copied from interface:IndexMonitorGets the size used on disk by the index directory. A large discrepancy from the value returned byIndexMonitor.getActualSize()may indicate that there are unused data files.- Specified by:
getUsedSizein interfaceIndexMonitor- Returns:
- the size on disk in bytes
- Throws:
java.io.IOException- Signals that an I/O exception has occurred.
-
getNumberOfDocuments
public int getNumberOfDocuments() throws java.io.IOExceptionDescription copied from interface:IndexMonitorGets the number of documents in the index.- Specified by:
getNumberOfDocumentsin interfaceIndexMonitor- Returns:
- the number of documents
- Throws:
java.io.IOException- Signals that an I/O exception has occurred.
-
getNumberOfFields
public int getNumberOfFields() throws java.io.IOExceptionDescription copied from interface:IndexMonitorGets the number of fields known to the index.- Specified by:
getNumberOfFieldsin interfaceIndexMonitor- Returns:
- the number of fields
- Throws:
java.io.IOException- Signals that an I/O exception has occurred.
-
getNumberOfIndexedFields
public int getNumberOfIndexedFields() throws java.io.IOExceptionDescription copied from interface:IndexMonitorGets the number of indexed fields.- Specified by:
getNumberOfIndexedFieldsin interfaceIndexMonitor- Returns:
- the number of indexed fields
- Throws:
java.io.IOException- Signals that an I/O exception has occurred.
-
addApplicationListener
public void addApplicationListener(org.springframework.context.ApplicationListener listener)
Description copied from interface:IndexMonitorRegisters a listener for events on this index.- Specified by:
addApplicationListenerin interfaceIndexMonitor- Parameters:
listener- the listener
-
-