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
  • Field Details

  • Constructor Details

  • Method Details

    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      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 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:
      iterator in interface Iterable<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
      This method groups file into per-segment files and per-commit files. A file is treated as identical if and on if all files in it's group are identical. On a per-segment level files for a segment are treated as identical iff:
      • all files in this segment have the same checksum
      • all files in this segment have the same length
      • the segments .si files hashes are byte-identical Note: This is a using a perfect hash function, The metadata transfers the .si file content as it's hash

      The .si file 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_N files 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_N files hashes are byte-identical Note: This is a using a perfect hash function, The metadata transfers the segments_N file content as it's hash

      NOTE: this diff will not contain the segments.gen file. This file is omitted on recovery.

    • size

      public int size()
      Returns the number of files in this snapshot
    • getCommitUserData

      public Map<String,String> getCommitUserData()
    • 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