Record Class Store.MetadataSnapshot

java.lang.Object
java.lang.Record
org.elasticsearch.index.store.Store.MetadataSnapshot
Record Components:
numDocs - the number of documents in this store snapshot
All Implemented Interfaces:
Iterable<StoreFileMetadata>, Writeable
Enclosing class:
Store

public static record Store.MetadataSnapshot(Map<String,StoreFileMetadata> fileMetadataMap, Map<String,String> commitUserData, long numDocs) extends Record 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

    • MetadataSnapshot

      public MetadataSnapshot(Map<String,StoreFileMetadata> fileMetadataMap, Map<String,String> commitUserData, long numDocs)
      Creates an instance of a MetadataSnapshot record class.
      Parameters:
      fileMetadataMap - the value for the fileMetadataMap record component
      commitUserData - the value for the commitUserData record component
      numDocs - the value for the numDocs record component
  • Method Details

    • readFrom

      public static Store.MetadataSnapshot readFrom(StreamInput in) throws IOException
      Throws:
      IOException
    • 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
    • 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
      Throws:
      IOException
    • iterator

      public Iterator<StoreFileMetadata> iterator()
      Specified by:
      iterator in interface Iterable<StoreFileMetadata>
    • get

      public StoreFileMetadata get(String name)
    • 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
    • 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
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • fileMetadataMap

      public Map<String,StoreFileMetadata> fileMetadataMap()
      Returns the value of the fileMetadataMap record component.
      Returns:
      the value of the fileMetadataMap record component
    • commitUserData

      public Map<String,String> commitUserData()
      Returns the value of the commitUserData record component.
      Returns:
      the value of the commitUserData record component
    • numDocs

      public long numDocs()
      Returns the value of the numDocs record component.
      Returns:
      the value of the numDocs record component