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;
}
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);
}
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));
}
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();
}
Aggregations