Search in sources :

Example 11 with MerkleTrees

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

the class ActiveRepairService method handleMessage.

public void handleMessage(Message<? extends RepairMessage> message) {
    RepairMessage payload = message.payload;
    RepairJobDesc desc = payload.desc;
    RepairSession session = sessions.get(desc.sessionId);
    if (session == null) {
        if (payload instanceof ValidationResponse) {
            // The trees may be off-heap, and will therefore need to be released.
            ValidationResponse validation = (ValidationResponse) payload;
            MerkleTrees trees = validation.trees;
            // The response from a failed validation won't have any trees.
            if (trees != null)
                trees.release();
        }
        return;
    }
    switch(message.verb()) {
        case VALIDATION_RSP:
            ValidationResponse validation = (ValidationResponse) payload;
            session.validationComplete(desc, message.from(), validation.trees);
            break;
        case SYNC_RSP:
            // one of replica is synced.
            SyncResponse sync = (SyncResponse) payload;
            session.syncComplete(desc, sync.nodes, sync.success, sync.summaries);
            break;
        default:
            break;
    }
}
Also used : RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) MerkleTrees(org.apache.cassandra.utils.MerkleTrees) SyncResponse(org.apache.cassandra.repair.messages.SyncResponse) RepairJobDesc(org.apache.cassandra.repair.RepairJobDesc) ValidationResponse(org.apache.cassandra.repair.messages.ValidationResponse) RepairSession(org.apache.cassandra.repair.RepairSession)

Example 12 with MerkleTrees

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

the class RepairJobTest method createInitialTree.

private MerkleTrees createInitialTree(boolean invalidate) {
    MerkleTrees trees = new MerkleTrees(MURMUR3_PARTITIONER);
    trees.addMerkleTrees((int) Math.pow(2, 15), FULL_RANGE);
    trees.init();
    if (invalidate) {
        // change a range in one of the trees
        Token token = MURMUR3_PARTITIONER.midpoint(FULL_RANGE.get(0).left, FULL_RANGE.get(0).right);
        trees.invalidate(token);
        trees.get(token).hash("non-empty hash!".getBytes());
    }
    return trees;
}
Also used : MerkleTrees(org.apache.cassandra.utils.MerkleTrees) Token(org.apache.cassandra.dht.Token)

Example 13 with MerkleTrees

use of org.apache.cassandra.utils.MerkleTrees 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 14 with MerkleTrees

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

the class ValidationTaskTest method shouldIgnoreTreesWhenDeactivated.

@Test
public void shouldIgnoreTreesWhenDeactivated() throws Exception {
    ValidationTask task = createTask();
    assertTrue(task.isActive());
    task.abort();
    assertFalse(task.isActive());
    task.treesReceived(new MerkleTrees(null));
    assertNull(task.get());
}
Also used : MerkleTrees(org.apache.cassandra.utils.MerkleTrees) Test(org.junit.Test)

Example 15 with MerkleTrees

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

the class ValidationTaskTest method shouldReleaseTreesOnAbort.

@Test
public void shouldReleaseTreesOnAbort() throws Exception {
    ValidationTask task = createTask();
    assertTrue(task.isActive());
    IPartitioner partitioner = Murmur3Partitioner.instance;
    MerkleTrees trees = new MerkleTrees(partitioner);
    trees.addMerkleTree(128, new Range<>(partitioner.getMinimumToken(), partitioner.getMaximumToken()));
    task.treesReceived(trees);
    assertEquals(1, trees.size());
    // This relies on the fact that MerkleTrees clears its range -> tree map on release.
    task.abort();
    assertEquals(0, trees.size());
}
Also used : MerkleTrees(org.apache.cassandra.utils.MerkleTrees) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

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