use of org.apache.cassandra.utils.MerkleTree.RowHash in project cassandra by apache.
the class Validator method rowHash.
private MerkleTree.RowHash rowHash(UnfilteredRowIterator partition) {
validated++;
// MerkleTree uses XOR internally, so we want lots of output bits here
Digest digest = Digest.forValidator();
UnfilteredRowIterators.digest(partition, digest, MessagingService.current_version);
// only return new hash for merkle tree in case digest was updated - see CASSANDRA-8979
return digest.inputBytes() > 0 ? new MerkleTree.RowHash(partition.partitionKey().getToken(), digest.digest(), digest.inputBytes()) : null;
}
use of org.apache.cassandra.utils.MerkleTree.RowHash in project cassandra by apache.
the class MerkleTreesTest method testHashRandom.
@Test
public void testHashRandom() {
int max = 1000000;
TOKEN_SCALE = new BigInteger("" + max);
mts = new MerkleTrees(partitioner);
mts.addMerkleTree(32, fullRange());
Random random = new Random();
while (true) {
if (!mts.split(tok(random.nextInt(max))))
break;
}
// validate the tree
TreeRangeIterator ranges = mts.rangeIterator();
for (TreeRange range : ranges) range.addHash(new RowHash(range.right, new byte[0], 0));
assert mts.hash(new Range<>(tok(-1), tok(-1))) != null : "Could not hash tree " + mts;
}
use of org.apache.cassandra.utils.MerkleTree.RowHash in project cassandra by apache.
the class MerkleTreeTest method testHashRandom.
@Test
public void testHashRandom() {
int max = 1000000;
TOKEN_SCALE = new BigInteger("" + max);
mt = new MerkleTree(partitioner, fullRange(), RECOMMENDED_DEPTH, 32);
Random random = new Random();
while (true) {
if (!mt.split(tok(random.nextInt(max))))
break;
}
// validate the tree
TreeRangeIterator ranges = mt.rangeIterator();
for (TreeRange range : ranges) range.addHash(new RowHash(range.right, new byte[0], 0));
assert mt.hash(new Range<>(tok(-1), tok(-1))) != null : "Could not hash tree " + mt;
}
use of org.apache.cassandra.utils.MerkleTree.RowHash in project cassandra by apache.
the class MerkleTreeTest method matchingSmallRange.
/**
* matching should behave as expected, even with extremely small ranges
*/
@Test
public void matchingSmallRange() {
Token start = new BigIntegerToken("9");
Token end = new BigIntegerToken("10");
Range<Token> range = new Range<>(start, end);
MerkleTree ltree = new MerkleTree(partitioner, range, RECOMMENDED_DEPTH, 16);
ltree.init();
MerkleTree rtree = new MerkleTree(partitioner, range, RECOMMENDED_DEPTH, 16);
rtree.init();
byte[] h1 = digest("asdf");
byte[] h2 = digest("asdf");
// add dummy hashes to both trees
for (TreeRange tree : ltree.rangeIterator()) {
tree.addHash(new RowHash(range.right, h1, h1.length));
}
for (TreeRange tree : rtree.rangeIterator()) {
tree.addHash(new RowHash(range.right, h2, h2.length));
}
// top level difference() should show no differences
assertEquals(MerkleTree.difference(ltree, rtree), newArrayList());
}
use of org.apache.cassandra.utils.MerkleTree.RowHash in project eiger by wlloyd.
the class MerkleTreeTest method testHashRandom.
@Test
public void testHashRandom() {
int max = 1000000;
TOKEN_SCALE = new BigInteger("" + max);
mt = new MerkleTree(partitioner, fullRange(), RECOMMENDED_DEPTH, 32);
Random random = new Random();
while (true) {
if (!mt.split(tok(random.nextInt(max))))
break;
}
// validate the tree
TreeRangeIterator ranges = mt.invalids();
for (TreeRange range : ranges) range.addHash(new RowHash(range.right, new byte[0]));
assert null != mt.hash(new Range(tok(-1), tok(-1))) : "Could not hash tree " + mt;
}
Aggregations