Search in sources :

Example 1 with RowHash

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;
}
Also used : MerkleTree(org.apache.cassandra.utils.MerkleTree) Digest(org.apache.cassandra.db.Digest) RowHash(org.apache.cassandra.utils.MerkleTree.RowHash)

Example 2 with RowHash

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;
}
Also used : RowHash(org.apache.cassandra.utils.MerkleTree.RowHash) TreeRange(org.apache.cassandra.utils.MerkleTree.TreeRange) BigInteger(java.math.BigInteger) TreeRange(org.apache.cassandra.utils.MerkleTree.TreeRange) TreeRangeIterator(org.apache.cassandra.utils.MerkleTrees.TreeRangeIterator) Test(org.junit.Test)

Example 3 with RowHash

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;
}
Also used : RowHash(org.apache.cassandra.utils.MerkleTree.RowHash) TreeRange(org.apache.cassandra.utils.MerkleTree.TreeRange) BigInteger(java.math.BigInteger) Range(org.apache.cassandra.dht.Range) TreeRange(org.apache.cassandra.utils.MerkleTree.TreeRange) TreeRangeIterator(org.apache.cassandra.utils.MerkleTree.TreeRangeIterator) Test(org.junit.Test)

Example 4 with RowHash

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());
}
Also used : RowHash(org.apache.cassandra.utils.MerkleTree.RowHash) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) TreeRange(org.apache.cassandra.utils.MerkleTree.TreeRange) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) TreeRange(org.apache.cassandra.utils.MerkleTree.TreeRange) Test(org.junit.Test)

Example 5 with RowHash

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;
}
Also used : RowHash(org.apache.cassandra.utils.MerkleTree.RowHash) Random(java.util.Random) TreeRange(org.apache.cassandra.utils.MerkleTree.TreeRange) BigInteger(java.math.BigInteger) Range(org.apache.cassandra.dht.Range) TreeRange(org.apache.cassandra.utils.MerkleTree.TreeRange) TreeRangeIterator(org.apache.cassandra.utils.MerkleTree.TreeRangeIterator) Test(org.junit.Test)

Aggregations

RowHash (org.apache.cassandra.utils.MerkleTree.RowHash)8 TreeRange (org.apache.cassandra.utils.MerkleTree.TreeRange)5 Test (org.junit.Test)5 Range (org.apache.cassandra.dht.Range)4 BigInteger (java.math.BigInteger)3 BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)3 Token (org.apache.cassandra.dht.Token)3 TreeRangeIterator (org.apache.cassandra.utils.MerkleTree.TreeRangeIterator)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Random (java.util.Random)1 Digest (org.apache.cassandra.db.Digest)1 MerkleTree (org.apache.cassandra.utils.MerkleTree)1 TreeRangeIterator (org.apache.cassandra.utils.MerkleTrees.TreeRangeIterator)1