Class LucenePrimaryKeySegmentIndexV1
java.lang.Object
com.apple.foundationdb.record.lucene.LucenePrimaryKeySegmentIndexV1
- All Implemented Interfaces:
LucenePrimaryKeySegmentIndex
Maintain a B-tree index of primary key to segment and doc id.
This allows for efficient deleting of a document given that key, such as when doing index maintenance from an update.
This works with any implementation of
StoredFieldsWriter
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Hook for getting back segment info during merge.Nested classes/interfaces inherited from interface com.apple.foundationdb.record.lucene.LucenePrimaryKeySegmentIndex
LucenePrimaryKeySegmentIndex.DocumentIndexEntry
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addOrDeletePrimaryKeyEntry
(byte[] primaryKey, long segmentId, int docId, boolean add, String segmentName) Add or delete the primary key/segment/docId from the index.void
clearForSegment
(String segmentName) Clears all the primary key entries for a given segment name.findDocument
(org.apache.lucene.index.DirectoryReader directoryReader, Tuple primaryKey) Find document in index for direct delete.findSegments
(Tuple primaryKey) Return all the segments in which the given primary key appears.Get all stored primary key index entries.org.apache.lucene.codecs.StoredFieldsWriter
wrapFieldsWriter
(org.apache.lucene.codecs.StoredFieldsWriter storedFieldsWriter, org.apache.lucene.index.SegmentInfo si) Hook the fields writer to also record primary keys in index.
-
Constructor Details
-
LucenePrimaryKeySegmentIndexV1
-
-
Method Details
-
readAllEntries
Get all stored primary key index entries. Really only useful for small-scale debugging.- Specified by:
readAllEntries
in interfaceLucenePrimaryKeySegmentIndex
- Returns:
- a list of Tuple-decoded key entries
-
findSegments
Return all the segments in which the given primary key appears. Mostly for debug logging.- Specified by:
findSegments
in interfaceLucenePrimaryKeySegmentIndex
- Parameters:
primaryKey
- the document's record's primary key- Returns:
- a list of segment names or segment ids when apparently not associated with a name
- Throws:
IOException
-
findDocument
@Nullable public LucenePrimaryKeySegmentIndex.DocumentIndexEntry findDocument(@Nonnull org.apache.lucene.index.DirectoryReader directoryReader, @Nonnull Tuple primaryKey) throws IOException Description copied from interface:LucenePrimaryKeySegmentIndex
Find document in index for direct delete.- Specified by:
findDocument
in interfaceLucenePrimaryKeySegmentIndex
- Parameters:
directoryReader
- a NRT readerprimaryKey
- the document's record's primary key- Returns:
- an entry with the leaf reader and document id in that segment or
null
if not found - Throws:
IOException
- See Also:
-
IndexWriter.tryDeleteDocument(org.apache.lucene.index.IndexReader, int)
-
wrapFieldsWriter
@Nonnull public org.apache.lucene.codecs.StoredFieldsWriter wrapFieldsWriter(@Nonnull org.apache.lucene.codecs.StoredFieldsWriter storedFieldsWriter, @Nonnull org.apache.lucene.index.SegmentInfo si) throws IOException Hook the fields writer to also record primary keys in index.- Parameters:
storedFieldsWriter
- normal field writersi
- segment info for current writer- Returns:
- a wrapped writer
- Throws:
IOException
- thrown by called methods
-
addOrDeletePrimaryKeyEntry
public void addOrDeletePrimaryKeyEntry(@Nonnull byte[] primaryKey, long segmentId, int docId, boolean add, String segmentName) Description copied from interface:LucenePrimaryKeySegmentIndex
Add or delete the primary key/segment/docId from the index.- Specified by:
addOrDeletePrimaryKeyEntry
in interfaceLucenePrimaryKeySegmentIndex
- Parameters:
primaryKey
- the primary ey of the recordsegmentId
- the id of the segment (seeFDBDirectory.primaryKeySegmentId(java.lang.String, boolean)
)docId
- the document id within the segmentadd
- whether to add (true
) or delete (false
) the entrysegmentName
- name associated with the segment, for logging
-
clearForSegment
Description copied from interface:LucenePrimaryKeySegmentIndex
Clears all the primary key entries for a given segment name.- Specified by:
clearForSegment
in interfaceLucenePrimaryKeySegmentIndex
- Parameters:
segmentName
- the name of the segment to clear out
-