Search in sources :

Example 1 with MerkleTree

use of org.apache.cassandra.utils.MerkleTree 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 MerkleTree

use of org.apache.cassandra.utils.MerkleTree in project cassandra by apache.

the class RepairJobTest method treeResponse.

private static TreeResponse treeResponse(InetAddressAndPort addr, Object... rangesAndHashes) {
    MerkleTrees trees = new MerkleTrees(PARTITIONER);
    for (int i = 0; i < rangesAndHashes.length; i += 2) {
        Range<Token> range = (Range<Token>) rangesAndHashes[i];
        String hash = (String) rangesAndHashes[i + 1];
        MerkleTree tree = trees.addMerkleTree(2, MerkleTree.RECOMMENDED_DEPTH, range);
        tree.get(range.left).hash(hash.getBytes());
    }
    return new TreeResponse(addr, trees);
}
Also used : MerkleTrees(org.apache.cassandra.utils.MerkleTrees) MerkleTree(org.apache.cassandra.utils.MerkleTree) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range)

Example 3 with MerkleTree

use of org.apache.cassandra.utils.MerkleTree in project eiger by wlloyd.

the class AntiEntropyServiceTestAbstract method testDifferencer.

@Test
public void testDifferencer() throws Throwable {
    // this next part does some housekeeping so that cleanup in the differencer doesn't error out.
    AntiEntropyService.RepairFuture sess = AntiEntropyService.instance.submitArtificialRepairSession(request, tablename, cfname);
    // generate a tree
    Validator validator = new Validator(request);
    validator.prepare(store);
    validator.completeTree();
    MerkleTree ltree = validator.tree;
    // and a clone
    validator = new Validator(request);
    validator.prepare(store);
    validator.completeTree();
    MerkleTree rtree = validator.tree;
    // change a range in one of the trees
    Token ltoken = StorageService.getPartitioner().midpoint(local_range.left, local_range.right);
    ltree.invalidate(ltoken);
    MerkleTree.TreeRange changed = ltree.get(ltoken);
    changed.hash("non-empty hash!".getBytes());
    Set<Range> interesting = new HashSet<Range>();
    interesting.add(changed);
    // difference the trees
    // note: we reuse the same endpoint which is bogus in theory but fine here
    AntiEntropyService.TreeResponse r1 = new AntiEntropyService.TreeResponse(REMOTE, ltree);
    AntiEntropyService.TreeResponse r2 = new AntiEntropyService.TreeResponse(REMOTE, rtree);
    AntiEntropyService.RepairSession.Differencer diff = sess.session.new Differencer(cfname, r1, r2);
    diff.run();
    // ensure that the changed range was recorded
    assertEquals("Wrong differing ranges", interesting, new HashSet<Range>(diff.differences));
}
Also used : Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) MerkleTree(org.apache.cassandra.utils.MerkleTree) AntiEntropyService(org.apache.cassandra.service.AntiEntropyService) Test(org.junit.Test)

Example 4 with MerkleTree

use of org.apache.cassandra.utils.MerkleTree in project eiger by wlloyd.

the class SerializationsTest method testTreeResponseWrite.

private void testTreeResponseWrite() throws IOException {
    AntiEntropyService.Validator v0 = new AntiEntropyService.Validator(Statics.req);
    IPartitioner part = new RandomPartitioner();
    MerkleTree mt = new MerkleTree(part, FULL_RANGE, MerkleTree.RECOMMENDED_DEPTH, Integer.MAX_VALUE);
    List<Token> tokens = new ArrayList<Token>();
    for (int i = 0; i < 10; i++) {
        Token t = part.getRandomToken();
        tokens.add(t);
        mt.split(t);
    }
    AntiEntropyService.Validator v1 = new AntiEntropyService.Validator(Statics.req, mt);
    DataOutputStream out = getOutput("service.TreeResponse.bin");
    AntiEntropyService.TreeResponseVerbHandler.SERIALIZER.serialize(v0, out, getVersion());
    AntiEntropyService.TreeResponseVerbHandler.SERIALIZER.serialize(v1, out, getVersion());
    messageSerializer.serialize(AntiEntropyService.TreeResponseVerbHandler.makeVerb(FBUtilities.getBroadcastAddress(), v0), out, getVersion());
    messageSerializer.serialize(AntiEntropyService.TreeResponseVerbHandler.makeVerb(FBUtilities.getBroadcastAddress(), v1), out, getVersion());
    out.close();
}
Also used : RandomPartitioner(org.apache.cassandra.dht.RandomPartitioner) MerkleTree(org.apache.cassandra.utils.MerkleTree) DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) Token(org.apache.cassandra.dht.Token) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Aggregations

MerkleTree (org.apache.cassandra.utils.MerkleTree)4 Token (org.apache.cassandra.dht.Token)3 Range (org.apache.cassandra.dht.Range)2 DataOutputStream (java.io.DataOutputStream)1 ArrayList (java.util.ArrayList)1 Digest (org.apache.cassandra.db.Digest)1 IPartitioner (org.apache.cassandra.dht.IPartitioner)1 RandomPartitioner (org.apache.cassandra.dht.RandomPartitioner)1 AntiEntropyService (org.apache.cassandra.service.AntiEntropyService)1 RowHash (org.apache.cassandra.utils.MerkleTree.RowHash)1 MerkleTrees (org.apache.cassandra.utils.MerkleTrees)1 Test (org.junit.Test)1