java.lang.Object
org.apache.hadoop.hdfs.server.namenode.snapshot.FileDiffList
All Implemented Interfaces:
Iterable<FileDiff>

public class FileDiffList extends Object
A list of FileDiffs for storing snapshot data.
  • Constructor Details

    • FileDiffList

      public FileDiffList()
  • Method Details

    • destroyAndCollectSnapshotBlocks

      public void destroyAndCollectSnapshotBlocks(INode.BlocksMapUpdateInfo collectedBlocks)
    • saveSelf2Snapshot

      public void saveSelf2Snapshot(int latestSnapshotId, INodeFile iNodeFile, INodeFileAttributes snapshotCopy, boolean withBlocks)
    • findEarlierSnapshotBlocks

      public BlockInfo[] findEarlierSnapshotBlocks(int snapshotId)
    • findLaterSnapshotBlocks

      public BlockInfo[] findLaterSnapshotBlocks(int snapshotId)
    • asList

      public final DiffList<FileDiff> asList()
      Returns:
      this list as a unmodifiable List.
    • isEmpty

      public boolean isEmpty()
    • clear

      public void clear()
      Clear the list.
    • deleteSnapshotDiff

      public final void deleteSnapshotDiff(INode.ReclaimContext reclaimContext, int snapshot, int prior, INodeFile currentINode)
      Delete a snapshot. The synchronization of the diff list will be done outside. If the diff to remove is not the first one in the diff list, we need to combine the diff with its previous one.
      Parameters:
      reclaimContext - blocks and inodes that need to be reclaimed
      snapshot - The id of the snapshot to be deleted
      prior - The id of the snapshot taken before the to-be-deleted snapshot
      currentINode - the inode where the snapshot diff is deleted
    • getLast

      public final FileDiff getLast()
      Returns:
      the last diff.
    • getLastSnapshotId

      public final int getLastSnapshotId()
      Returns:
      the id of the last snapshot.
    • getPrior

      public final int getPrior(int anchorId, boolean exclusive)
      Find the latest snapshot before a given snapshot.
      Parameters:
      anchorId - The returned snapshot's id must be <= or < this given snapshot id.
      exclusive - True means the returned snapshot's id must be < the given id, otherwise <=.
      Returns:
      The id of the latest snapshot before the given snapshot.
    • getPrior

      public final int getPrior(int snapshotId)
    • getDiffById

      public final FileDiff getDiffById(int snapshotId)
    • getSnapshotById

      public final int getSnapshotById(int snapshotId)
      Search for the snapshot whose id is 1) no less than the given id, and 2) most close to the given id.
    • getDiffIndexById

      public final int getDiffIndexById(int snapshotId)
    • getSnapshotINode

      public INodeFileAttributes getSnapshotINode(int snapshotId, INodeFileAttributes currentINode)
      Returns:
      the inode corresponding to the given snapshot. Note that the current inode is returned if there is no change between the given snapshot and the current state.
    • saveSelf2Snapshot

      public FileDiff saveSelf2Snapshot(int latestSnapshotId, INodeFile currentINode, INodeFileAttributes snapshotCopy)
      Save the snapshot copy to the latest snapshot.
    • iterator

      public Iterator<FileDiff> iterator()
      Specified by:
      iterator in interface Iterable<N extends INode>
    • toString

      public String toString()
      Overrides:
      toString in class Object