Class Store.MetadataSnapshot

All Implemented Interfaces:
Iterable<StoreFileMetadata>, Writeable
Enclosing class:

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:
  • 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
    • getNumDocs

      public long getNumDocs()
      Returns the number of documents in this store snapshot
    • getCommitVersion

      @Nullable public Version getCommitVersion()
    • 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
    • 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 targetSnapshot)
      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

      Individual files are compared by name, length, checksum and (if present) a UUID that was assigned when the file was originally written. The segment info (*.si) files and the segments file (segments_N) are also checked to be a byte-for-byte match.

      Files are collected together into a group for each segment plus one group of "per-commit" (segments_N) files. Each per-segment group is subdivided into a nongenerational group (most of them) and a generational group (e.g. *.liv, *.fnm, *.dvm, *.dvd that have been updated by subsequent commits).

      For each segment, if any nongenerational files are different then the whole segment is considered to be different and will be recovered in full. If all the nongenerational files are the same but any generational files are different then all the generational files are considered to be different and will be recovered in full, but the nongenerational files are left alone. Finally, if any file is different then all the per-commit files are recovered too.

    • 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.
      sync id if exists, else null