Package org.elasticsearch.index.store
Class Store.MetadataSnapshot
- java.lang.Object
-
- org.elasticsearch.index.store.Store.MetadataSnapshot
-
- All Implemented Interfaces:
Iterable<StoreFileMetaData>,Writeable
- Enclosing class:
- Store
public static final class Store.MetadataSnapshot extends Object implements Iterable<StoreFileMetaData>, Writeable
Represents a snapshot of the current directory build from the latest Lucene commit. Only files that are part of the last commit are considered in this datastructure. For backwards compatibility the snapshot might include legacy checksums that are derived from a dedicated checksum file written by older elasticsearch version pre 1.3Note: This class will ignore the
segments.genfile since it's optional and might change concurrently for safety reasons.- See Also:
StoreFileMetaData
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
-
Field Summary
Fields Modifier and Type Field Description static Store.MetadataSnapshotEMPTY
-
Constructor Summary
Constructors Constructor Description MetadataSnapshot(Map<String,StoreFileMetaData> metadata, Map<String,String> commitUserData, long numDocs)MetadataSnapshot(StreamInput in)Read from a stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,StoreFileMetaData>asMap()booleancontains(String existingFile)Returns true iff this metadata contains the given file.StoreFileMetaDataget(String name)Map<String,String>getCommitUserData()StringgetHistoryUUID()returns the history uuid the store points at, or null if nonexistent.longgetNumDocs()Returns the number of documents in this store snapshotStoreFileMetaDatagetSegmentsFile()Returns the segments file that this metadata snapshot represents or null if the snapshot is empty.StringgetSyncId()Returns the sync id of the commit point that this MetadataSnapshot represents.static voidhashFile(BytesRefBuilder fileHash, InputStream in, long size)Computes a strong hash value for small files.Iterator<StoreFileMetaData>iterator()Store.RecoveryDiffrecoveryDiff(Store.MetadataSnapshot recoveryTargetSnapshot)Returns a diff between the two snapshots that can be used for recovery.intsize()Returns the number of files in this snapshotvoidwriteTo(StreamOutput out)Write this into the StreamOutput.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
EMPTY
public static final Store.MetadataSnapshot EMPTY
-
-
Constructor Detail
-
MetadataSnapshot
public MetadataSnapshot(Map<String,StoreFileMetaData> metadata, Map<String,String> commitUserData, long numDocs)
-
MetadataSnapshot
public MetadataSnapshot(StreamInput in) throws IOException
Read from a stream.- Throws:
IOException
-
-
Method Detail
-
writeTo
public void writeTo(StreamOutput out) throws IOException
Description copied from interface:WriteableWrite this into the StreamOutput.- Specified by:
writeToin interfaceWriteable- Throws:
IOException
-
getNumDocs
public long getNumDocs()
Returns the number of documents in this store snapshot
-
hashFile
public static void hashFile(BytesRefBuilder fileHash, InputStream in, long size) throws IOException
Computes a strong hash value for small files. Note that this method should only be used for files < 1MB- Throws:
IOException
-
iterator
public Iterator<StoreFileMetaData> iterator()
- Specified by:
iteratorin interfaceIterable<StoreFileMetaData>
-
get
public StoreFileMetaData get(String name)
-
asMap
public Map<String,StoreFileMetaData> asMap()
-
recoveryDiff
public Store.RecoveryDiff recoveryDiff(Store.MetadataSnapshot recoveryTargetSnapshot)
Returns a diff between the two snapshots that can be used for recovery. The given snapshot is treated as the recovery target and this snapshot as the source. The returned diff will hold a list of files that are:- identical: they exist in both snapshots and they can be considered the same ie. they don't need to be recovered
- different: they exist in both snapshots but their they are not identical
- missing: files that exist in the source but not in the target
- all files in this segment have the same checksum
- all files in this segment have the same length
- the segments
.sifiles hashes are byte-identical Note: This is a using a perfect hash function, The metadata transfers the.sifile content as it's hash
The
.sifile contains a lot of diagnostics including a timestamp etc. in the future there might be unique segment identifiers in there hardening this method further.The per-commit files handles very similar. A commit is composed of the
segments_Nfiles as well as generational files like deletes (_x_y.del) or field-info (_x_y.fnm) files. On a per-commit level files for a commit are treated as identical iff:- all files belonging to this commit have the same checksum
- all files belonging to this commit have the same length
- the segments file
segments_Nfiles hashes are byte-identical Note: This is a using a perfect hash function, The metadata transfers thesegments_Nfile content as it's hash
NOTE: this diff will not contain the
segments.genfile. This file is omitted on recovery.
-
size
public int size()
Returns the number of files in this snapshot
-
getHistoryUUID
public String getHistoryUUID()
returns the history uuid the store points at, or null if nonexistent.
-
contains
public boolean contains(String existingFile)
Returns true iff this metadata contains the given file.
-
getSegmentsFile
public StoreFileMetaData getSegmentsFile()
Returns the segments file that this metadata snapshot represents or null if the snapshot is empty.
-
getSyncId
public String getSyncId()
Returns the sync id of the commit point that this MetadataSnapshot represents.- Returns:
- sync id if exists, else null
-
-