Class LucenePrimaryKeySegmentIndexV1

java.lang.Object
com.apple.foundationdb.record.lucene.LucenePrimaryKeySegmentIndexV1
All Implemented Interfaces:
LucenePrimaryKeySegmentIndex

public class LucenePrimaryKeySegmentIndexV1 extends Object implements 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.
  • Constructor Details

    • LucenePrimaryKeySegmentIndexV1

      public LucenePrimaryKeySegmentIndexV1(@Nonnull FDBDirectory directory, @Nonnull Subspace subspace)
  • Method Details

    • readAllEntries

      public List<List<Object>> readAllEntries()
      Get all stored primary key index entries. Really only useful for small-scale debugging.
      Specified by:
      readAllEntries in interface LucenePrimaryKeySegmentIndex
      Returns:
      a list of Tuple-decoded key entries
    • findSegments

      public List<String> findSegments(@Nonnull Tuple primaryKey) throws IOException
      Return all the segments in which the given primary key appears. Mostly for debug logging.
      Specified by:
      findSegments in interface LucenePrimaryKeySegmentIndex
      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 interface LucenePrimaryKeySegmentIndex
      Parameters:
      directoryReader - a NRT reader
      primaryKey - 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 writer
      si - 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 interface LucenePrimaryKeySegmentIndex
      Parameters:
      primaryKey - the primary ey of the record
      segmentId - the id of the segment (see FDBDirectory.primaryKeySegmentId(java.lang.String, boolean))
      docId - the document id within the segment
      add - whether to add (true) or delete (false) the entry
      segmentName - name associated with the segment, for logging
    • clearForSegment

      public void clearForSegment(String segmentName)
      Description copied from interface: LucenePrimaryKeySegmentIndex
      Clears all the primary key entries for a given segment name.
      Specified by:
      clearForSegment in interface LucenePrimaryKeySegmentIndex
      Parameters:
      segmentName - the name of the segment to clear out