java.lang.Object
org.apache.lucene.index.SegmentInfos
- All Implemented Interfaces:
Cloneable,Iterable<SegmentCommitInfo>
A collection of segmentInfo objects with methods for operating on those segments in relation to
the file system.
The active segments in the index are stored in the segment info file, segments_N.
There may be one or more segments_N files in the index; however, the one with the
largest generation is the active one (when older segments_N files are present it's because they
temporarily cannot be deleted, or a custom IndexDeletionPolicy is in use). This file
lists each segment by name and has details about the codec and generation of deletes.
Files:
segments_N: Header, LuceneVersion, Version, NameCounter, SegCount, MinSegmentLuceneVersion, <SegName, SegID, SegCodec, DelGen, DeletionCount, FieldInfosGen, DocValuesGen, UpdatesFiles>SegCount, CommitUserData, Footer
- Header -->
IndexHeader - LuceneVersion --> Which Lucene code
Versionwas used for this commit, written as threevInt: major, minor, bugfix - MinSegmentLuceneVersion --> Lucene code
Versionof the oldest segment, written as threevInt: major, minor, bugfix; this is only written only if there's at least one segment - NameCounter, SegCount, DeletionCount -->
Int32 - Generation, Version, DelGen, Checksum, FieldInfosGen, DocValuesGen -->
Int64 - SegID -->
Int8ID_LENGTH - SegName, SegCodec -->
String - CommitUserData -->
Map<String,String> - UpdatesFiles --> Map<
Int32,Set<String>> - Footer -->
CodecFooter
- Version counts how often the index has been changed by adding or deleting documents.
- NameCounter is used to generate names for new segment files.
- SegName is the name of the segment, and is used as the file name prefix for all of the files that compose the segment's index.
- DelGen is the generation count of the deletes file. If this is -1, there are no deletes.
Anything above zero means there are deletes stored by
LiveDocsFormat. - DeletionCount records the number of deleted documents in this segment.
- SegCodec is the
nameof the Codec that encoded this segment. - SegID is the identifier of the Codec that encoded this segment.
- CommitUserData stores an optional user-supplied opaque Map<String,String> that was
passed to
IndexWriter.setLiveCommitData(Iterable). - FieldInfosGen is the generation count of the fieldInfos file. If this is -1, there are no
updates to the fieldInfos in that segment. Anything above zero means there are updates to
fieldInfos stored by
FieldInfosFormat. - DocValuesGen is the generation count of the updatable DocValues. If this is -1, there are
no updates to DocValues in that segment. Anything above zero means there are updates to
DocValues stored by
DocValuesFormat. - UpdatesFiles stores the set of files that were updated in that segment per field.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classUtility class for executing code that needs to do something with the current segments file. -
Field Summary
FieldsModifier and TypeFieldDescriptionlongUsed to name new segments.private longprivate byte[]Id for this commit; only written starting with Lucene 5.0private final intThe Lucene version major that was used to create the index.private static PrintStreamIf non-null, information about loading segments_N files will be printed here.private longprivate VersionWhich Lucene version wrote this commit.private VersionVersion of the oldest segment in the index, or null if there are no segments.(package private) static final StringName of the generation reference file name(package private) booleanprivate List<SegmentCommitInfo> Opaque Map<String, String> that user can specify during IndexWriter.commitlongCounts how often the index has been changed.static final intThe version that added information about the Lucene version at the time when the index has been created.static final intThe version that updated segment name counter to be long instead of int.static final intThe version that recorded softDelCountstatic final intThe version that recorded SegmentCommitInfo IDs(package private) static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(SegmentCommitInfo si) Appends the providedSegmentCommitInfo.voidaddAll(Iterable<SegmentCommitInfo> sis) Appends the providedSegmentCommitInfos.(package private) voidapplyMergeChanges(MergePolicy.OneMerge merge, boolean dropSegment) applies all changes caused by committing a merge to this SegmentInfosasList()Returns all contained segments as an unmodifiableListview.voidchanged()Call this before committing if changes have been made to the segments.voidclear()Clear allSegmentCommitInfos.clone()Returns a copy of this instance, also copying each SegmentInfo.final voidWrites and syncs to the Directory dir, taking care to remove the segments file on exception(package private) booleanReturn true if the providedSegmentCommitInfois contained.(package private) List<SegmentCommitInfo> files(boolean includeSegmentsFile) Returns all file names referenced by SegmentInfo.(package private) final StringfinishCommit(Directory dir) Returns the committed segments_N filename.static longgenerationFromSegmentsFileName(String fileName) Parse the generation off the segments file name and return it.Returns which LuceneVersionwrote this commit, or null if the version this index was written with did not directly record the version.longReturns current generation.byte[]getId()Since Lucene 5.0, every commit (segments_N) writes a unique id.intReturn the version major that was used to initially create the index.static PrintStreamReturnsinfoStream.static longgetLastCommitGeneration(String[] files) Get the generation of the most recent commit to the list of index files (N in the segments_N file).static longgetLastCommitGeneration(Directory directory) Get the generation of the most recent commit to the index in this directory (N in the segments_N file).static StringgetLastCommitSegmentsFileName(String[] files) Get the filename of the segments_N file for the most recent commit in the list of index files.static StringgetLastCommitSegmentsFileName(Directory directory) Get the filename of the segments_N file for the most recent commit to the index in this Directory.longReturns last succesfully read or written generation.Returns the version of the oldest segment, or null if there are no segments.private longreturn generation of the next pending_segments_N that will be writtenGet the segments_N filename in use by this segment infos.ReturnuserDatasaved with this commit.longversion number when this SegmentInfos was generated.(package private) intReturns index of the providedSegmentCommitInfo.info(int i) ReturnsSegmentCommitInfoat the provided index.iterator()Returns an unmodifiableIteratorof contained segments in order.private static voidPrints the given message to the infoStream.private static voidparseSegmentInfos(Directory directory, DataInput input, SegmentInfos infos, int format) (package private) final voidprepareCommit(Directory dir) Call this to start a commit.private static Codecstatic final SegmentInfosreadCommit(Directory directory, String segmentFileName) Read a particular segmentFileName.(package private) static final SegmentInfosreadCommit(Directory directory, String segmentFileName, int minSupportedMajorVersion) static final SegmentInfosreadCommit(Directory directory, ChecksumIndexInput input, long generation) Read the commit from the providedChecksumIndexInput.(package private) static final SegmentInfosreadCommit(Directory directory, ChecksumIndexInput input, long generation, int minSupportedMajorVersion) Read the commit from the providedChecksumIndexInput.static final SegmentInfosreadLatestCommit(Directory directory) Find the latest commit (segments_N file) and load allSegmentCommitInfos.static final SegmentInfosreadLatestCommit(Directory directory, int minSupportedMajorVersion) Find the latest commit (segments_N file) and load allSegmentCommitInfos, as long as the commit'sgetIndexCreatedVersionMajor()is strictly greater than the provided minimum supported major version.(package private) voidremove(int index) Remove theSegmentCommitInfoat the provided index.booleanRemove the providedSegmentCommitInfo.(package private) voidreplace(SegmentInfos other) Replaces all segments in this instance, but keeps generation, version, counter so that future commits remain write once.(package private) final voidrollbackCommit(Directory dir) (package private) voidstatic voidsetInfoStream(PrintStream infoStream) If non-null, information about retries when loading the segments file will be printed to this.voidsetNextWriteGeneration(long generation) Set the generation to be used for the next commitvoidsetUserData(Map<String, String> data, boolean doIncrementVersion) Sets the commit data.(package private) voidsetVersion(long newVersion) intsize()Returns number ofSegmentCommitInfos.toString()Returns readable description of this segment.intReturns sum of all segment's maxDocs.voidupdateGeneration(SegmentInfos other) Carry over generation numbers from another SegmentInfos(package private) voidprivate voidvoidwrite(IndexOutput out) Write ourselves to the providedIndexOutputMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
VERSION_70
public static final int VERSION_70The version that added information about the Lucene version at the time when the index has been created.- See Also:
-
VERSION_72
public static final int VERSION_72The version that updated segment name counter to be long instead of int.- See Also:
-
VERSION_74
public static final int VERSION_74The version that recorded softDelCount- See Also:
-
VERSION_86
public static final int VERSION_86The version that recorded SegmentCommitInfo IDs- See Also:
-
VERSION_CURRENT
static final int VERSION_CURRENT- See Also:
-
OLD_SEGMENTS_GEN
Name of the generation reference file name- See Also:
-
counter
public long counterUsed to name new segments. -
version
public long versionCounts how often the index has been changed. -
generation
private long generation -
lastGeneration
private long lastGeneration -
userData
Opaque Map<String, String> that user can specify during IndexWriter.commit -
segments
-
infoStream
If non-null, information about loading segments_N files will be printed here.- See Also:
-
id
private byte[] idId for this commit; only written starting with Lucene 5.0 -
luceneVersion
Which Lucene version wrote this commit. -
minSegmentLuceneVersion
Version of the oldest segment in the index, or null if there are no segments. -
indexCreatedVersionMajor
private final int indexCreatedVersionMajorThe Lucene version major that was used to create the index. -
pendingCommit
boolean pendingCommit
-
-
Constructor Details
-
SegmentInfos
public SegmentInfos(int indexCreatedVersionMajor) Sole constructor.- Parameters:
indexCreatedVersionMajor- the Lucene version major at index creation time, or 6 if the index was created before 7.0
-
-
Method Details
-
info
ReturnsSegmentCommitInfoat the provided index. -
getLastCommitGeneration
Get the generation of the most recent commit to the list of index files (N in the segments_N file).- Parameters:
files- -- array of file names to check
-
getLastCommitGeneration
Get the generation of the most recent commit to the index in this directory (N in the segments_N file).- Parameters:
directory- -- directory to search for the latest segments_N file- Throws:
IOException
-
getLastCommitSegmentsFileName
Get the filename of the segments_N file for the most recent commit in the list of index files.- Parameters:
files- -- array of file names to check
-
getLastCommitSegmentsFileName
Get the filename of the segments_N file for the most recent commit to the index in this Directory.- Parameters:
directory- -- directory to search for the latest segments_N file- Throws:
IOException
-
getSegmentsFileName
Get the segments_N filename in use by this segment infos. -
generationFromSegmentsFileName
Parse the generation off the segments file name and return it. -
getNextPendingGeneration
private long getNextPendingGeneration()return generation of the next pending_segments_N that will be written -
getId
public byte[] getId()Since Lucene 5.0, every commit (segments_N) writes a unique id. This will return that id -
readCommit
public static final SegmentInfos readCommit(Directory directory, String segmentFileName) throws IOException Read a particular segmentFileName. Note that this may throw an IOException if a commit is in process.- Parameters:
directory- -- directory containing the segments filesegmentFileName- -- segment file to load- Throws:
CorruptIndexException- if the index is corruptIOException- if there is a low-level IO error
-
readCommit
static final SegmentInfos readCommit(Directory directory, String segmentFileName, int minSupportedMajorVersion) throws IOException - Throws:
IOException
-
readCommit
public static final SegmentInfos readCommit(Directory directory, ChecksumIndexInput input, long generation) throws IOException Read the commit from the providedChecksumIndexInput.- Throws:
IOException
-
readCommit
static final SegmentInfos readCommit(Directory directory, ChecksumIndexInput input, long generation, int minSupportedMajorVersion) throws IOException Read the commit from the providedChecksumIndexInput.- Throws:
IOException
-
parseSegmentInfos
private static void parseSegmentInfos(Directory directory, DataInput input, SegmentInfos infos, int format) throws IOException - Throws:
IOException
-
readCodec
- Throws:
IOException
-
readLatestCommit
Find the latest commit (segments_N file) and load allSegmentCommitInfos.- Throws:
IOException
-
readLatestCommit
public static final SegmentInfos readLatestCommit(Directory directory, int minSupportedMajorVersion) throws IOException Find the latest commit (segments_N file) and load allSegmentCommitInfos, as long as the commit'sgetIndexCreatedVersionMajor()is strictly greater than the provided minimum supported major version. If the commit's version is older, anIndexFormatTooOldExceptionwill be thrown.- Throws:
IOException
-
write
- Throws:
IOException
-
write
Write ourselves to the providedIndexOutput- Throws:
IOException
-
clone
Returns a copy of this instance, also copying each SegmentInfo. -
getVersion
public long getVersion()version number when this SegmentInfos was generated. -
getGeneration
public long getGeneration()Returns current generation. -
getLastGeneration
public long getLastGeneration()Returns last succesfully read or written generation. -
setInfoStream
If non-null, information about retries when loading the segments file will be printed to this. -
getInfoStream
ReturnsinfoStream.- See Also:
-
message
Prints the given message to the infoStream. Note, this method does not check for null infoStream. It assumes this check has been performed by the caller, which is recommended to avoid the (usually) expensive message creation. -
updateGeneration
Carry over generation numbers from another SegmentInfos -
updateGenerationVersionAndCounter
-
setNextWriteGeneration
public void setNextWriteGeneration(long generation) Set the generation to be used for the next commit -
rollbackCommit
-
prepareCommit
Call this to start a commit. This writes the new segments file, but writes an invalid checksum at the end, so that it is not visible to readers. Once this is called you must callfinishCommit(org.apache.lucene.store.Directory)to complete the commit orrollbackCommit(org.apache.lucene.store.Directory)to abort it.Note:
changed()should be called prior to this method if changes have been made to thisSegmentInfosinstance- Throws:
IOException
-
files
Returns all file names referenced by SegmentInfo. The returned collection is recomputed on each invocation.- Throws:
IOException
-
finishCommit
Returns the committed segments_N filename.- Throws:
IOException
-
commit
Writes and syncs to the Directory dir, taking care to remove the segments file on exceptionNote:
changed()should be called prior to this method if changes have been made to thisSegmentInfosinstance- Throws:
IOException
-
toString
Returns readable description of this segment. -
getUserData
ReturnuserDatasaved with this commit.- See Also:
-
setUserData
Sets the commit data. -
replace
Replaces all segments in this instance, but keeps generation, version, counter so that future commits remain write once. -
totalMaxDoc
public int totalMaxDoc()Returns sum of all segment's maxDocs. Note that this does not include deletions -
changed
public void changed()Call this before committing if changes have been made to the segments. -
setVersion
void setVersion(long newVersion) -
applyMergeChanges
applies all changes caused by committing a merge to this SegmentInfos -
createBackupSegmentInfos
List<SegmentCommitInfo> createBackupSegmentInfos() -
rollbackSegmentInfos
-
iterator
Returns an unmodifiableIteratorof contained segments in order.- Specified by:
iteratorin interfaceIterable<SegmentCommitInfo>
-
asList
Returns all contained segments as an unmodifiableListview. -
size
public int size()Returns number ofSegmentCommitInfos. -
add
Appends the providedSegmentCommitInfo. -
addAll
Appends the providedSegmentCommitInfos. -
clear
public void clear()Clear allSegmentCommitInfos. -
remove
Remove the providedSegmentCommitInfo.WARNING: O(N) cost
-
remove
void remove(int index) Remove theSegmentCommitInfoat the provided index.WARNING: O(N) cost
-
contains
Return true if the providedSegmentCommitInfois contained.WARNING: O(N) cost
-
indexOf
Returns index of the providedSegmentCommitInfo.WARNING: O(N) cost
-
getCommitLuceneVersion
Returns which LuceneVersionwrote this commit, or null if the version this index was written with did not directly record the version. -
getMinSegmentLuceneVersion
Returns the version of the oldest segment, or null if there are no segments. -
getIndexCreatedVersionMajor
public int getIndexCreatedVersionMajor()Return the version major that was used to initially create the index. This version is set when the index is first created and then never changes. This information was added as of version 7.0 so older indices report 6 as a creation version.
-