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