Class DiffListBySkipList
- All Implemented Interfaces:
Iterable<DirectoryWithSnapshotFeature.DirectoryDiff>,DiffList<DirectoryWithSnapshotFeature.DirectoryDiff>
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
FieldsFields inherited from interface org.apache.hadoop.hdfs.server.namenode.snapshot.DiffList
EMPTY_LIST -
Constructor Summary
ConstructorsConstructorDescriptionDiffListBySkipList(int capacity) Constructs a new, empty instance of SkipList. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the specified data element to the beginning of the SkipList, if the element is not already present.booleanAdds the specified data element to the end of the SkipList, if the element is not already present.intbinarySearch(int key) Searches the list for the specified object using the binary search algorithm.get(int index) Returns the data element at the specified index in this SkipList.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.booleanisEmpty()Returns true if this SkipList contains no data elements.iterator()Iterator is an iterator over the SkipList.remove(int index) Removes the element at the specified position in this list.intsize()Returns the number of data elements in this SkipList.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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
Adds the specified data element to the beginning of the SkipList, if the element is not already present.- Specified by:
addFirstin interfaceDiffList<DirectoryWithSnapshotFeature.DirectoryDiff>- Parameters:
diff- the element to be inserted
-
addLast
Adds the specified data element to the end of the SkipList, if the element is not already present.- Specified by:
addLastin interfaceDiffList<DirectoryWithSnapshotFeature.DirectoryDiff>- Parameters:
diff- the element to be inserted- Returns:
- true, if insertion is successful
-
get
Returns the data element at the specified index in this SkipList.- Specified by:
getin interfaceDiffList<DirectoryWithSnapshotFeature.DirectoryDiff>- Parameters:
index- The index of the element to be returned.- Returns:
- The element at the specified index in this SkipList.
-
remove
Removes the element at the specified position in this list.- Specified by:
removein interfaceDiffList<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:
isEmptyin interfaceDiffList<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:
sizein interfaceDiffList<DirectoryWithSnapshotFeature.DirectoryDiff>- Returns:
- The number of elements in this SkipList.
-
iterator
Iterator is an iterator over the SkipList. This should always provide a linear view of the list.- Specified by:
iteratorin interfaceIterable<DirectoryWithSnapshotFeature.DirectoryDiff>
-
binarySearch
public int binarySearch(int key) Description copied from interface:DiffListSearches the list for the specified object using the binary search algorithm.- Specified by:
binarySearchin interfaceDiffList<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:
getMinListForRangein interfaceDiffList<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
-