Search in sources :

Example 16 with MerkleTrees

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());
}
Also used : MerkleTrees(org.apache.cassandra.utils.MerkleTrees) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) MerkleTree(org.apache.cassandra.utils.MerkleTree) TreeResponse(org.apache.cassandra.repair.TreeResponse) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test) MerkleTreesTest(org.apache.cassandra.utils.MerkleTreesTest)

Example 17 with MerkleTrees

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);
}
Also used : MerkleTrees(org.apache.cassandra.utils.MerkleTrees) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) Test(org.junit.Test)

Example 18 with MerkleTrees

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

Aggregations

MerkleTrees (org.apache.cassandra.utils.MerkleTrees)18 Test (org.junit.Test)10 Token (org.apache.cassandra.dht.Token)9 Range (org.apache.cassandra.dht.Range)8 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)6 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)4 ValidationResponse (org.apache.cassandra.repair.messages.ValidationResponse)4 MerkleTree (org.apache.cassandra.utils.MerkleTree)4 UUID (java.util.UUID)3 Keyspace (org.apache.cassandra.db.Keyspace)3 CompactionsTest (org.apache.cassandra.db.compaction.CompactionsTest)3 IPartitioner (org.apache.cassandra.dht.IPartitioner)3 Message (org.apache.cassandra.net.Message)3 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)2 TreeResponse (org.apache.cassandra.repair.TreeResponse)2 MerkleTreesTest (org.apache.cassandra.utils.MerkleTreesTest)2 HashSet (java.util.HashSet)1 BufferDecoratedKey (org.apache.cassandra.db.BufferDecoratedKey)1 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)1 LongToken (org.apache.cassandra.dht.Murmur3Partitioner.LongToken)1