public final class SegmentInfos extends Object implements Cloneable, Iterable<SegmentCommitInfo>
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 writer is in the process of committing, or a custom
IndexDeletionPolicy
is in use). This file lists each segment by name and has details about the
codec and generation of deletes.
There is also a file segments.gen. This file contains
the current generation (the _N in segments_N) of the index.
This is used only as a fallback in case the current generation cannot be
accurately determined by directory listing alone (as is the case for some NFS
clients with time-based directory cache expiration). This file simply contains
an Int32
version header
(FORMAT_SEGMENTS_GEN_CURRENT
), followed by the
generation recorded as Int64
, written twice.
Files:
CodecHeader
Int32
Int64
String
Map<String,String>
Set<String>
CodecFooter
LiveDocsFormat
.name
of the Codec that encoded
this segment.IndexWriter.setCommitData(java.util.Map)
.FieldInfosFormat
.Modifier and Type | Class and Description |
---|---|
static class |
SegmentInfos.FindSegmentsFile
Utility class for executing code that needs to do
something with the current segments file.
|
Modifier and Type | Field and Description |
---|---|
int |
counter
Used to name new segments.
|
static int |
FORMAT_SEGMENTS_GEN_CURRENT
Current format of segments.gen
|
Map<String,String> |
userData
Opaque Map<String, String> that user can specify during IndexWriter.commit
|
long |
version
Counts how often the index has been changed.
|
static int |
VERSION_40
The file format version for the segments_N codec header, up to 4.5.
|
static int |
VERSION_46
The file format version for the segments_N codec header, since 4.6+.
|
static int |
VERSION_48
The file format version for the segments_N codec header, since 4.8+
|
Constructor and Description |
---|
SegmentInfos()
Sole constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(SegmentCommitInfo si)
Appends the provided
SegmentCommitInfo . |
void |
addAll(Iterable<SegmentCommitInfo> sis)
Appends the provided
SegmentCommitInfo s. |
List<SegmentCommitInfo> |
asList()
Returns all contained segments as an unmodifiable
List view. |
void |
changed()
Call this before committing if changes have been made to the
segments.
|
void |
clear()
Clear all
SegmentCommitInfo s. |
SegmentInfos |
clone()
Returns a copy of this instance, also copying each
SegmentInfo.
|
Collection<String> |
files(Directory dir,
boolean includeSegmentsFile)
Returns all file names referenced by SegmentInfo
instances matching the provided Directory (ie files
associated with any "external" segments are skipped).
|
static long |
generationFromSegmentsFileName(String fileName)
Parse the generation off the segments file name and
return it.
|
static int |
getDefaultGenLookahedCount()
Returns the
defaultGenLookaheadCount . |
long |
getGeneration()
Returns current generation.
|
static PrintStream |
getInfoStream()
Returns
infoStream . |
static long |
getLastCommitGeneration(Directory directory)
Get the generation of the most recent commit to the
index in this directory (N in the segments_N file).
|
static long |
getLastCommitGeneration(String[] files)
Get the generation of the most recent commit to the
list of index files (N in the segments_N file).
|
static String |
getLastCommitSegmentsFileName(Directory directory)
Get the filename of the segments_N file for the most
recent commit to the index in this Directory.
|
static String |
getLastCommitSegmentsFileName(String[] files)
Get the filename of the segments_N file for the most
recent commit in the list of index files.
|
long |
getLastGeneration()
Returns last succesfully read or written generation.
|
String |
getNextSegmentFileName()
Get the next segments_N filename that will be written.
|
String |
getSegmentsFileName()
Get the segments_N filename in use by this segment infos.
|
Map<String,String> |
getUserData()
Return
userData saved with this commit. |
long |
getVersion()
version number when this SegmentInfos was generated.
|
SegmentCommitInfo |
info(int i)
Returns
SegmentCommitInfo at the provided
index. |
Iterator<SegmentCommitInfo> |
iterator()
Returns an unmodifiable
Iterator of contained segments in order. |
void |
read(Directory directory)
Find the latest commit (
segments_N file ) and
load all SegmentCommitInfo s. |
void |
read(Directory directory,
String segmentFileName)
Read a particular segmentFileName.
|
void |
remove(SegmentCommitInfo si)
Remove the provided
SegmentCommitInfo . |
static void |
setDefaultGenLookaheadCount(int count)
Advanced: set how many times to try incrementing the
gen when loading the segments file.
|
static void |
setInfoStream(PrintStream infoStream)
If non-null, information about retries when loading
the segments file will be printed to this.
|
int |
size()
Returns number of
SegmentCommitInfo s. |
String |
toString(Directory directory)
Returns readable description of this segment.
|
int |
totalDocCount()
Returns sum of all segment's docCounts.
|
static String |
write3xInfo(Directory dir,
SegmentInfo si,
IOContext context)
Deprecated.
|
static void |
writeSegmentsGen(Directory dir,
long generation)
A utility for writing the
IndexFileNames.SEGMENTS_GEN file to a
Directory . |
public static final int VERSION_40
public static final int VERSION_46
public static final int VERSION_48
public static final int FORMAT_SEGMENTS_GEN_CURRENT
public int counter
public long version
public SegmentInfos()
or
#read(Directory,String)
to populate each SegmentCommitInfo
. Alternatively, you can add/remove your
own SegmentCommitInfo
s.public SegmentCommitInfo info(int i)
SegmentCommitInfo
at the provided
index.public static long getLastCommitGeneration(String[] files)
files
- -- array of file names to checkpublic static long getLastCommitGeneration(Directory directory) throws IOException
directory
- -- directory to search for the latest segments_N fileIOException
public static String getLastCommitSegmentsFileName(String[] files)
files
- -- array of file names to checkpublic static String getLastCommitSegmentsFileName(Directory directory) throws IOException
directory
- -- directory to search for the latest segments_N fileIOException
public String getSegmentsFileName()
public static long generationFromSegmentsFileName(String fileName)
public static void writeSegmentsGen(Directory dir, long generation)
IndexFileNames.SEGMENTS_GEN
file to a
Directory
.
NOTE: this is an internal utility which is kept public so that it's accessible by code from other packages. You should avoid calling this method unless you're absolutely sure what you're doing!
public String getNextSegmentFileName()
public final void read(Directory directory, String segmentFileName) throws IOException
directory
- -- directory containing the segments filesegmentFileName
- -- segment file to loadCorruptIndexException
- if the index is corruptIOException
- if there is a low-level IO errorpublic final void read(Directory directory) throws IOException
segments_N file
) and
load all SegmentCommitInfo
s.IOException
@Deprecated public static String write3xInfo(Directory dir, SegmentInfo si, IOContext context) throws IOException
IOException
public SegmentInfos clone()
public long getVersion()
public long getGeneration()
public long getLastGeneration()
public static void setInfoStream(PrintStream infoStream)
public static void setDefaultGenLookaheadCount(int count)
public static int getDefaultGenLookahedCount()
defaultGenLookaheadCount
.setDefaultGenLookaheadCount(int)
public static PrintStream getInfoStream()
infoStream
.setInfoStream(java.io.PrintStream)
public Collection<String> files(Directory dir, boolean includeSegmentsFile) throws IOException
IOException
public Map<String,String> getUserData()
userData
saved with this commit.IndexWriter.commit()
public int totalDocCount()
public void changed()
public Iterator<SegmentCommitInfo> iterator()
Iterator
of contained segments in order.iterator
in interface Iterable<SegmentCommitInfo>
public List<SegmentCommitInfo> asList()
List
view.public int size()
SegmentCommitInfo
s.public void add(SegmentCommitInfo si)
SegmentCommitInfo
.public void addAll(Iterable<SegmentCommitInfo> sis)
SegmentCommitInfo
s.public void clear()
SegmentCommitInfo
s.public void remove(SegmentCommitInfo si)
SegmentCommitInfo
.
WARNING: O(N) cost
Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.