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.3
Note: This class will ignore the segments.gen file 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 -
Constructor Summary
ConstructorsConstructorDescriptionMetadataSnapshot(Map<String,StoreFileMetadata> metadata, Map<String,String> commitUserData, long numDocs)Read from a stream. -
Method Summary
Modifier and TypeMethodDescriptionasMap()booleanReturns true iff this metadata contains the given file.returns the history uuid the store points at, or null if nonexistent.longReturns the number of documents in this store snapshotReturns the segments file that this metadata snapshot represents or null if the snapshot is empty.Returns the sync id of the commit point that this MetadataSnapshot represents.static voidhashFile(org.apache.lucene.util.BytesRefBuilder fileHash, InputStream in, long size)Computes a strong hash value for small files.iterator()recoveryDiff(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, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
EMPTY
-
-
Constructor Details
-
MetadataSnapshot
-
MetadataSnapshot
Read from a stream.- Throws:
IOException
-
-
Method Details
-
writeTo
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(org.apache.lucene.util.BytesRefBuilder fileHash, InputStream in, long size) throws IOExceptionComputes a strong hash value for small files. Note that this method should only be used for files < 1MB- Throws:
IOException
-
iterator
- Specified by:
iteratorin interfaceIterable<StoreFileMetadata>
-
get
-
asMap
-
recoveryDiff
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 -
getCommitUserData
-
getHistoryUUID
returns the history uuid the store points at, or null if nonexistent. -
contains
Returns true iff this metadata contains the given file. -
getSegmentsFile
Returns the segments file that this metadata snapshot represents or null if the snapshot is empty. -
getSyncId
Returns the sync id of the commit point that this MetadataSnapshot represents.- Returns:
- sync id if exists, else null
-