|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.cassandra.utils.MerkleTree
public class MerkleTree
A MerkleTree implemented as a binary tree. A MerkleTree is a full binary that represents a perfect binary tree of depth 'hashdepth'. In a perfect binary tree, each leaf contains a sequentially hashed range, and each inner node contains the binary hash of its two children. In the MerkleTree, many ranges will not be split to the full depth of the perfect binary tree: the leaves of this tree are Leaf objects, which contain the computed values of the nodes that would be below them if the tree were perfect. All nodes of the perfect tree are calculated using a MD5 hash: leaves are sequential hashes of the rows that fall into the range they represent, and inner nodes are a binary hash of their children. If two MerkleTrees have the same hashdepth, they represent a perfect tree of the same depth, and can always be compared, regardless of size or splits.
Nested Class Summary | |
---|---|
static class |
MerkleTree.RowHash
Hash value representing a row, to be used to pass hashes to the MerkleTree. |
static class |
MerkleTree.TreeRange
The public interface to a range in the tree. |
static class |
MerkleTree.TreeRangeIterator
Performs a depth-first, inorder traversal of invalid nodes under the given root and intersecting the given range. |
Field Summary | |
---|---|
static int |
CONSISTENT
|
static byte[][] |
EMPTIES
|
static int |
FULLY_INCONSISTENT
|
byte |
hashdepth
|
static int |
PARTIALLY_INCONSISTENT
|
static byte |
RECOMMENDED_DEPTH
|
Constructor Summary | |
---|---|
MerkleTree(IPartitioner partitioner,
byte hashdepth,
int maxsize)
|
Method Summary | |
---|---|
void |
compact(Token t)
Compacts the smallest subranges evenly split by the given token into a single range. |
static java.util.List<MerkleTree.TreeRange> |
difference(MerkleTree ltree,
MerkleTree rtree)
|
byte[] |
hash(Range range)
Hash the given range in the tree. |
void |
init()
Initializes this tree by splitting it into maxsize ranges, or until hashdepth is reached. |
void |
invalidate(Token t)
Invalidates the ranges containing the given token. |
MerkleTree.TreeRangeIterator |
invalids(Range range)
Returns a lazy iterator of invalid TreeRanges that need to be filled in order to make the given Range valid. |
int |
maxsize()
|
void |
maxsize(int maxsize)
|
IPartitioner |
partitioner()
|
void |
partitioner(IPartitioner partitioner)
TODO: Find another way to use the local partitioner after serialization. |
int |
size()
The number of distinct ranges contained in this tree. |
boolean |
split(Token t)
Splits the range containing the given token, if no tree limits would be violated. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final byte RECOMMENDED_DEPTH
public static final int CONSISTENT
public static final int FULLY_INCONSISTENT
public static final int PARTIALLY_INCONSISTENT
public static final byte[][] EMPTIES
public final byte hashdepth
Constructor Detail |
---|
public MerkleTree(IPartitioner partitioner, byte hashdepth, int maxsize)
partitioner
- The partitioner in use.hashdepth
- The maximum depth of the tree. 100/(2^depth) is the %
of the key space covered by each subrange of a fully populated tree.maxsize
- The maximum number of subranges in the tree.Method Detail |
---|
public void init()
public IPartitioner partitioner()
public int size()
public int maxsize()
public void maxsize(int maxsize)
public void partitioner(IPartitioner partitioner)
public static java.util.List<MerkleTree.TreeRange> difference(MerkleTree ltree, MerkleTree rtree)
ltree
- First tree.rtree
- Second tree.
public void invalidate(Token t)
public byte[] hash(Range range)
public boolean split(Token t)
public void compact(Token t)
public MerkleTree.TreeRangeIterator invalids(Range range)
range
- The range to find invalid subranges for.public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |