Class IndexInfo
- java.lang.Object
-
- org.alfresco.repo.search.impl.lucene.index.IndexInfo
-
- All Implemented Interfaces:
IndexMonitor
public class IndexInfo extends 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 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(String id)Make sure the writer and reader for TX data are closed.voidcloseDeltaIndexReader(String id)Manage closing and unregistering an index reader.voidcloseDeltaIndexWriter(String id)Manage closing and unregistering an index writer .voiddelete(String deltaId)static voiddestroy()voiddestroyInstance()<R> RdoReadOnly(IndexInfo.LockWork<R> lockWork)longgetActualSize()Gets the actual size of the index in bytes.Set<String>getDeletions(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(String id)This method should only be called from one thread as it is bound to a transaction.org.apache.lucene.index.IndexWritergetDeltaIndexWriter(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(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(String id, Set<String> deletions, Set<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.StringgetRelativePath()Gets the relative path of the index directory.Map<String,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(String[] args)Helper to print out index informationvoidsetPreparedState(String id, Set<String> toDelete, Set<String> containersToDelete, long documents, boolean deleteNodesOnly)Set the aux data for the index entry for a transactional unit of work.voidsetStatus(String id, TransactionStatus state, Set<org.apache.lucene.index.Term> toDelete, Set<org.apache.lucene.index.Term> read)StringtoString()
-
-
-
Field Detail
-
MAIN_READER
public static final String MAIN_READER
- See Also:
- Constant Field Values
-
-
Method Detail
-
destroy
public static void destroy()
-
destroyInstance
public void destroyInstance()
-
delete
public void delete(String deltaId)
-
getIndexInfo
public static IndexInfo getIndexInfo(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(String id) throws IOException
This method should only be called from one thread as it is bound to a transaction.- Parameters:
id- String- Returns:
- IndexReader
- Throws:
IOException
-
getDeltaIndexWriter
public org.apache.lucene.index.IndexWriter getDeltaIndexWriter(String id, org.apache.lucene.analysis.Analyzer analyzer) throws IOException
Manage 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:
IOException
-
closeDeltaIndexReader
public void closeDeltaIndexReader(String id) throws IOException
Manage closing and unregistering an index reader.- Parameters:
id- String- Throws:
IOException
-
closeDeltaIndexWriter
public void closeDeltaIndexWriter(String id) throws IOException
Manage closing and unregistering an index writer .- Parameters:
id- String- Throws:
IOException
-
closeDelta
public void closeDelta(String id) throws IOException
Make sure the writer and reader for TX data are closed.- Parameters:
id- String- Throws:
IOException
-
getDeletions
public Set<String> getDeletions(String id) throws IOException
Get 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:
IOException
-
setPreparedState
public void setPreparedState(String id, Set<String> toDelete, Set<String> containersToDelete, long documents, boolean deleteNodesOnly) throws IOException
Set 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:
IOException
-
getMainIndexReferenceCountingReadOnlyIndexReader
public org.apache.lucene.index.IndexReader getMainIndexReferenceCountingReadOnlyIndexReader() throws IOExceptionGet the main reader for committed index data- Returns:
- IndexReader
- Throws:
IOException
-
getMainIndexReferenceCountingReadOnlyIndexReader
public org.apache.lucene.index.IndexReader getMainIndexReferenceCountingReadOnlyIndexReader(String id, Set<String> deletions, Set<String> containerDeletions, boolean deleteOnlyNodes) throws IOException
Get 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:
IOException
-
setStatus
public void setStatus(String id, TransactionStatus state, Set<org.apache.lucene.index.Term> toDelete, Set<org.apache.lucene.index.Term> read) throws IOException
- Throws:
IOException
-
doReadOnly
public <R> R doReadOnly(IndexInfo.LockWork<R> lockWork)
-
main
public static void main(String[] args) throws Throwable
Helper to print out index information- Parameters:
args- String[]- Throws:
Throwable
-
getRelativePath
public String getRelativePath()
Description copied from interface:IndexMonitorGets the relative path of the index directory.- Specified by:
getRelativePathin interfaceIndexMonitor- Returns:
- the relative path
-
getStatusSnapshot
public Map<String,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 IOExceptionDescription copied from interface:IndexMonitorGets the actual size of the index in bytes.- Specified by:
getActualSizein interfaceIndexMonitor- Returns:
- the actual size in bytes
- Throws:
IOException- Signals that an I/O exception has occurred.
-
getUsedSize
public long getUsedSize() throws 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:
IOException- Signals that an I/O exception has occurred.
-
getNumberOfDocuments
public int getNumberOfDocuments() throws IOExceptionDescription copied from interface:IndexMonitorGets the number of documents in the index.- Specified by:
getNumberOfDocumentsin interfaceIndexMonitor- Returns:
- the number of documents
- Throws:
IOException- Signals that an I/O exception has occurred.
-
getNumberOfFields
public int getNumberOfFields() throws IOExceptionDescription copied from interface:IndexMonitorGets the number of fields known to the index.- Specified by:
getNumberOfFieldsin interfaceIndexMonitor- Returns:
- the number of fields
- Throws:
IOException- Signals that an I/O exception has occurred.
-
getNumberOfIndexedFields
public int getNumberOfIndexedFields() throws IOExceptionDescription copied from interface:IndexMonitorGets the number of indexed fields.- Specified by:
getNumberOfIndexedFieldsin interfaceIndexMonitor- Returns:
- the number of indexed fields
- Throws:
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
-
-