use of org.apache.cassandra.utils.MerkleTrees in project cassandra by apache.
the class DifferenceHolderTest method testFromMismatchedMerkleTrees.
@Test
public void testFromMismatchedMerkleTrees() throws UnknownHostException {
IPartitioner partitioner = Murmur3Partitioner.instance;
Range<Token> fullRange = new Range<>(partitioner.getMinimumToken(), partitioner.getMinimumToken());
int maxsize = 16;
InetAddressAndPort a1 = InetAddressAndPort.getByName("127.0.0.1");
InetAddressAndPort a2 = InetAddressAndPort.getByName("127.0.0.2");
// merkle tree building stolen from MerkleTreesTest:
MerkleTrees mts1 = new MerkleTrees(partitioner);
MerkleTrees mts2 = new MerkleTrees(partitioner);
mts1.addMerkleTree(32, fullRange);
mts2.addMerkleTree(32, fullRange);
mts1.init();
mts2.init();
// add dummy hashes to both trees
for (MerkleTree.TreeRange range : mts1.rangeIterator()) range.addAll(new MerkleTreesTest.HIterator(range.right));
for (MerkleTree.TreeRange range : mts2.rangeIterator()) range.addAll(new MerkleTreesTest.HIterator(range.right));
MerkleTree.TreeRange leftmost = null;
MerkleTree.TreeRange middle = null;
// give some room for splitting
mts1.maxsize(fullRange, maxsize + 2);
// split the leftmost
Iterator<MerkleTree.TreeRange> ranges = mts1.rangeIterator();
leftmost = ranges.next();
mts1.split(leftmost.right);
// set the hashes for the leaf of the created split
middle = mts1.get(leftmost.right);
middle.hash(digest("arbitrary!"));
mts1.get(partitioner.midpoint(leftmost.left, leftmost.right)).hash(digest("even more arbitrary!"));
TreeResponse tr1 = new TreeResponse(a1, mts1);
TreeResponse tr2 = new TreeResponse(a2, mts2);
DifferenceHolder dh = new DifferenceHolder(Lists.newArrayList(tr1, tr2));
assertTrue(dh.get(a1).get(a2).size() == 1);
assertTrue(dh.hasDifferenceBetween(a1, a2, fullRange));
// only a1 is added as a key - see comment in dh.keyHosts()
assertEquals(Sets.newHashSet(a1), dh.keyHosts());
}
use of org.apache.cassandra.utils.MerkleTrees in project cassandra by apache.
the class LocalSyncTaskTest method testNoDifference.
/**
* When there is no difference between two, SymmetricLocalSyncTask should return stats with 0 difference.
*/
@Test
public void testNoDifference() throws Throwable {
final InetAddressAndPort ep2 = InetAddressAndPort.getByName("127.0.0.2");
Range<Token> range = new Range<>(partitioner.getMinimumToken(), partitioner.getRandomToken());
RepairJobDesc desc = new RepairJobDesc(UUID.randomUUID(), UUID.randomUUID(), KEYSPACE1, "Standard1", Arrays.asList(range));
MerkleTrees tree1 = createInitialTree(desc);
MerkleTrees tree2 = createInitialTree(desc);
// difference the trees
// note: we reuse the same endpoint which is bogus in theory but fine here
TreeResponse r1 = new TreeResponse(local, tree1);
TreeResponse r2 = new TreeResponse(ep2, tree2);
LocalSyncTask task = new LocalSyncTask(desc, r1.endpoint, r2.endpoint, MerkleTrees.difference(r1.trees, r2.trees), NO_PENDING_REPAIR, true, true, PreviewKind.NONE);
task.run();
assertEquals(0, task.get().numberOfDifferences);
}
use of org.apache.cassandra.utils.MerkleTrees in project cassandra by apache.
the class LocalSyncTaskTest method createInitialTree.
private MerkleTrees createInitialTree(RepairJobDesc desc, IPartitioner partitioner) {
MerkleTrees trees = new MerkleTrees(partitioner);
trees.addMerkleTrees((int) Math.pow(2, 15), desc.ranges);
trees.init();
return trees;
}
Aggregations