|
||||||||||
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 tree 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. The hash values of the inner nodes of the MerkleTree are calculated lazily based on their children when the hash of a range is requested with hash(range). Inputs passed to TreeRange.validate should be calculated using a very secure hash, because all hashing internal to the tree is accomplished using XOR. 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 int |
FULLY_INCONSISTENT
|
byte |
hashdepth
|
static int |
PARTIALLY_INCONSISTENT
|
static byte |
RECOMMENDED_DEPTH
|
Constructor Summary | |
---|---|
MerkleTree(IPartitioner partitioner,
byte hashdepth,
long 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 until hashdepth is reached, or until an additional level of splits would violate maxsize. |
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. |
long |
maxsize()
|
void |
maxsize(long maxsize)
|
IPartitioner |
partitioner()
|
void |
partitioner(IPartitioner partitioner)
TODO: Find another way to use the local partitioner after serialization. |
long |
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 final byte hashdepth
Constructor Detail |
---|
public MerkleTree(IPartitioner partitioner, byte hashdepth, long 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 long size()
public long maxsize()
public void maxsize(long 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 |