DiffListBySkipList (Apache Hadoop HDFS 3.5.0 API)
Description: declaration: package: org.apache.hadoop.hdfs.server.namenode.snapshot, class: DiffListBySkipList

Package org.apache.hadoop.hdfs.server.namenode.snapshot

# Class DiffListBySkipList

java.lang.Object
org.apache.hadoop.hdfs.server.namenode.snapshot.DiffListBySkipList

All Implemented Interfaces:
  `Iterable<DirectoryWithSnapshotFeature.DirectoryDiff>`, `DiffList<DirectoryWithSnapshotFeature.DirectoryDiff>`

public class DiffListBySkipList extends Object implements DiffList<DirectoryWithSnapshotFeature.DirectoryDiff>
SkipList is an implementation of a data structure for storing a sorted list of Directory Diff elements, using a hierarchy of linked lists that connect increasingly sparse subsequences(defined by skip interval here) of the diffs. The elements contained in the tree must be mutually comparable.

Consider a case where we have 10 snapshots for a directory starting from s0 to s9 each associated with certain change records in terms of inodes deleted and created after a particular snapshot and before the next snapshot. The sequence will look like this:

s0->s1->s2->s3->s4->s5->s6->s7->s8->s9.

Assuming a skip interval of 3, which means a new diff will be added at a level higher than the current level after we have ore than 3 snapshots. Next level promotion happens after 9 snapshots and so on.

level 2: s08------------------------------->s9 level 1: S02------->s35-------->s68-------->s9 level 0: s0->s1->s2->s3->s4->s5->s6->s7->s8->s9

s02 will be created by combining diffs for s0, s1, s2 once s3 gets created. Similarly, s08 will be created by combining s02, s35 and s68 once s9 gets created.So, for constructing the children list fot s0, we have to combine s08, s9 and reverse apply to the live fs.

Similarly, for constructing the children list for s2, s2, s35, s68 and s9 need to get combined(or added) and reverse applied to current fs.

This approach will improve the snapshot deletion and snapshot diff calculation.

Once a snapshot gets deleted, the list needs to be balanced.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final org.slf4j.Logger`
  `LOG`

  ### Fields inherited from interface org.apache.hadoop.hdfs.server.namenode.snapshot.DiffList

  `EMPTY_LIST`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DiffListBySkipList(int capacity)`
  Constructs a new, empty instance of SkipList.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addFirst(DirectoryWithSnapshotFeature.DirectoryDiff diff)`
  Adds the specified data element to the beginning of the SkipList, if the element is not already present.
  `boolean`
  `addLast(DirectoryWithSnapshotFeature.DirectoryDiff diff)`
  Adds the specified data element to the end of the SkipList, if the element is not already present.
  `int`
  `binarySearch(int key)`
  Searches the list for the specified object using the binary search algorithm.
  `DirectoryWithSnapshotFeature.DirectoryDiff`
  `get(int index)`
  Returns the data element at the specified index in this SkipList.
  `List<DirectoryWithSnapshotFeature.DirectoryDiff>`
  `getMinListForRange(int fromIndex, int toIndex, INodeDirectory dir)`
  This function returns the minimal set of diffs required to combine in order to generate all the changes occurred between fromIndex and toIndex.
  `boolean`
  `isEmpty()`
  Returns true if this SkipList contains no data elements.
  `Iterator<DirectoryWithSnapshotFeature.DirectoryDiff>`
  `iterator()`
  Iterator is an iterator over the SkipList.
  `DirectoryWithSnapshotFeature.DirectoryDiff`
  `remove(int index)`
  Removes the element at the specified position in this list.
  `int`
  `size()`
  Returns the number of data elements in this SkipList.
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface java.lang.Iterable

  `forEach, spliterator`

- ## Field Details

  - ### LOG

    public static final org.slf4j.Logger LOG

- ## Constructor Details

  - ### DiffListBySkipList

    public DiffListBySkipList(int capacity)
    Constructs a new, empty instance of SkipList.

- ## Method Details

  - ### addFirst

    public void addFirst(DirectoryWithSnapshotFeature.DirectoryDiff diff)
    Adds the specified data element to the beginning of the SkipList, if the element is not already present.
    Specified by:
      `addFirst` in interface `DiffList<DirectoryWithSnapshotFeature.DirectoryDiff>`
    Parameters:
      `diff` - the element to be inserted

  - ### addLast

    public boolean addLast(DirectoryWithSnapshotFeature.DirectoryDiff diff)
    Adds the specified data element to the end of the SkipList, if the element is not already present.
    Specified by:
      `addLast` in interface `DiffList<DirectoryWithSnapshotFeature.DirectoryDiff>`
    Parameters:
      `diff` - the element to be inserted
    Returns:
      true, if insertion is successful

  - ### get

    public DirectoryWithSnapshotFeature.DirectoryDiff get(int index)
    Returns the data element at the specified index in this SkipList.
    Specified by:
      `get` in interface `DiffList<DirectoryWithSnapshotFeature.DirectoryDiff>`
    Parameters:
      `index` - The index of the element to be returned.
    Returns:
      The element at the specified index in this SkipList.

  - ### remove

    public DirectoryWithSnapshotFeature.DirectoryDiff remove(int index)
    Removes the element at the specified position in this list.
    Specified by:
      `remove` in interface `DiffList<DirectoryWithSnapshotFeature.DirectoryDiff>`
    Parameters:
      `index` - the index of the element to be removed
    Returns:
      the removed DirectoryDiff

  - ### isEmpty

    public boolean isEmpty()
    Returns true if this SkipList contains no data elements. In other words, returns true if the size of this SkipList is zero.
    Specified by:
      `isEmpty` in interface `DiffList<DirectoryWithSnapshotFeature.DirectoryDiff>`
    Returns:
      True if this SkipList contains no elements.

  - ### size

    public int size()
    Returns the number of data elements in this SkipList.
    Specified by:
      `size` in interface `DiffList<DirectoryWithSnapshotFeature.DirectoryDiff>`
    Returns:
      The number of elements in this SkipList.

  - ### iterator

    public Iterator<DirectoryWithSnapshotFeature.DirectoryDiff> iterator()
    Iterator is an iterator over the SkipList. This should always provide a linear view of the list.
    Specified by:
      `iterator` in interface `Iterable<DirectoryWithSnapshotFeature.DirectoryDiff>`

  - ### binarySearch

    public int binarySearch(int key)
    Description copied from interface: `DiffList`
    Searches the list for the specified object using the binary search algorithm.
    Specified by:
      `binarySearch` in interface `DiffList<DirectoryWithSnapshotFeature.DirectoryDiff>`
    Parameters:
      `key` - key to be searched for
    Returns:
      the index of the search key, if it is contained in the list otherwise, (-insertion point - 1).

  - ### getMinListForRange

    public List<DirectoryWithSnapshotFeature.DirectoryDiff> getMinListForRange(int fromIndex, int toIndex, INodeDirectory dir)
    This function returns the minimal set of diffs required to combine in order to generate all the changes occurred between fromIndex and toIndex.
    Specified by:
      `getMinListForRange` in interface `DiffList<DirectoryWithSnapshotFeature.DirectoryDiff>`
    Parameters:
      `fromIndex` - index from where the summation has to start(inclusive)
      `toIndex` - index till where the summation has to end(exclusive)
    Returns:
      list of Directory Diff

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`